diff --git a/search-client/src/commonTest/kotlin/com/jillesvangurp/ktsearch/SniffingNodeSelectorTest.kt b/search-client/src/commonTest/kotlin/com/jillesvangurp/ktsearch/SniffingNodeSelectorTest.kt index f0544253..f0b4b149 100644 --- a/search-client/src/commonTest/kotlin/com/jillesvangurp/ktsearch/SniffingNodeSelectorTest.kt +++ b/search-client/src/commonTest/kotlin/com/jillesvangurp/ktsearch/SniffingNodeSelectorTest.kt @@ -1,5 +1,6 @@ package com.jillesvangurp.ktsearch +import io.kotest.assertions.nondeterministic.eventually import io.kotest.matchers.shouldBe import kotlinx.coroutines.async import kotlinx.coroutines.awaitAll @@ -8,31 +9,34 @@ import kotlinx.coroutines.delay import kotlin.random.Random import kotlin.random.nextULong import kotlin.test.Test +import kotlin.time.Duration.Companion.seconds class SniffingNodeSelectorTest : SearchTestBase() { @Test fun shouldPickSameNodeGivenSameAffinity() = coRun { - // FIXME this test fails occasionally - // bug with sniffing kicking in somehow and clearing the affinity map? val ids = (0..5).map { "thread-${Random.nextULong()}" } coroutineScope { - val firstSelectedHosts = ids.map { id -> - async(AffinityId(id)) { - id to client.restClient.nextNode().host - } - }.awaitAll().toMap() - delay(1000) - ids.map { id -> - async(AffinityId(id)) { - id to client.restClient.nextNode().host + eventually(duration = 10.seconds) { + // this fails occasionally bug with sniffing kicking in and clearing the affinity map + // so use eventually to work around this + + val firstSelectedHosts = ids.map { id -> + async(AffinityId(id)) { + id to client.restClient.nextNode().host + } + }.awaitAll().toMap() + delay(1000) + ids.map { id -> + async(AffinityId(id)) { + id to client.restClient.nextNode().host + } + }.awaitAll().forEach { (id, host) -> + host shouldBe firstSelectedHosts[id] } - }.awaitAll().forEach { (id, host) -> - host shouldBe firstSelectedHosts[id] } } - } } \ No newline at end of file