Skip to content

Commit

Permalink
fix: do not skip timeout exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
symbiont-eric-torreborre committed Feb 14, 2022
1 parent b9a1b17 commit 2476639
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ trait ResultExecution:
Failure(e.getMessage.notNull, "", e.getStackTrace.toList, details = FromJUnitAssertionError)
case e: java.lang.Error if simpleClassName(e) == "ExpectationError" =>
Failure(e.toString, "", e.getStackTrace.toList, details = FromExpectationError)
case e: TimeoutException => Skipped(e.getMessage)
case NonFatal(t) => Error(t)
case NonFatal(t) => Error(t)

/** execute a Result and rethrow any exception or throws an exception if it is not a success */
def effectively(result: =>Result): Result =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import scala.scalajs.*
import org.scalajs.macrotaskexecutor.MacrotaskExecutor
import specification.core.*
import runner.*
import main.*

class MacrotaskExecutorSpec(env: Env) extends Specification:
def is = s2"""
Expand All @@ -17,7 +18,7 @@ class MacrotaskExecutorSpec(env: Env) extends Specification:

def timeoutExample =
given ExecutionContext = env.executionContext
TextRunner.runFuture(MacrotaskExecutorSpecification())(env).map { output =>
TextRunner.runFuture(MacrotaskExecutorSpecification())(env.setArguments(Arguments())).map { output =>
output.messages must contain(contain("timeout after"))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import scala.concurrent.*, duration.*
import LoopingCode.*
import specification.core.*
import runner.*
import main.*

class MacrotaskExecutorSpec(env: Env) extends Specification:
def is = s2"""
Expand All @@ -18,14 +19,14 @@ class MacrotaskExecutorSpec(env: Env) extends Specification:

def timeoutExample =
given ExecutionContext = env.executionContext
TextRunner.runFuture(MacrotaskExecutorSpecification())(env).map { output =>
TextRunner.runFuture(MacrotaskExecutorSpecification())(env.setArguments(Arguments())).map { output =>
output.messages must contain(contain("timeout after"))
}

class MacrotaskExecutorSpecification extends Specification:
def is = args.execute(timeout = 500.millis) ^ s2"""

An example can be timed-out when using ScalaJS $timeoutExample
An example can be timed-out $timeoutExample

"""

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ class ExecutorSpec(val env: Env) extends Specification with ThrownExpectations w
val fragments = Fragments(example("very slow", verySlow))
val env1 = ownEnv.setTimeout(100.millis * timeFactor.toLong)

execute(fragments, env1) must contain(beFailing[Result]("timeout after " + 100 * timeFactor + " milliseconds"))
execute(fragments, env1) must contain(beSkipped[Result]("timeout after " + 100 * timeFactor + " milliseconds"))

def userEnv =
val fragments =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import execute.*
import concurrent.*
import matcher.*
import specification.core.*
import main.*

class TimeoutSpec(env: Env) extends Specification with ResultMatchers:
def is = section("ci") ^ s2"""
Expand All @@ -17,12 +18,15 @@ class TimeoutSpec(env: Env) extends Specification with ResultMatchers:

def executionTimeout =
val execution = Execution.result { Thread.sleep(1000); ok }.setTimeout(100.millis)
execution.startExecution(env).executionResult.runOption(env.executionEnv) must beSome(beFailing[Result])
execution.startExecution(env).executionResult.runOption(env.executionEnv) must beSome(beSkipped[Result])

def timeout =
val messages = TextRunner.run(TimeoutSpecExample)(env).messages
val messages = TextRunner.run(TimeoutSpecExample)(env.setArguments(Arguments())).messages
messages must contain(
"[error] timeout after 100 milliseconds (TimeoutSpec.scala:31)"
allOf(
"[info] o timeout this example",
"[info] timeout after 100 milliseconds"
)
)

object TimeoutSpecExample extends Specification:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,11 @@ case class Execution(
else
Future.failed(FatalExecution(e.getCause))

// we catch timeout exceptions here when they are caused by the timeout argument
// and the skip the corresponding example
case e: TimeoutException =>
Future.successful((Skipped(e.getMessage), timer.stop))

case NonFatal(e) =>
// Future execution could still throw FailureExceptions or TimeoutExceptions
// which can only be recovered here
Expand Down

0 comments on commit 2476639

Please sign in to comment.