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() + } }