Skip to content

Commit

Permalink
Add CI mode and drastically increase time limit
Browse files Browse the repository at this point in the history
  • Loading branch information
japgolly committed Dec 9, 2020
1 parent dda7c26 commit 60aecb9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .travis.yml
Expand Up @@ -6,6 +6,9 @@ scala:
jdk:
- openjdk8

env:
- CI=1

script:
- sbt test

Expand Down
18 changes: 17 additions & 1 deletion src/test/scala/tla2json/TestUtil.scala
Expand Up @@ -21,6 +21,22 @@ object TestUtil extends japgolly.microlibs.testutil.TestUtil {
assertEq(actual, e)
}

private def sysPropOrEnvVar(name: String): String =
Option(System.getProperty(name)).orElse(Option(System.getenv(name)))
.fold("")(_.trim.toLowerCase)

private val inCI: Boolean =
sysPropOrEnvVar("CI") == "1"

if (inCI)
println("============ CI MODE DETECTED ============")

private val defaultTimeLimit: Duration =
if (inCI)
Duration.ofSeconds(2)
else
Duration.ofSeconds(30)

def timeLimitedLazy[A](task: => A)(implicit l: Line): () => A = {
val lock = new AnyRef
var result = Option.empty[A]
Expand All @@ -37,7 +53,7 @@ object TestUtil extends japgolly.microlibs.testutil.TestUtil {
}

def timeLimited[A](task: => A)(implicit l: Line): A =
runWithTimeLimit(Duration.ofSeconds(2))(task)
runWithTimeLimit(defaultTimeLimit)(task)

def runWithTimeLimit[A](maxDur: Duration)(task: => A)(implicit l: Line): A =
runAttemptWithTimeLimit(maxDur)(task).getOrElse(fail("Task didn't complete within " + maxDur))
Expand Down

0 comments on commit 60aecb9

Please sign in to comment.