Created
March 6, 2019 16:17
-
-
Save Malinskiy/6b62fa6729384ee07aa7ee87a712a0eb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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