Skip to content

Commit

Permalink
Fix test flakyness
Browse files Browse the repository at this point in the history
  • Loading branch information
breskeby committed Nov 26, 2024
1 parent cf6816b commit c570637
Showing 1 changed file with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class BuildParameterExtensionSpec extends Specification {
def buildParams = extension(project, providers)
int numberOfThreads = 10;
when:
var service = Executors.newFixedThreadPool(10)
var service = Executors.newFixedThreadPool(numberOfThreads)
var latch = new CountDownLatch(numberOfThreads)
def testedProvider = buildParams."$getterName"()
def futures = (1..numberOfThreads).collect {
Expand All @@ -58,7 +58,7 @@ class BuildParameterExtensionSpec extends Specification {

then:
futures.size() == numberOfThreads
futures.collect { it.state() }.every { it == Future.State.SUCCESS }
futures.collect { it.state() }.any() { it == Future.State.FAILED } == false

where:
getterName << [
Expand Down Expand Up @@ -104,6 +104,10 @@ class BuildParameterExtensionSpec extends Specification {
println "accessing provider"
return counter.get() == 1 ? fail("Accessing cached provider more than once") : counter.incrementAndGet()
}
provider
provider.get() >> {
fail("Accessing cached provider directly")
}
return provider

}
}

0 comments on commit c570637

Please sign in to comment.