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.
Invokes the passed by-name parameter repeatedly until it either succeeds, or a configured maximum amount of time has passed, sleeping a configured interval between attempts.
Invokes the passed by-name parameter repeatedly until it either succeeds, or a configured maximum amount of time has passed, sleeping a configured interval between attempts.
The by-name parameter "succeeds" if it returns a result. It "fails" if it throws any exception that
would normally cause a test to fail. (These are any exceptions except TestPendingException and
Errors listed in the
Treatment of java.lang.Errors section of the
documentation of trait Suite.)
The maximum amount of time in milliseconds to tolerate unsuccessful attempts before giving up is configured by the timeout field of
the TimeoutConfig passed implicitly as the last parameter.
The interval to sleep between attempts is configured by the interval field of
the TimeoutConfig passed implicitly as the last parameter.
the by-name parameter to repeatedly invoke
the TimeoutConfig object containing the timeout and
interval parameters
the result of invoking the fun by-name parameter, the first time it succeeds
Invokes the passed by-name parameter repeatedly until it either succeeds, or a configured maximum amount of time has passed, sleeping a configured interval between attempts.
Invokes the passed by-name parameter repeatedly until it either succeeds, or a configured maximum amount of time has passed, sleeping a configured interval between attempts.
The by-name parameter "succeeds" if it returns a result. It "fails" if it throws any exception that
would normally cause a test to fail. (These are any exceptions except TestPendingException and
Errors listed in the
Treatment of java.lang.Errors section of the
documentation of trait Suite.)
The maximum amount of time in milliseconds to tolerate unsuccessful attempts before giving up is configured by the timeout field of
the TimeoutConfig passed implicitly as the last parameter.
The interval to sleep between attempts is configured by the value contained in the passed
interval parameter.
the Interval configuration parameter
the by-name parameter to repeatedly invoke
the TimeoutConfig object containing the (used) timeout and
(unused) interval parameters
the result of invoking the fun by-name parameter, the first time it succeeds
Invokes the passed by-name parameter repeatedly until it either succeeds, or a configured maximum amount of time has passed, sleeping a configured interval between attempts.
Invokes the passed by-name parameter repeatedly until it either succeeds, or a configured maximum amount of time has passed, sleeping a configured interval between attempts.
The by-name parameter "succeeds" if it returns a result. It "fails" if it throws any exception that
would normally cause a test to fail. (These are any exceptions except TestPendingException and
Errors listed in the
Treatment of java.lang.Errors section of the
documentation of trait Suite.)
The maximum amount of time in milliseconds to tolerate unsuccessful attempts before giving up and throwing
TestFailedException is configured by the value contained in the passed
timeout parameter.
The interval to sleep between attempts is configured by the interval field of
the TimeoutConfig passed implicitly as the last parameter.
the Timeout configuration parameter
the by-name parameter to repeatedly invoke
the TimeoutConfig object containing the (unused) timeout and
(used) interval parameters
the result of invoking the fun by-name parameter, the first time it succeeds
Invokes the passed by-name parameter repeatedly until it either succeeds, or a configured maximum amount of time has passed, sleeping a configured interval between attempts.
Invokes the passed by-name parameter repeatedly until it either succeeds, or a configured maximum amount of time has passed, sleeping a configured interval between attempts.
The by-name parameter "succeeds" if it returns a result. It "fails" if it throws any exception that
would normally cause a test to fail. (These are any exceptions except TestPendingException and
Errors listed in the
Treatment of java.lang.Errors section of the
documentation of trait Suite.)
The maximum amount of time in milliseconds to tolerate unsuccessful attempts before giving up and throwing
TestFailedException is configured by the value contained in the passed
timeout parameter.
The interval to sleep between attempts is configured by the value contained in the passed
interval parameter.
the Timeout configuration parameter
the Interval configuration parameter
the by-name parameter to repeatedly invoke
the result of invoking the fun by-name parameter, the first time it succeeds
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 provides the
eventuallyconstruct, which periodically retries executing a passed by-name parameter, until it either succeeds or the configured timeout has been surpassed.The by-name parameter "succeeds" if it returns a result. It "fails" if it throws any exception that would normally cause a test to fail. (These are any exceptions except
TestPendingExceptionandErrors listed in the Treatment ofjava.lang.Errors section of the documentation of traitSuite.)For example, the following invocation of
eventuallywould succeed (not throw an exception):val xs = 1 to 125 val it = xs.iterator eventually { it.next should be (3) }However, because the default timeout is one second, the following invocation of
eventuallywould ultimately produce aTestFailedException:val xs = 1 to 125 val it = xs.iterator eventually { Thread.sleep(999); it.next should be (110) }Assuming the default configuration parameters, a
timeoutof 1 second and anintervalof 10 milliseconds, were passed implicitly toeventually, the detail message of the thrownTestFailedExceptionwould look like:The code passed to eventually never returned normally. Attempted 2 times, sleeping 10 milliseconds between each attempt.Configuration of
eventuallyThe
eventuallymethods of this trait can be flexibly configured. The two configuration parameters foreventuallyalong with their default values and meanings are described in the following table:TestFailedExceptionThe
eventuallymethods of traitEventuallyeach take anTimeoutConfigobject as an implicit parameter. This object provides values for the two configuration parameters. TraitEventuallyprovides an implicitvalnamedretryConfigwith 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 ofeventuallyin a suite you can override this val (or hide it, for example, if you are importing the members of theEventuallycompanion 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 overrideretryConfig, like this:Or, hide it by declaring a variable of the same name in whatever scope you want the changed values to be in effect:
In addition to taking a
TimeoutConfigobject as an implicit parameter, theeventuallymethods of traitEventuallyinclude overloaded forms that take one or twoTimeoutConfigParamobjects that you can use to override the values provided by the implicitTimeoutConfigfor a singleeventuallyinvocation. For example, if you want to settimeoutto 5000 for just one particulareventuallyinvocation, you can do so like this:eventually (timeout(Span(5, Seconds))) { Thread.sleep(10); it.next should be (110) }This invocation of
eventuallywill use 5 seconds for thetimeoutand whatever value is specified by the implicitly passedTimeoutConfigobject for theintervalconfiguration parameter. If you want to set both configuration parameters in this way, just list them separated by commas:eventually (timeout(Span(5, Seconds)), interval(Span(5, Millis)) { it.next should be (110) }You can also import or mix in the members of
SpanSugarif you want a more concise DSL for expressing time spans:eventually (timeout(5 seconds), interval(5 millis) { it.next should be (110) }