4141import  org .bson .Document ;
4242import  org .junit .jupiter .api .AfterEach ;
4343import  org .junit .jupiter .api .BeforeEach ;
44- import  org .junit .jupiter .api .DisplayName ;
4544import  org .junit .jupiter .api .Test ;
4645import  org .junit .jupiter .params .ParameterizedTest ;
4746import  org .junit .jupiter .params .provider .Arguments ;
4847import  org .junit .jupiter .params .provider .MethodSource ;
48+ import  org .junit .jupiter .params .provider .ValueSource ;
4949
5050import  java .io .IOException ;
5151import  java .lang .reflect .Field ;
5454import  java .nio .file .Path ;
5555import  java .nio .file .Paths ;
5656import  java .time .Duration ;
57+ import  java .time .temporal .ChronoUnit ;
5758import  java .util .ArrayList ;
5859import  java .util .Arrays ;
5960import  java .util .Collections ;
@@ -208,10 +209,12 @@ public void test2p1ValidCallbackInputs() {
208209    }
209210
210211    // Not a prose test 
211-     @ ParameterizedTest 
212+     @ ParameterizedTest (name  = "{testName}. " 
213+             + "Parameters: timeoutMs={1}, " 
214+             + "serverSelectionTimeoutMS={2}," 
215+             + " expectedTimeoutThreshold={3}" )
212216    @ MethodSource 
213-     @ DisplayName ("{testName}" )
214-     void  testValidCallbackInputsTimeout (final  String  testName ,
217+     void  testValidCallbackInputsTimeoutWhenTimeoutMsIsSet (final  String  testName ,
215218                                        final  int  timeoutMs ,
216219                                        final  int  serverSelectionTimeoutMS ,
217220                                        final  int  expectedTimeoutThreshold ) {
@@ -247,7 +250,7 @@ void testValidCallbackInputsTimeout(final String testName,
247250        }
248251    }
249252
250-     private  static  Stream <Arguments > testValidCallbackInputsTimeout () {
253+     private  static  Stream <Arguments > testValidCallbackInputsTimeoutWhenTimeoutMsIsSet () {
251254        return  Stream .of (
252255                Arguments .of ("serverSelectionTimeoutMS honored for oidc callback if it's lower than timeoutMS" ,
253256                        1000 , // timeoutMS 
@@ -264,6 +267,32 @@ private static Stream<Arguments> testValidCallbackInputsTimeout() {
264267        );
265268    }
266269
270+     // Not a prose test 
271+     @ ParameterizedTest (name  = "test callback timeout when server selection timeout is " 
272+             + "infinite and timeoutMs is set to {0}" )
273+     @ ValueSource (ints  = {0 , 100 })
274+     void  testCallbackTimeoutWhenServerSelectionTimeoutIsInfiniteTimeoutMsIsSet (final  int  timeoutMs ) {
275+         TestCallback  callback1  = createCallback ();
276+ 
277+         OidcCallback  callback2  = (context ) -> {
278+             assertEquals (context .getTimeout (), ChronoUnit .FOREVER .getDuration ());
279+             return  callback1 .onRequest (context );
280+         };
281+ 
282+         MongoClientSettings  clientSettings  = MongoClientSettings .builder (createSettings (callback2 ))
283+                 .applyToClusterSettings (builder  ->
284+                         builder .serverSelectionTimeout (
285+                                 -1 , // -1 means infinite 
286+                                 TimeUnit .MILLISECONDS ))
287+                 .timeout (timeoutMs , TimeUnit .MILLISECONDS )
288+                 .build ();
289+ 
290+         try  (MongoClient  mongoClient  = createMongoClient (clientSettings )) {
291+             performFind (mongoClient );
292+             assertEquals (1 , callback1 .getInvocations ());
293+         }
294+     }
295+ 
267296    @ Test 
268297    public  void  test2p2RequestCallbackReturnsNull () {
269298        //noinspection ConstantConditions 
0 commit comments