package concurrent
ScalaTest's main traits, classes, and other members, including members supporting ScalaTest's DSL for the Scala interpreter.
- Alphabetic
- By Inheritance
- concurrent
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Type Members
-
trait
AbstractPatienceConfiguration extends ScaledTimeSpans
Trait that defines an abstract
patienceConfigmethod that is implemented inPatienceConfigurationand can be overriden in stackable modification traits such asIntegrationPatience.Trait that defines an abstract
patienceConfigmethod that is implemented inPatienceConfigurationand can be overriden in stackable modification traits such asIntegrationPatience.The main purpose of
AbstractPatienceConfigurationis to differentiate corePatienceConfigurationtraits, such asEventuallyandWaiters, from stackable modification traits forPatienceConfigurations such asIntegrationPatience. Because these stackable traits extendAbstractPatienceConfigurationinstead ofSuite, you can't simply mix in a stackable trait:class ExampleSpec extends FunSpec with IntegrationPatience // Won't compile
The previous code is undesirable because
IntegrationPatiencewould have no affect on the class. Instead, you need to mix in a corePatienceConfigurationtrait and mix the stackableIntegrationPatiencetrait into that, like this:class ExampleSpec extends FunSpec with Eventually with IntegrationPatience // Compiles fine
The previous code is better because
IntegrationPatiencedoes have an effect: it modifies the behavior ofEventually. -
trait
AsyncCancelAfterFailure extends AsyncTestSuiteMixin
Trait that when mixed into a
AsyncTestSuitecancels any remaining tests in thatAsyncTestSuiteinstance after a test fails.Trait that when mixed into a
AsyncTestSuitecancels any remaining tests in thatAsyncTestSuiteinstance after a test fails.The intended use case for this trait is if you have a suite of long-running tests that are related such that if one fails, you aren't interested in running the others, you can use this trait to simply cancel any remaining tests, so you need not wait long for them to complete.
-
trait
AsyncTimeLimitedTests extends AsyncTestSuiteMixin with TimeLimits
Trait that when mixed into an asynchronous suite class establishes a time limit for its tests.
Trait that when mixed into an asynchronous suite class establishes a time limit for its tests.
This trait overrides
withFixture, wrapping asuper.withFixture(test)call in afailAfterinvocation, specifying a timeout obtained by invokingtimeLimit:failAfter(timeLimit) { super.withFixture(test) }Note that the
failAftermethod executes the body of the by-name passed to it using the same thread that invokedfailAfter. This means that the calling ofwithFixturemethod will be run using the same thread, but the test body may be run using a different thread, depending on theexecutionContextset at theAsyncTestSuitelevel.The
timeLimitfield is abstract in this trait. Thus you must specify a time limit when you use it. For example, the following code specifies that each test must complete within 200 milliseconds:import org.scalatest.AsyncFunSpec import org.scalatest.concurrent.AsyncTimeLimitedTests import org.scalatest.time.SpanSugar._ class ExampleSpec extends AsyncFunSpec with AsyncTimeLimitedTests { // Note: You may need to either write 200.millis or (200 millis), or // place a semicolon or blank line after plain old 200 millis, to // avoid the semicolon inference problems of postfix operator notation. val timeLimit = 200 millis describe("An asynchronous time-limited test") { it("should succeed if it completes within the time limit") { Thread.sleep(100) succeed } it("should fail if it is taking too darn long") { Thread.sleep(300) succeed } } }If you run the above
ExampleSpec, the second test will fail with the error message:The test did not complete within the specified 200 millisecond time limit.Different from
TimeLimitedTests,AsyncTimeLimitedTestsdoes not supportInterruptorfor now. -
trait
Futures extends PatienceConfiguration
Trait that facilitates testing with futures.
Trait that facilitates testing with futures.
This trait defines a
FutureConcepttrait that can be used to implicitly wrap different kinds of futures, thereby providing a uniform testing API for futures. The three ways this trait enables you to test futures are:1. Invoking
isReadyWithin, to assert that a future is ready within a a specified time period. Here's an example:assert(result.isReadyWithin(100 millis))
2. Invoking
futureValue, to obtain a futures result within a specified or implicit time period, like this:assert(result.futureValue === 7) // Or, if you expect the future to fail: assert(result.failed.futureValue.isInstanceOf[ArithmeticException])
3. Passing the future to
whenReady, and performing assertions on the result value passed to the given function, as in:whenReady(result) { s => s should be ("hello") }The
whenReadyconstruct periodically inspects the passed future, until it is either ready or the configured timeout has been surpassed. If the future becomes ready before the timeout,whenReadypasses the future's value to the specified function.To make
whenReadymore broadly applicable, the type of future it accepts is aFutureConcept[T], whereTis the type of value promised by the future. Passing a future towhenReadyrequires an implicit conversion from the type of future you wish to pass (the modeled type) toFutureConcept[T]. SubtraitJavaFuturesprovides an implicit conversion fromjava.util.concurrent.Future[T]toFutureConcept[T].For example, the following invocation of
whenReadywould succeed (not throw an exception):import org.scalatest._ import Matchers._ import concurrent.Futures._ import java.util.concurrent._ val exec = Executors.newSingleThreadExecutor val task = new Callable[String] { def call() = { Thread.sleep(50); "hi" } } whenReady(exec.submit(task)) { s => s should be ("hi") }However, because the default timeout is 150 milliseconds, the following invocation of
whenReadywould ultimately produce aTestFailedException:val task = new Callable[String] { def call() = { Thread.sleep(500); "hi" } } whenReady(exec.submit(task)) { s => s should be ("hi") }Assuming the default configuration parameters, a
timeoutof 150 milliseconds and anintervalof 15 milliseconds, were passed implicitly towhenReady, the detail message of the thrownTestFailedExceptionwould look like:The future passed to whenReady was never ready, so whenReady timed out. Queried 95 times, sleeping 10 milliseconds between each query.Configuration of
whenReadyThe
whenReadymethods of this trait can be flexibly configured. The two configuration parameters forwhenReadyalong with their default values and meanings are described in the following table:Configuration Parameter Default Value Meaning timeout scaled(150 milliseconds) the maximum amount of time to allow unsuccessful queries before giving up and throwing TestFailedExceptioninterval scaled(15 milliseconds) the amount of time to sleep between each query The default values of both timeout and interval are passed to the
scaledmethod, inherited fromScaledTimeSpans, so that the defaults can be scaled up or down together with other scaled time spans. See the documentation for traitScaledTimeSpansfor more information.The
whenReadymethods of traitFutureseach take aPatienceConfigobject as an implicit parameter. This object provides values for the two configuration parameters. TraitFuturesprovides an implicitvalnameddefaultPatiencewith each configuration parameter set to its default value. If you want to set one or more configuration parameters to a different value for all invocations ofwhenReadyin a suite you can override this val (or hide it, for example, if you are importing the members of theFuturescompanion object rather than mixing in the trait). For example, if you always want the defaulttimeoutto be 2 seconds and the defaultintervalto be 5 milliseconds, you can overridedefaultPatience, like this:implicit override val defaultPatience = PatienceConfig(timeout = Span(2, Seconds), interval = Span(5, Millis))
Or, hide it by declaring a variable of the same name in whatever scope you want the changed values to be in effect:
implicit val defaultPatience = PatienceConfig(timeout = Span(2, Seconds), interval = Span(5, Millis))
In addition to taking a
PatienceConfigobject as an implicit parameter, thewhenReadymethods of traitFuturesinclude overloaded forms that take one or twoPatienceConfigParamobjects that you can use to override the values provided by the implicitPatienceConfigfor a singlewhenReadyinvocation. For example, if you want to settimeoutto 6 seconds for just one particularwhenReadyinvocation, you can do so like this:whenReady (exec.submit(task), timeout(Span(6, Seconds))) { s => s should be ("hi") }This invocation of
eventuallywill use 6000 fortimeoutand whatever value is specified by the implicitly passedPatienceConfigobject for theintervalconfiguration parameter. If you want to set both configuration parameters in this way, just list them separated by commas:whenReady (exec.submit(task), timeout(Span(6, Seconds)), interval(Span(500, Millis))) { s => s should be ("hi") }You can also import or mix in the members of
SpanSugarif you want a more concise DSL for expressing time spans:whenReady (exec.submit(task), timeout(6 seconds), interval(500 millis)) { s => s should be ("hi") }Note: The
whenReadyconstruct was in part inspired by thewhenDeliveredmatcher of the BlueEyes project, a lightweight, asynchronous web framework for Scala. -
trait
IntegrationPatience extends AbstractPatienceConfiguration
Stackable modification trait for
PatienceConfigurationthat provides default timeout and interval values appropriate for integration testing.Stackable modification trait for
PatienceConfigurationthat provides default timeout and interval values appropriate for integration testing.The default values for the parameters are:
Configuration Parameter Default Value timeoutscaled(15 seconds)intervalscaled(150 milliseconds)The default values of both timeout and interval are passed to the
scaledmethod, inherited fromScaledTimeSpans, so that the defaults can be scaled up or down together with other scaled time spans. See the documentation for traitScaledTimeSpansfor more information.Mix this trait into any class that uses
PatienceConfiguration(such as classes that mix inEventuallyorWaiters) to get timeouts tuned towards integration testing, like this:class ExampleSpec extends FeatureSpec with Eventually with IntegrationPatience { // ... } -
trait
PatienceConfiguration extends AbstractPatienceConfiguration
Trait providing methods and classes used to configure timeouts and, where relevant, the interval between retries.
Trait providing methods and classes used to configure timeouts and, where relevant, the interval between retries.
This trait is called
PatienceConfigurationbecause it allows configuration of two values related to patience: The timeout specifies how much time asynchronous operations will be given to succeed before giving up. The interval specifies how much time to wait between checks to determine success when polling.The default values for timeout and interval provided by trait
PatienceConfigurationare tuned for unit testing, where running tests as fast as possible is a high priority and subsystems requiring asynchronous operations are therefore often replaced by mocks. This table shows the default values:Configuration Parameter Default Value timeoutscaled(150 milliseconds)intervalscaled(15 milliseconds)Values more appropriate to integration testing, where asynchronous operations tend to take longer because the tests are run against the actual subsytems (not mocks), can be obtained by mixing in trait
IntegrationPatience.The default values of both timeout and interval are passed to the
scaledmethod, inherited fromScaledTimeSpans, so that the defaults can be scaled up or down together with other scaled time spans. See the documentation for traitScaledTimeSpansfor more information.Timeouts are used by the
eventuallymethods of traitEventuallyand theawaitmethod of classWaiter, a member of traitWaiters. Intervals are used by theeventuallymethods. -
trait
ScalaFutures extends Futures
Provides an implicit conversion from
scala.concurrent.Future[T]toFutureConcept[T].Provides an implicit conversion from
scala.concurrent.Future[T]toFutureConcept[T].This trait enables you to invoke the methods defined on
FutureConcepton a ScalaFuture, as well as to pass a Scala future to thewhenReadymethods of supertraitFutures. The three ways this trait enables you to test futures are:1. Invoking
isReadyWithin, to assert that a future is ready within a a specified time period. Here's an example:assert(result.isReadyWithin(100 millis))
2. Invoking
futureValue, to obtain a futures result within a specified or implicit time period, like this:assert(result.futureValue === 7) // Or, if you expect the future to fail: assert(result.failed.futureValue.isInstanceOf[ArithmeticException])
3. Passing the future to
whenReady, and performing assertions on the result value passed to the given function, as in:whenReady(result) { s => s should be ("hello") }The
whenReadyconstruct periodically inspects the passed future, until it is either ready or the configured timeout has been surpassed. If the future becomes ready before the timeout,whenReadypasses the future's value to the specified function.To make
whenReadymore broadly applicable, the type of future it accepts is aFutureConcept[T], whereTis the type of value promised by the future. Passing a future towhenReadyrequires an implicit conversion from the type of future you wish to pass (the modeled type) toFutureConcept[T]. SubtraitJavaFuturesprovides an implicit conversion fromjava.util.concurrent.Future[T]toFutureConcept[T].For example, the following invocation of
whenReadywould succeed (not throw an exception):import org.scalatest._ import Matchers._ import concurrent.Futures._ import java.util.concurrent._ val exec = Executors.newSingleThreadExecutor val task = new Callable[String] { def call() = { Thread.sleep(50); "hi" } } whenReady(exec.submit(task)) { s => s should be ("hi") }However, because the default timeout is 150 milliseconds, the following invocation of
whenReadywould ultimately produce aTestFailedException:val task = new Callable[String] { def call() = { Thread.sleep(500); "hi" } } whenReady(exec.submit(task)) { s => s should be ("hi") }Assuming the default configuration parameters, a
timeoutof 150 milliseconds and anintervalof 15 milliseconds, were passed implicitly towhenReady, the detail message of the thrownTestFailedExceptionwould look like:The future passed to whenReady was never ready, so whenReady timed out. Queried 95 times, sleeping 10 milliseconds between each query.Configuration of
whenReadyThe
whenReadymethods of this trait can be flexibly configured. The two configuration parameters forwhenReadyalong with their default values and meanings are described in the following table:Configuration Parameter Default Value Meaning timeout scaled(150 milliseconds) the maximum amount of time to allow unsuccessful queries before giving up and throwing TestFailedExceptioninterval scaled(15 milliseconds) the amount of time to sleep between each query The default values of both timeout and interval are passed to the
scaledmethod, inherited fromScaledTimeSpans, so that the defaults can be scaled up or down together with other scaled time spans. See the documentation for traitScaledTimeSpansfor more information.The
whenReadymethods of traitFutureseach take aPatienceConfigobject as an implicit parameter. This object provides values for the two configuration parameters. TraitFuturesprovides an implicitvalnameddefaultPatiencewith each configuration parameter set to its default value. If you want to set one or more configuration parameters to a different value for all invocations ofwhenReadyin a suite you can override this val (or hide it, for example, if you are importing the members of theFuturescompanion object rather than mixing in the trait). For example, if you always want the defaulttimeoutto be 2 seconds and the defaultintervalto be 5 milliseconds, you can overridedefaultPatience, like this:implicit override val defaultPatience = PatienceConfig(timeout = Span(2, Seconds), interval = Span(5, Millis))
Or, hide it by declaring a variable of the same name in whatever scope you want the changed values to be in effect:
implicit val defaultPatience = PatienceConfig(timeout = Span(2, Seconds), interval = Span(5, Millis))
In addition to taking a
PatienceConfigobject as an implicit parameter, thewhenReadymethods of traitFuturesinclude overloaded forms that take one or twoPatienceConfigParamobjects that you can use to override the values provided by the implicitPatienceConfigfor a singlewhenReadyinvocation. For example, if you want to settimeoutto 6 seconds for just one particularwhenReadyinvocation, you can do so like this:whenReady (exec.submit(task), timeout(Span(6, Seconds))) { s => s should be ("hi") }This invocation of
eventuallywill use 6000 fortimeoutand whatever value is specified by the implicitly passedPatienceConfigobject for theintervalconfiguration parameter. If you want to set both configuration parameters in this way, just list them separated by commas:whenReady (exec.submit(task), timeout(Span(6, Seconds)), interval(Span(500, Millis))) { s => s should be ("hi") }You can also import or mix in the members of
SpanSugarif you want a more concise DSL for expressing time spans:whenReady (exec.submit(task), timeout(6 seconds), interval(500 millis)) { s => s should be ("hi") }Note: The
whenReadyconstruct was in part inspired by thewhenDeliveredmatcher of the BlueEyes project, a lightweight, asynchronous web framework for Scala. -
trait
ScaledTimeSpans extends AnyRef
Trait providing a
scaledmethod that can be used to scale timeSpans used during the testing of asynchronous operations.Trait providing a
scaledmethod that can be used to scale timeSpans used during the testing of asynchronous operations.The
scaledmethod allows tests of asynchronous operations to be tuned according to need. For example,Spans can be scaled larger when running tests on slower continuous integration servers or smaller when running on faster development machines.The
Doublefactor by which to scale theSpans passed toscaledis obtained from thespanScaleFactormethod, also declared in this trait. By default this method returns 1.0, but can be configured to return a different value by passing a-Fargument toRunner(or an equivalent mechanism in an ant, sbt, or Maven build file).The default timeouts and intervals defined for traits
EventuallyandWaitersinvokescaled, so those defaults will be scaled automatically. Other than such defaults, however, to get aSpanto scale you'll need to explicitly pass it toscaled. For example, here's how you would scale aSpanyou supply to thefailAftermethod from traitTimeouts:failAfter(scaled(150 millis)) { // ... }The reason
Spans are not scaled automatically in the general case is to make code obvious. If a reader seesfailAfter(1 second), it will mean exactly that: fail after one second. And if aSpanwill be scaled, the reader will clearly see that as well:failAfter(scaled(1 second)).Overriding
spanScaleFactorYou can override the
spanScaleFactormethod to configure the factor by a different means. For example, to configure the factor from Akka TestKit's test time factor you might create a trait like this:import org.scalatest.concurrent.ScaledTimeSpans import akka.actor.ActorSystem import akka.testkit.TestKitExtension trait AkkaSpanScaleFactor extends ScaledTimeSpans { override def spanScaleFactor: Double = TestKitExtension.get(ActorSystem()).TestTimeFactor }This trait overrides
spanScaleFactorso that it takes its scale factor from Akka'sapplication.conffile. You could then scaleSpans tenfold in Akka's configuration file like this:akka { test { timefactor = 10.0 } }Armed with this trait and configuration file, you can simply mix trait
AkkaSpanScaleFactorinto any test class whoseSpans you want to scale, like this:class MySpec extends FunSpec with Eventually with AkkaSpanScaleFactor { // .. } -
class
SelectorSignaler extends Signaler
Strategy for signaling an operation in which
wakeupis called on thejava.nio.channels.Selectorpassed to the constructor.Strategy for signaling an operation in which
wakeupis called on thejava.nio.channels.Selectorpassed to the constructor.This class can be used for configuration when using traits
TimeLimitsandTimeLimitedTests. -
trait
Signaler extends AnyRef
Strategy for signaling an operation after a timeout expires.
Strategy for signaling an operation after a timeout expires.
An instance of this trait is used for configuration when using traits
TimeLimitsandTimeLimitedTests. -
class
SocketSignaler extends Signaler
Strategy for signaling an operation in which
closeis called on thejava.net.Socketpassed to the constructor.Strategy for signaling an operation in which
closeis called on thejava.net.Socketpassed to the constructor.This class can be used for configuration when using traits
TimeLimitsandTimeLimitedTests. -
trait
TimeLimitedTests extends TestSuiteMixin
Trait that when mixed into a suite class establishes a time limit for its tests.
Trait that when mixed into a suite class establishes a time limit for its tests.
Unfortunately this trait experienced a potentially breaking change in 3.0: previously this trait declared a
defaultTestInterruptorvalof typeInterruptor, in 3.0 that was renamed todefaultTestSignalerand given typeSignaler. The reason is that the defaultInterruptor,ThreadInterruptor, did not make sense on Scala.js—in fact, the entire notion of interruption did not make sense on Scala.js.Signaler's default isDoNotSignal, which is a better default on Scala.js, and works fine as a default on the JVM.Timeoutswas left the same in 3.0, so existing code using it would continue to work as before, but after a deprecation periodTimeoutswill be supplanted byTimeLimits, which usesSignaler.TimeLimitedTestsnow usesTimeLimitsinstead ofTimeouts, so if you overrode the defaultInterruptorbefore, you'll need to change it to the equivalentSignaler. And if you were depending on the default being aThreadInterruptor, you'll need to overridedefaultTestSignalerand set it toThreadSignaler.This trait overrides
withFixture, wrapping asuper.withFixture(test)call in afailAfterinvocation, specifying a time limit obtained by invokingtimeLimitand aSignalerby invokingdefaultTestSignaler:failAfter(timeLimit) { super.withFixture(test) } (defaultTestSignaler)Note that the
failAftermethod executes the body of the by-name passed to it using the same thread that invokedfailAfter. This means that the same thread will run thewithFixturemethod as well as each test, so no extra synchronization is required. A second thread is used to run a timer, and if the timeout expires, that second thread will attempt to signal the main test thread via thedefaultTestSignaler.The
timeLimitfield is abstract in this trait. Thus you must specify a time limit when you use it. For example, the following code specifies that each test must complete within 200 milliseconds:import org.scalatest.FunSpec import org.scalatest.concurrent.TimeLimitedTests import org.scalatest.time.SpanSugar._ class ExampleSpec extends FunSpec with TimeLimitedTests { // Note: You may need to either write 200.millis or (200 millis), or // place a semicolon or blank line after plain old 200 millis, to // avoid the semicolon inference problems of postfix operator notation. val timeLimit = 200 millis describe("A time-limited test") { it("should succeed if it completes within the time limit") { Thread.sleep(100) } it("should fail if it is taking too darn long") { Thread.sleep(300) } } }If you run the above
ExampleSpec, the second test will fail with the error message:The test did not complete within the specified 200 millisecond time limit.The
failAftermethod uses anSignalerto attempt to signal the main test thread if the timeout expires. The defaultSignalerreturned by thedefaultTestSignalermethod is aDoNotSignal, which does not signal the main test thread to stop. If you wish to change this signaling strategy, overridedefaultTestSignalerto return a differentSignaler. For example, here's how you'd change the default toThreadSignaler, which will interrupt the main test thread when time is up:import org.scalatest.FunSpec import org.scalatest.concurrent.{ThreadSignaler, TimeLimitedTests} import org.scalatest.time.SpanSugar._ class ExampleSignalerSpec extends FunSpec with TimeLimitedTests { val timeLimit = 200 millis override val defaultTestSignaler = ThreadSignaler describe("A time-limited test") { it("should succeed if it completes within the time limit") { Thread.sleep(100) } it("should fail if it is taking too darn long") { Thread.sleep(300) } } }Like the previous incarnation of
ExampleSuite, the second test will fail with an error message that indicates a timeout expired. But whereas in the previous case, theThread.sleepwould be interrupted after 200 milliseconds, in this case it is never interrupted. In the previous case, the failed test requires a little over 200 milliseconds to run. In this case, because thesleep(300)is never interrupted, the failed test requires a little over 300 milliseconds to run. -
trait
TimeLimits extends AnyRef
Trait that provides
failAfterandcancelAftermethods, which allow you to specify a time limit for an operation passed as a by-name parameter, as well as a way to signal it if the operation exceeds its time limit.Trait that provides
failAfterandcancelAftermethods, which allow you to specify a time limit for an operation passed as a by-name parameter, as well as a way to signal it if the operation exceeds its time limit.The time limit is passed as the first parameter, as a
Span. The operation is passed as the second parameter. ASignaler, a strategy for interrupting the operation, is passed as an implicit third parameter. Here's a simple example of its use:failAfter(Span(100, Millis)) { Thread.sleep(200) }The above code will eventually produce a
TestFailedDueToTimeoutExceptionwith a message that indicates a time limit has been exceeded:The code passed to failAfter did not complete within 100 milliseconds.If you use
cancelAfterin place offailAfter, aTestCanceledExceptionwill be thrown instead, also with a message that indicates a time limit has been exceeded:The code passed to cancelAfter did not complete within 100 milliseconds.If you prefer you can mix in or import the members of
SpanSugarand place a units value after the integer timeout. Here are some examples:import org.scalatest.time.SpanSugar._ failAfter(100 millis) { Thread.sleep(200) } failAfter(1 second) { Thread.sleep(2000) }The code passed via the by-name parameter to
failAfterorcancelAfterwill be executed by the thread that invokedfailAfterorcancelAfter, so that no synchronization is necessary to access variables declared outside the by-name.var result = -1 // No need to make this volatile failAfter(100 millis) { result = accessNetService() } result should be (99)The
failAfterorcancelAftermethod will create a timer that runs on a different thread than the thread that invokedfailAfterorcancelAfter, so that it can detect when the time limit has been exceeded and attempt to signal the main thread. Because different operations can require different signaling strategies, thefailAfterandcancelAftermethods accept an implicit third parameter of typeSignalerthat is responsible for signaling the main thread.Configuring
failAfterorcancelAfterwith aSignalerThe
Signalercompanion object declares an implicitvalof typeSignalerthat returns aDoNotSignal. This serves as the default signaling strategy. If you wish to use a different strategy, you can declare an implicitvalthat establishes a differentSignaleras the policy. Here's an example in which the default signaling strategy is changed toThreadSignaler, which does not attempt to interrupt the main thread in any way:override val signaler: Signaler = ThreadSignaler failAfter(100 millis) { Thread.sleep(500) }As with the default
Signaler, the above code will eventually produce aTestFailedDueToTimeoutExceptionwith a message that indicates a timeout expired. However, instead of throwing the exception after approximately 500 milliseconds, it will throw it after approximately 100 milliseconds.This illustrates an important feature of
failAfterandcancelAfter: it will throw aTestFailedDueToTimeoutException(orTestCanceledExceptionin case ofcancelAfter) if the code passed as the by-name parameter takes longer than the specified timeout to execute, even if it is allowed to run to completion beyond the specified timeout and returns normally.ScalaTest provides the following
Signalerimplementations:SignalerimplementationUsage DoNotSignal The default signaler, does not attempt to interrupt the main test thread in any way ThreadSignaler Invokes interrupton the main test thread. This will set the interrupted status for the main test thread and, if the main thread is blocked, will in some cases cause the main thread to complete abruptly with anInterruptedException.SelectorSignaler Invokes wakeupon the passedjava.nio.channels.Selector, which will cause the main thread, if blocked inSelector.select, to complete abruptly with aClosedSelectorException.SocketSignaler Invokes closeon thejava.io.Socket, which will cause the main thread, if blocked in a read or write of anjava.io.InputStreamorjava.io.OutputStreamthat uses theSocket, to complete abruptly with aSocketException.You may wish to create your own
Signalerin some situations. For example, if your operation is performing a loop and can check a volatile flag each pass through the loop, you could write aSignalerthat sets that flag so that the next time around, the loop would exit.
Value Members
-
object
DoNotSignal extends Signaler
Signaling strategy in which nothing is done to try and signal or interrupt an operation.
Signaling strategy in which nothing is done to try and signal or interrupt an operation.
This object can be used for configuration when using traits
TimeLimitsandTimeLimitedTests. - object PatienceConfiguration
-
object
ScalaFutures extends ScalaFutures
Companion object that facilitates the importing of
ScalaFuturesmembers as an alternative to mixing in the trait.Companion object that facilitates the importing of
ScalaFuturesmembers as an alternative to mixing in the trait. One use case is to importScalaFutures's members so you can use them in the Scala interpreter. -
object
SelectorSignaler
Companion object that provides a factory method for a
SelectorSignaler. -
object
Signaler
Companion object that provides a factory method for a
Singlaerdefined in terms of a function from a function of typeThreadto Unit. -
object
SocketSignaler
Companion object that provides a factory method for a
SocketSignaler. - object TestExecutionContext
-
object
ThreadSignaler extends Signaler
Strategy for signaling an operation in which
interruptis called on theThreadpassed toapply.Strategy for signaling an operation in which
interruptis called on theThreadpassed toapply.This object can be used for configuration when using traits
TimeLimitsandTimeLimitedTests. -
object
TimeLimits extends TimeLimits
Companion object that facilitates the importing of
Timeoutsmembers as an alternative to mixing in the trait.Companion object that facilitates the importing of
Timeoutsmembers as an alternative to mixing in the trait. One use case is to importTimeouts's members so you can use them in the Scala interpreter.