From c017a937ee20628ddaf17be9bb04f47f787f0274 Mon Sep 17 00:00:00 2001 From: Zlatin Balevsky Date: Tue, 10 Jul 2018 19:58:31 +0100 Subject: [PATCH] do not to unverified if already in verified --- .../main/groovy/com/muwire/hostcache/HostPool.groovy | 4 +++- .../groovy/com/muwire/hostcache/HostPoolTest.groovy | 10 ++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/host-cache/src/main/groovy/com/muwire/hostcache/HostPool.groovy b/host-cache/src/main/groovy/com/muwire/hostcache/HostPool.groovy index b01c71ef..a9460767 100644 --- a/host-cache/src/main/groovy/com/muwire/hostcache/HostPool.groovy +++ b/host-cache/src/main/groovy/com/muwire/hostcache/HostPool.groovy @@ -26,7 +26,9 @@ class HostPool { } synchronized def addUnverified(host) { - unverified.add(host) + if (!verified.contains(host)) { + unverified.add(host) + } } synchronized def getUnverified(int max) { diff --git a/host-cache/src/test/groovy/com/muwire/hostcache/HostPoolTest.groovy b/host-cache/src/test/groovy/com/muwire/hostcache/HostPoolTest.groovy index e1167952..7ffc21eb 100644 --- a/host-cache/src/test/groovy/com/muwire/hostcache/HostPoolTest.groovy +++ b/host-cache/src/test/groovy/com/muwire/hostcache/HostPoolTest.groovy @@ -160,4 +160,14 @@ class HostPoolTest { assert hp.getVerified(10,true).isEmpty() assert hp.getUnverified(10).size() == 1 } + + @Test + void doNotAddIfVerified() { + hp.addUnverified(freeBoth) + hp.verify(freeBoth) + assert hp.getUnverified(1).isEmpty() + + hp.addUnverified(freeBoth) + assert hp.getUnverified(1).isEmpty() + } }