add TestKit.fishForMessage
This commit is contained in:
parent
6a2f203d26
commit
25f436d521
1 changed files with 21 additions and 0 deletions
|
|
@ -263,6 +263,27 @@ class TestKit(_app: AkkaApplication) {
|
||||||
f(o)
|
f(o)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hybrid of expectMsgPF and receiveWhile: receive messages while the
|
||||||
|
* partial function matches and returns false. Use it to ignore certain
|
||||||
|
* messages while waiting for a specific message.
|
||||||
|
*
|
||||||
|
* @return the last received messsage, i.e. the first one for which the
|
||||||
|
* partial function returned true
|
||||||
|
*/
|
||||||
|
def fishForMessage(max: Duration = Duration.MinusInf, hint: String = "")(f: PartialFunction[Any, Boolean]): Any = {
|
||||||
|
val _max = if (max eq Duration.MinusInf) remaining else max.dilated
|
||||||
|
val end = now + _max
|
||||||
|
@tailrec
|
||||||
|
def recv: Any = {
|
||||||
|
val o = receiveOne(end - now)
|
||||||
|
assert(o ne null, "timeout during fishForMessage, hint: " + hint)
|
||||||
|
assert(f.isDefinedAt(o), "fishForMessage(" + hint + ") found unexpected message " + o)
|
||||||
|
if (f(o)) o else recv
|
||||||
|
}
|
||||||
|
recv
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Same as `expectMsgType[T](remaining)`, but correctly treating the timeFactor.
|
* Same as `expectMsgType[T](remaining)`, but correctly treating the timeFactor.
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue