1 package com.intellij.testFramework.fixtures.kotlin
3 import com.intellij.openapi.diagnostic.logger
5 class KtFlakyErrorWorkaround(private val setUp: () -> Unit,
6 private val tearDown: () -> Unit,
7 private val repeatCount: Int = 5) {
9 fun wrapFlaky(actualMessagePattern: Regex, body: () -> Unit): Unit =
10 repeatTest({ e -> e is AssertionError && e.actual.contains(actualMessagePattern) }, body)
12 fun wrapFlaky(actualMessagePattern: Regex, body: Runnable): Unit = wrapFlaky(actualMessagePattern) { body.run() }
14 fun repeatTest(repeatCondition: (Throwable) -> Boolean = { true }, body: () -> Unit) {
22 catch (e: Throwable) {
23 if (repeatCondition(e)) {
24 logger<KtFlakyErrorWorkaround>().warn("Workaround hit! ${e.javaClass} on try: $repeatedTimes")
27 if (repeatedTimes > repeatCount) {
28 logger<KtFlakyErrorWorkaround>().error("Workaround: hit too many times: $repeatedTimes, max is $repeatCount")
42 private val AssertionError.actual: String
44 is org.junit.ComparisonFailure -> this.actual
45 is junit.framework.ComparisonFailure -> this.actual