Skip to content

Commit

Permalink
improvement: Add a larger timeout for tests and don't wait
Browse files Browse the repository at this point in the history
  • Loading branch information
tgodzik committed Jun 23, 2023
1 parent 1765a76 commit 58fb709
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 13 deletions.
29 changes: 16 additions & 13 deletions frontend/src/test/scala/bloop/TestSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -389,24 +389,27 @@ object JvmTestSpec extends BaseTestSpec("test-project-test", "cross-test-build-s
}

object NoTestFrameworksSpec extends ProjectBaseSuite("no-test-frameworks") {
testProject("must have frameworks in test project", runOnlyOnJava8 = false) { (build, logger) =>
val project = build.projectFor("myProject")
val testState = build.state.test(project)
try {
assert(!testState.status.isOk)
assert(logger.errors.contains("Missing configured test frameworks in myProject-test"))
} catch { case err: AssertionError => logger.dump(); throw err }
testProjectTask("must have frameworks in test project", runOnlyOnJava8 = false) {
(build, logger) =>
val project = build.projectFor("myProject")
build.state.testTask(project).map { testState =>
try {
assert(!testState.status.isOk)
assert(logger.errors.contains("Missing configured test frameworks in myProject-test"))
} catch { case err: AssertionError => logger.dump(); throw err }
}
}

testProject("non-test projects can have empty frameworks", runOnlyOnJava8 = false) {
testProjectTask("non-test projects can have empty frameworks", runOnlyOnJava8 = false) {
(rawBuild, logger) =>
val build = rawBuild.filterProjectsByName(!_.endsWith("-test"))
val project = build.projectFor("myProject")
val testState = build.state.test(project)
try {
assert(testState.status.isOk)
// No message is logged - this is not a test target, and therefore it is ignored.
} catch { case err: AssertionError => logger.dump(); throw err }
build.state.testTask(project).map { testState =>
try {
assert(testState.status.isOk)
// No message is logged - this is not a test target, and therefore it is ignored.
} catch { case err: AssertionError => logger.dump(); throw err }
}
}
}

Expand Down
4 changes: 4 additions & 0 deletions frontend/src/test/scala/bloop/testing/BloopHelpers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,10 @@ trait BloopHelpers {
test(project, Nil, Nil)
}

def testTask(project: TestProject): Task[TestState] = {
testTask(project, Nil, Nil)
}

def testHandle(
project: TestProject,
only: List[String],
Expand Down
15 changes: 15 additions & 0 deletions frontend/src/test/scala/bloop/testing/ProjectBaseSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import java.nio.file.Files
import bloop.io.AbsolutePath
import bloop.io.Paths
import bloop.logging.RecordingLogger
import bloop.task.Task
import scala.concurrent.duration.Duration

class ProjectBaseSuite(buildName: String) extends BaseSuite {
val workspace: AbsolutePath = AbsolutePath(Files.createTempDirectory(s"workspace-${buildName}"))
Expand All @@ -22,6 +24,19 @@ class ProjectBaseSuite(buildName: String) extends BaseSuite {
else test(name)(fun(newBuild, newLogger))
}

def testProjectTask(
name: String,
runOnlyOnJava8: Boolean,
maxDuration: Duration = Duration("60s")
)(
fun: (TestBuild, RecordingLogger) => Task[Unit]
): Unit = {
val newLogger = new RecordingLogger(ansiCodesSupported = false)
val newBuild = build.withLogger(newLogger)
if (runOnlyOnJava8) testOnlyOnJava8(name)(fun(newBuild, newLogger))
else testTask(name, maxDuration)(fun(newBuild, newLogger))
}

override def test(name: String)(fun: => Any): Unit = {
super.test(name)(fun)
}
Expand Down

0 comments on commit 58fb709

Please sign in to comment.