@@ -508,20 +508,15 @@ public void hostSwitch() throws Exception {
508
508
}
509
509
510
510
@ Test
511
- public void DNSTimeout () throws Exception {
512
- // On Travis, the reported run duration is not reliable.
513
- if ("true" .equals (System .getenv ("TRAVIS" ))) {
514
- return ;
515
- }
516
-
511
+ public void DNSTimeout () throws AssertionError {
517
512
// Given all hosts resulting in a DNS Timeout
518
- String appId = (String ) Whitebox .getInternalState (client , "applicationID" );
519
513
List <String > hostsArray = (List <String >) Whitebox .getInternalState (client , "readHosts" );
520
- final String hostName = appId + "-dsn.algolia.biz" ; //TODO: Random host name to avoid system DNS cache
521
- hostsArray .set (0 , hostName );
522
- hostsArray .set (1 , hostName );
523
- hostsArray .set (2 , hostName );
524
- hostsArray .set (3 , hostName );
514
+ // With random hostnames to avoid any caching
515
+ final String hostNameSuffix = "-dsn.algolia.biz" ;
516
+ hostsArray .set (0 , UUID .randomUUID ().toString () + hostNameSuffix );
517
+ hostsArray .set (1 , UUID .randomUUID ().toString () + hostNameSuffix );
518
+ hostsArray .set (2 , UUID .randomUUID ().toString () + hostNameSuffix );
519
+ hostsArray .set (3 , UUID .randomUUID ().toString () + hostNameSuffix );
525
520
Whitebox .setInternalState (client , "readHosts" , hostsArray );
526
521
527
522
//A connect timeout of 500 ms
@@ -538,7 +533,8 @@ public void DNSTimeout() throws Exception {
538
533
@ Override public void doRequestCompleted (JSONObject content , AlgoliaException error ) {
539
534
if (error != null ) {
540
535
final long duration = (System .nanoTime () - startTime ) / 1000000 ;
541
- assertTrue ("We should hit 4 times the timeout before failing, but test took only " + duration + " ms." , duration > timeout * 4 );
536
+ assertTrue ("We should hit 4 times the timeout before failing, but test took only " + duration + " ms." ,
537
+ duration > timeout * 4 );
542
538
} else {
543
539
fail ("Searching with failing hosts should result in an error." );
544
540
}
0 commit comments