Skip to content
This repository was archived by the owner on Jan 31, 2022. It is now read-only.

Commit 717e9bb

Browse files
committed
fix(IndexTest): Randomize DNSTimeout's hostnames
1 parent 9bcd0d2 commit 717e9bb

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

algoliasearch/src/test/java/com/algolia/search/saas/IndexTest.java

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -508,20 +508,15 @@ public void hostSwitch() throws Exception {
508508
}
509509

510510
@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 {
517512
// Given all hosts resulting in a DNS Timeout
518-
String appId = (String) Whitebox.getInternalState(client, "applicationID");
519513
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);
525520
Whitebox.setInternalState(client, "readHosts", hostsArray);
526521

527522
//A connect timeout of 500 ms
@@ -538,7 +533,8 @@ public void DNSTimeout() throws Exception {
538533
@Override public void doRequestCompleted(JSONObject content, AlgoliaException error) {
539534
if (error != null) {
540535
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);
542538
} else {
543539
fail("Searching with failing hosts should result in an error.");
544540
}

0 commit comments

Comments
 (0)