Skip to content

Commit

Permalink
work around test flakiness with eventually
Browse files Browse the repository at this point in the history
  • Loading branch information
jillesvangurp committed Dec 9, 2024
1 parent a4f36e0 commit 3916118
Showing 1 changed file with 18 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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]
}
}

}
}

0 comments on commit 3916118

Please sign in to comment.