@@ -286,27 +286,32 @@ public void testFOInstanceResolution2() throws SQLException {
286
286
287
287
verifyTimeout (timerEnd - timerStart , defaultTimeout );
288
288
}
289
-
289
+
290
290
/**
291
- * Tests that failover is still used with socket timeout by measuring timing during a socket timeout.
292
- *
291
+ * Tests that failover is correctly used after a socket timeout, by confirming total time includes socketTimeout
292
+ * for both primary and failover server.
293
293
*/
294
294
@ Test
295
295
public void testFailoverInstanceResolutionWithSocketTimeout () {
296
296
long timerEnd ;
297
297
long timerStart = System .currentTimeMillis ();
298
-
299
- try (Connection conn = PrepUtil .getConnection (connectionString
300
- + ";failoverPartner=" + RandomUtil . getIdentifier ( "FailoverPartner" )
301
- + ";socketTimeout=" + waitForDelaySeconds )) {
298
+
299
+ try (Connection con = PrepUtil .getConnection ("jdbc:sqlserver://" + randomServer
300
+ + ";databaseName=FailoverDB; failoverPartner=" + randomServer + " \\ foo;user=sa;password=pwd;"
301
+ + ";socketTimeout=" + waitForDelaySeconds )) {
302
302
fail (TestResource .getResource ("R_shouldNotConnect" ));
303
303
} catch (Exception e ) {
304
304
timerEnd = System .currentTimeMillis ();
305
305
if (!(e instanceof SQLException )) {
306
306
fail (TestResource .getResource ("R_unexpectedErrorMessage" ) + e .getMessage ());
307
307
}
308
308
309
- verifyTimeout (timerEnd - timerStart , waitForDelaySeconds );
309
+ // Driver should correctly attempt to connect to db, experience a socketTimeout, attempt to connect to
310
+ // failover, and then have another socketTimeout. So, expected total time is 2 x socketTimeout.
311
+ long totalTime = timerEnd - timerStart ;
312
+ long totalExpectedTime = waitForDelaySeconds * 1000L * 2 ; // We expect 2 * socketTimeout
313
+ assertTrue ( totalTime >= totalExpectedTime , TestResource .getResource ("R_executionNotLong" )
314
+ + "totalTime: " + totalTime + " expectedTime: " + totalExpectedTime );
310
315
}
311
316
}
312
317
0 commit comments