Skip to content

Commit 88e93ea

Browse files
committed
Update AsyncRunnable for use with TimeoutContext
1 parent 4b019f3 commit 88e93ea

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

driver-core/src/main/com/mongodb/internal/async/AsyncRunnable.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package com.mongodb.internal.async;
1818

19+
import com.mongodb.internal.TimeoutContext;
1920
import com.mongodb.internal.async.function.RetryState;
2021
import com.mongodb.internal.async.function.RetryingAsyncCallbackSupplier;
2122

@@ -231,10 +232,10 @@ default <R> AsyncSupplier<R> thenSupply(final AsyncSupplier<R> supplier) {
231232
* @see RetryingAsyncCallbackSupplier
232233
*/
233234
default AsyncRunnable thenRunRetryingWhile(
234-
final AsyncRunnable runnable, final Predicate<Throwable> shouldRetry) {
235+
final TimeoutContext timeoutContext, final AsyncRunnable runnable, final Predicate<Throwable> shouldRetry) {
235236
return thenRun(callback -> {
236237
new RetryingAsyncCallbackSupplier<Void>(
237-
new RetryState(),
238+
new RetryState(timeoutContext),
238239
(rs, lastAttemptFailure) -> shouldRetry.test(lastAttemptFailure),
239240
// `finish` is required here instead of `unsafeFinish`
240241
// because only `finish` meets the contract of

driver-core/src/test/unit/com/mongodb/internal/async/AsyncFunctionsTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
package com.mongodb.internal.async;
1717

1818
import com.mongodb.client.TestListener;
19+
import com.mongodb.internal.TimeoutContext;
20+
import com.mongodb.internal.TimeoutSettings;
1921
import org.junit.jupiter.api.Test;
2022
import org.opentest4j.AssertionFailedError;
2123

@@ -36,6 +38,7 @@
3638
import static org.junit.jupiter.api.Assertions.fail;
3739

3840
final class AsyncFunctionsTest {
41+
private static final TimeoutContext TIMEOUT_CONTEXT = new TimeoutContext(new TimeoutSettings(0, 0, 0, 0L, 0));
3942
private final TestListener listener = new TestListener();
4043
private final InvocationTracker invocationTracker = new InvocationTracker();
4144
private boolean isTestingAbruptCompletion = false;
@@ -647,6 +650,7 @@ void testRetryLoop() {
647650
},
648651
(callback) -> {
649652
beginAsync().thenRunRetryingWhile(
653+
TIMEOUT_CONTEXT,
650654
c -> async(plainTest(0) ? 1 : 2, c),
651655
e -> e.getMessage().equals("exception-1")
652656
).finish(callback);

0 commit comments

Comments
 (0)