From c2310cdd43abb2ec8afce32d86f391998450469b Mon Sep 17 00:00:00 2001 From: Jon Bratseth Date: Fri, 7 Oct 2016 13:12:28 +0200 Subject: Avoid test timing sensitivity --- .../fastsearch/test/fs4mock/MockFS4ResourcePool.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'container-search') 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 requestsPerBackend = new HashMap<>(); private final Set nonRespondingBackends = new HashSet<>(); private final Map 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); } -- cgit v1.2.3