Skip to content

Commit

Permalink
[tyXNOmR9] Investigate flaky test
Browse files Browse the repository at this point in the history
  • Loading branch information
loveleif authored Dec 28, 2023
1 parent 09ce08b commit e3922fd
Showing 1 changed file with 20 additions and 25 deletions.
45 changes: 20 additions & 25 deletions core/src/test/java/apoc/spatial/GeocodeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,21 @@

import static apoc.ApocConfig.apocConfig;
import static apoc.util.MapUtil.map;
import static org.junit.Assert.*;
import static org.neo4j.test.assertion.Assert.assertEventually;
import static org.awaitility.Awaitility.await;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;

import apoc.util.JsonUtil;
import apoc.util.TestUtil;
import inet.ipaddr.IPAddressString;
import java.io.InputStream;
import java.time.Duration;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;
import java.util.function.Consumer;
import java.util.stream.Stream;
Expand Down Expand Up @@ -295,27 +299,18 @@ private void testGeocodeAddress(

private void waitForServerResponseOK(
String query, Map<String, Object> params, AtomicLong time, Consumer<Result> resultObjectFunction) {
assertEventually(
() -> {
try {
long start = System.currentTimeMillis();
db.executeTransactionally(query, params, res -> {
resultObjectFunction.accept(res);
return null;
});

time.addAndGet(System.currentTimeMillis() - start);
return true;
} catch (Exception e) {
String msg = e.getMessage();
if (msg.contains("Server returned HTTP response code") || msg.contains("connect timed out")) {
return false;
}
throw e;
}
},
(value) -> value,
20L,
TimeUnit.SECONDS);
await("waitForServerResponseOK")
.atMost(Duration.ofSeconds(30))
.pollInterval(Duration.ofMillis(250))
.pollInSameThread()
.untilAsserted(() -> {
long start = System.currentTimeMillis();
db.executeTransactionally(query, params, res -> {
resultObjectFunction.accept(res);
return null;
});

time.addAndGet(System.currentTimeMillis() - start);
});
}
}

0 comments on commit e3922fd

Please sign in to comment.