Skip to content

Instantly share code, notes, and snippets.

@Malinskiy
Created March 6, 2019 16:17
Show Gist options
  • Save Malinskiy/6b62fa6729384ee07aa7ee87a712a0eb to your computer and use it in GitHub Desktop.
Save Malinskiy/6b62fa6729384ee07aa7ee87a712a0eb to your computer and use it in GitHub Desktop.
class ProbabilityBasedFlakinessStrategy(val minSuccessRate: Double,
val maxCount: Int,
val timeLimit: Instant) : FlakinessStrategy {
override fun process(testShard: TestShard,
metricsProvider: MetricsProvider): TestShard {
val tests = testShard.tests
val output = mutableListOf<Test>()
tests.forEach {
val successRate = metricsProvider.successRate(it, timeLimit)
if (successRate < minSuccessRate) {
val maxFailRate = 1.0 - minSuccessRate
var currentFailRate = 1.0 - successRate
var counter = 0
while (currentFailRate > maxFailRate && counter < maxCount) {
output.add(it)
currentFailRate *= currentFailRate
counter++
}
}
}
return testShard.copy(flakyTests = output)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment