A configuration parameter that specifies the number of dismissals to wait for before returning normally
from an await call on a Waiter.
A TimeoutConfigParam that specifies the amount of time to sleep after
each retry: each unsuccessful invocation of the by-name parameter passed to eventually or
each query of a future passed to whenReady.
A TimeoutConfigParam that specifies the maximum amount of time to allow retries: either invocations of the
by-name parameter passed to eventually that give an unsuccessful result, or futures passed to whenReady that
are canceled, or expired, or not ready.
Configuration object for traits Eventually and Futures.
Abstract class defining a family of configuration parameters for traits Eventually and Futures.
Class that facilitates performing assertions outside the main test thread, such as assertions in callback methods that are invoked asynchronously.
Returns a Dismissals configuration parameter containing the passed value, which
specifies the number of dismissals to wait for before returning normally from an await
call on a Waiter.
Returns an Interval configuration parameter containing the passed value, which
specifies the amount of time to sleep after
each retry: each unsuccessful invocation of the by-name parameter passed to eventually
or each query of a non-ready, canceled, or expired future passed to whenReady.
Returns an Interval configuration parameter containing the passed value, which
specifies the amount of time to sleep after
each retry: each unsuccessful invocation of the by-name parameter passed to eventually
or each query of a non-ready, canceled, or expired future passed to whenReady.
Returns a Timeout configuration parameter containing the passed value, which
specifies the maximum amount of time to retry: to allow invocations of the
by-name parameter passed to eventually to give an unsuccessful result, or to
allow a future passed to whenReady to be canceled, or expired, or not ready.
Returns a Timeout configuration parameter containing the passed value, which
specifies the maximum amount of time to retry: to allow invocations of the
by-name parameter passed to eventually to give an unsuccessful result, or to
allow a future passed to whenReady to be canceled, or expired, or not ready.
Implicit TimeoutConfig value providing default configuration values.
Implicit TimeoutConfig value providing default configuration values.
To change the default configuration, override or hide this val with another implicit
TimeoutConfig containing your desired default configuration values.
Trait that facilitates performing assertions outside the main test thread, such as assertions in callback methods that are invoked asynchronously.
Trait
AsyncAssertionsprovides aWaiterclass that you can use to orchestrate the inter-thread communication required to perform assertions outside the main test thread, and means to configure it.To use
Waiter, create an instance of it in the main test thread:At some point later, call
awaiton the waiter:The
awaitcall will block until it either receives a report of a failed assertion from a different thread, at which point it will complete abruptly with the same exception, or until it is dismissed by a different thread (or threads), at which point it will return normally. You can optionally specify a timeout, interval (the timeawaitsleeps between checks), and/or a number of dismissals to wait for. Here's an example:The default value for
timeout, provided via an implicitTimeoutConfigparameter, is 1 second. The default value fordismissalsis 1. Theawaitmethod will block until either it is dismissed a sufficient number of times by other threads or an assertion fails in another thread. Thus if you just want to perform assertions in just one other thread, only that thread will be performing a dismissal, so you can use the default value of 1 fordismissals.Waitercontains several overloaded forms ofawait, most of which take an implicitTimeoutConfigparameter. To change the default timeout configuration, override or hide (if you imported the members ofAsyncAssertionscompanion object instead of mixing in the trait)timeoutConfigwith a new one that returns your desired configuration.To dismiss a waiter, you just invoke
dismisson it:You may want to put
dismissinvocations in a finally clause to ensure they happen even if an exception is thrown. Otherwise if a dismissal is missed because of a thrown exception, anawaitcall will wait until it times out.Finally, to perform an assertion in a different thread, you just apply the
Waiterto the assertion code. Here are some examples:w { assert(1 + 1 === 3) } // Can use assertions w { 1 + 1 should equal (3) } // Or matchers w { "hi".charAt(-1) } // Any exceptions will be forwarded to awaitHere's a complete example: