+tes #15132 Add additional overloaded expectMsg to TestKit
This commit is contained in:
parent
e48b6b4185
commit
cdf2bc24d4
2 changed files with 48 additions and 4 deletions
|
|
@ -332,10 +332,20 @@ trait TestKitBase {
|
|||
*/
|
||||
def expectMsg[T](max: FiniteDuration, obj: T): T = expectMsg_internal(max.dilated, obj)
|
||||
|
||||
private def expectMsg_internal[T](max: Duration, obj: T): T = {
|
||||
/**
|
||||
* Receive one message from the test actor and assert that it equals the
|
||||
* given object. Wait time is bounded by the given duration, with an
|
||||
* AssertionFailure being thrown in case of timeout.
|
||||
*
|
||||
* @return the received object
|
||||
*/
|
||||
def expectMsg[T](max: FiniteDuration, hint: String, obj: T): T = expectMsg_internal(max.dilated, obj, Some(hint))
|
||||
|
||||
private def expectMsg_internal[T](max: Duration, obj: T, hint: Option[String] = None): T = {
|
||||
val o = receiveOne(max)
|
||||
assert(o ne null, s"timeout ($max) during expectMsg while waiting for $obj")
|
||||
assert(obj == o, s"expected $obj, found $o")
|
||||
lazy val hintOrEmptyString = hint.map(": " + _).getOrElse("")
|
||||
assert(o ne null, s"timeout ($max) during expectMsg while waiting for $obj" + hintOrEmptyString)
|
||||
assert(obj == o, s"expected $obj, found $o" + hintOrEmptyString)
|
||||
o.asInstanceOf[T]
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue