@@ -75,29 +75,29 @@ void shouldInterruptConnectionEstablishmentWhenConnectionTimeoutExpires(final in
75
75
76
76
//then
77
77
long elapsedMs = TimeUnit .NANOSECONDS .toMillis (System .nanoTime () - connectOpenStart );
78
+ long diff = elapsedMs - connectTimeout ;
79
+ // Allowed difference, with test overhead setup is 300MS.
80
+ int epsilonMs = 300 ;
81
+
78
82
assertInstanceOf (InterruptedByTimeoutException .class , mongoSocketOpenException .getCause (),
79
83
"Actual cause: " + mongoSocketOpenException .getCause ());
80
- long diff = elapsedMs - connectTimeout ;
81
84
assertFalse (diff < 0 ,
82
85
String .format ("Connection timed-out sooner than expected. Difference: %d ms" , diff ));
83
- // Allowed difference, with test overhead setup is 300MS.
84
- int epsilon = 300 ;
85
- assertTrue (diff < epsilon ,
86
- String .format ("Elapsed time %d ms should be within %d ms of the connect timeout" , elapsedMs , epsilon ));
86
+ assertTrue (diff < epsilonMs ,
87
+ String .format ("Elapsed time %d ms should be within %d ms of the connect timeout" , elapsedMs , epsilonMs ));
87
88
}
88
89
}
89
90
90
91
@ ParameterizedTest
91
92
@ ValueSource (ints = {0 , 500 , 1000 , 2000 })
92
93
void shouldEstablishConnection (final int connectTimeout ) throws IOException {
94
+ //given
93
95
try (TlsChannelStreamFactoryFactory factory = new TlsChannelStreamFactoryFactory (new DefaultInetAddressResolver ())) {
94
- //given
95
96
StreamFactory streamFactory = factory .create (SocketSettings .builder ()
96
97
.connectTimeout (connectTimeout , TimeUnit .MILLISECONDS )
97
98
.build (), SSL_SETTINGS );
98
99
99
100
Stream stream = streamFactory .create (new ServerAddress ("localhost" , port ));
100
-
101
101
try {
102
102
//when
103
103
stream .open (OperationContext .simpleOperationContext (
0 commit comments