summaryrefslogtreecommitdiffstats
path: root/container-search
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@yahoo-inc.com>2016-10-07 13:12:28 +0200
committerJon Bratseth <bratseth@yahoo-inc.com>2016-10-07 13:12:28 +0200
commitc2310cdd43abb2ec8afce32d86f391998450469b (patch)
treee9be0cc492234a845d17f994562c896571358c5c /container-search
parentfb8d2cff4c80e38f30c689e833068e8eb05b4fb3 (diff)
Avoid test timing sensitivity
Diffstat (limited to 'container-search')
-rw-r--r--container-search/src/test/java/com/yahoo/prelude/fastsearch/test/fs4mock/MockFS4ResourcePool.java14
1 files changed, 11 insertions, 3 deletions
diff --git a/container-search/src/test/java/com/yahoo/prelude/fastsearch/test/fs4mock/MockFS4ResourcePool.java b/container-search/src/test/java/com/yahoo/prelude/fastsearch/test/fs4mock/MockFS4ResourcePool.java
index 91f12184884..71a8556fb00 100644
--- a/container-search/src/test/java/com/yahoo/prelude/fastsearch/test/fs4mock/MockFS4ResourcePool.java
+++ b/container-search/src/test/java/com/yahoo/prelude/fastsearch/test/fs4mock/MockFS4ResourcePool.java
@@ -16,9 +16,11 @@ public class MockFS4ResourcePool extends FS4ResourcePool {
private final Map<String, Integer> requestsPerBackend = new HashMap<>();
private final Set<String> nonRespondingBackends = new HashSet<>();
private final Map<String, Long> activeDocumentsInBackend = new HashMap<>();
-
+ private final long testingThreadId;
+
public MockFS4ResourcePool() {
super(1);
+ this.testingThreadId = Thread.currentThread().getId();
}
@Override
@@ -31,17 +33,23 @@ public class MockFS4ResourcePool extends FS4ResourcePool {
() -> new MockFSChannel(activeDocumentsInBackend.getOrDefault(hostname, 0L)));
}
- /** Returns the number of times a backend for this hostname and port has been requested */
+ /**
+ * Returns the number of times a backend for this hostname and port has been requested
+ * from the thread creating this
+ */
public int requestCount(String hostname, int port) {
return requestsPerBackend.getOrDefault(hostname + ":" + port, 0);
}
- /** sets the number of active documents the given host will report to have in ping responses */
+ /** Sets the number of active documents the given host will report to have in ping responses */
public void setActiveDocuments(String hostname, long activeDocuments) {
activeDocumentsInBackend.put(hostname, activeDocuments);
}
private void countRequest(String hostAndPort) {
+ // ignore requests from the ping thread to avoid timing issues
+ if (Thread.currentThread().getId() != testingThreadId) return;
+
requestsPerBackend.put(hostAndPort, requestsPerBackend.getOrDefault(hostAndPort, 0) + 1);
}