File tree Expand file tree Collapse file tree 2 files changed +37
-1
lines changed
modules/docs-tests/src/test/scala/sclicheck Expand file tree Collapse file tree 2 files changed +37
-1
lines changed Original file line number Diff line number Diff line change @@ -38,7 +38,7 @@ class DocTests extends munit.FunSuite {
38
38
md <- inputs
39
39
}
40
40
test(s " $tpe ${md.toString.stripSuffix(" .md" )}" ) {
41
- checkFile(dir / md, options)
41
+ TestUtil .retryOnCi()( checkFile(dir / md, options) )
42
42
}
43
43
44
44
}
Original file line number Diff line number Diff line change 1
1
package sclicheck
2
2
3
+ import scala .annotation .tailrec
4
+ import scala .concurrent .duration .{DurationInt , FiniteDuration }
5
+
3
6
object TestUtil {
7
+ val isCI : Boolean = System .getenv(" CI" ) != null
4
8
5
9
def withTmpDir [T ](prefix : String )(f : os.Path => T ): T = {
6
10
val tmpDir = os.temp.dir(prefix = prefix)
@@ -20,4 +24,36 @@ object TestUtil {
20
24
sys.error(" SCLICHECK_SCALA_CLI not set" )
21
25
}
22
26
27
+ def retry [T ](
28
+ maxAttempts : Int = 3 ,
29
+ waitDuration : FiniteDuration = 5 .seconds
30
+ )(
31
+ run : => T
32
+ ): T = {
33
+ @ tailrec
34
+ def helper (count : Int ): T =
35
+ try run
36
+ catch {
37
+ case t : Throwable =>
38
+ if (count >= maxAttempts) {
39
+ System .err.println(s " $maxAttempts attempts failed, caught $t. Giving up. " )
40
+ throw new Exception (t)
41
+ }
42
+ else {
43
+ val remainingAttempts = maxAttempts - count
44
+ System .err.println(
45
+ s " Caught $t, $remainingAttempts attempts remaining, trying again in $waitDuration… "
46
+ )
47
+ Thread .sleep(waitDuration.toMillis)
48
+ System .err.println(s " Trying attempt $count out of $maxAttempts... " )
49
+ helper(count + 1 )
50
+ }
51
+ }
52
+
53
+ helper(1 )
54
+ }
55
+
56
+ def retryOnCi [T ](maxAttempts : Int = 3 , waitDuration : FiniteDuration = 5 .seconds)(
57
+ run : => T
58
+ ): T = retry(if (isCI) maxAttempts else 1 , waitDuration)(run)
23
59
}
You can’t perform that action at this time.
0 commit comments