FSMTimingSpec overhaul
- revise timings to make them more robust (granularity changed in general from 100ms to 500ms) - make one test more deterministic by awaiting context.hasMessages, which has been added for this purpose; is the same kind of “non-racy” as isShutdown - add static version of TestKit.awaitCond (checked that it does not conflict, even when “import TestKit._” is used; seems like imports are not even searched if the symbol is found locally)
This commit is contained in:
parent
4f4227acf3
commit
6559511bce
3 changed files with 92 additions and 44 deletions
|
|
@ -555,6 +555,36 @@ class TestKit(_app: AkkaApplication) {
|
|||
|
||||
object TestKit {
|
||||
private[testkit] val testActorId = new AtomicInteger(0)
|
||||
|
||||
/**
|
||||
* Block until the given condition evaluates to `true` or the timeout
|
||||
* expires, whichever comes first.
|
||||
*
|
||||
* If no timeout is given, take it from the innermost enclosing `within`
|
||||
* block.
|
||||
*
|
||||
* Note that the timeout is scaled using Duration.timeFactor.
|
||||
*/
|
||||
def awaitCond(p: ⇒ Boolean, max: Duration, interval: Duration = 100.millis) {
|
||||
val stop = now + max
|
||||
|
||||
@tailrec
|
||||
def poll(t: Duration) {
|
||||
if (!p) {
|
||||
assert(now < stop, "timeout " + max + " expired")
|
||||
Thread.sleep(t.toMillis)
|
||||
poll((stop - now) min interval)
|
||||
}
|
||||
}
|
||||
|
||||
poll(max min interval)
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtain current timestamp as Duration for relative measurements (using System.nanoTime).
|
||||
*/
|
||||
def now: Duration = System.nanoTime().nanos
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue