Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@
import org.bson.Document;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import org.junit.jupiter.params.provider.ValueSource;

import java.io.IOException;
import java.lang.reflect.Field;
Expand Down Expand Up @@ -260,6 +260,10 @@ private static Stream<Arguments> testValidCallbackInputsTimeoutWhenTimeoutMsIsSe
500, // timeoutMS
1000, // serverSelectionTimeoutMS
499), // expectedTimeoutThreshold
Arguments.of("timeoutMS honored for oidc callback if serverSelectionTimeoutMS is infinite",
500, // timeoutMS
-1, // serverSelectionTimeoutMS
499), // expectedTimeoutThreshold,
Arguments.of("serverSelectionTimeoutMS honored for oidc callback if timeoutMS=0",
0, // infinite timeoutMS
500, // serverSelectionTimeoutMS
Expand All @@ -268,14 +272,19 @@ private static Stream<Arguments> testValidCallbackInputsTimeoutWhenTimeoutMsIsSe
}

// Not a prose test
@ParameterizedTest(name = "test callback timeout when server selection timeout is "
+ "infinite and timeoutMs is set to {0}")
@ValueSource(ints = {0, 100})
void testCallbackTimeoutWhenServerSelectionTimeoutIsInfiniteTimeoutMsIsSet(final int timeoutMs) {
@Test
@DisplayName("test callback timeout when server selection timeout and "
+ "timeoutMs are infinite")
void testCallbackTimeoutWhenServerSelectionTimeoutIsInfiniteTimeoutMsIsSet() {
TestCallback callback1 = createCallback();
Duration expectedTimeout = ChronoUnit.FOREVER.getDuration();

OidcCallback callback2 = (context) -> {
assertEquals(context.getTimeout(), ChronoUnit.FOREVER.getDuration());
assertEquals(expectedTimeout, context.getTimeout(),
format("Expected timeout to be infinite (%d seconds), but was %d seconds",
expectedTimeout.getSeconds(),
context.getTimeout().getSeconds()));

return callback1.onRequest(context);
};

Expand All @@ -284,7 +293,7 @@ void testCallbackTimeoutWhenServerSelectionTimeoutIsInfiniteTimeoutMsIsSet(final
builder.serverSelectionTimeout(
-1, // -1 means infinite
TimeUnit.MILLISECONDS))
.timeout(timeoutMs, TimeUnit.MILLISECONDS)
.timeout(0, TimeUnit.MILLISECONDS)
.build();

try (MongoClient mongoClient = createMongoClient(clientSettings)) {
Expand Down