Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
=tes akka#24270 expectNoMessage should pull the unexpected msg (akka#…
…24271)

* =tes akka#24270 expectNoMessage should pull the unexpected msg from the queue

* Update TestKit.scala
  • Loading branch information
ktoso authored and manonthegithub committed Jan 31, 2018
1 parent f648682 commit 2f8683b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
16 changes: 12 additions & 4 deletions akka-testkit/src/main/scala/akka/testkit/TestKit.scala
Expand Up @@ -679,10 +679,18 @@ trait TestKitBase {
elem = queue.peekFirst()
}
}
val diff = (max.toNanos - left.toNanos).nanos
val m = s"received unexpected message $elem after ${diff.toMillis} millis"
assert(elem eq null, m)
lastWasNoMsg = true

if (elem ne null) {
// we pop the message, such that subsequent expectNoMessage calls can
// assert on the next period without a message
queue.pop()

val diff = (max.toNanos - left.toNanos).nanos
val m = s"assertion failed: received unexpected message $elem after ${diff.toMillis} millis"
throw new java.lang.AssertionError(m)
} else {
lastWasNoMsg = true
}
}

/**
Expand Down
21 changes: 18 additions & 3 deletions akka-testkit/src/test/scala/akka/testkit/TestProbeSpec.scala
@@ -1,15 +1,18 @@
package akka.testkit

import language.postfixOps

import akka.actor._
import scala.concurrent.{ Await }

import scala.concurrent.Await
import scala.concurrent.duration._
import akka.pattern.ask

import scala.util.Try
import java.util.concurrent.atomic.AtomicInteger

class TestProbeSpec extends AkkaSpec with DefaultTimeout {
import org.scalatest.concurrent.Eventually

class TestProbeSpec extends AkkaSpec with DefaultTimeout with Eventually {

"A TestProbe" must {

Expand Down Expand Up @@ -201,6 +204,18 @@ class TestProbeSpec extends AkkaSpec with DefaultTimeout {
val probe = new TestProbe(system)
probe.ref.path.name should startWith("testProbe")
}

"expectNoMessage should pull the thingy" in {
val p = new TestProbe(system)

p.ref ! "nein" // no
p.ref ! "nie" // no

eventually(p.expectNoMessage(100.millis))

p.ref ! "tak" // yes
p.expectMsg("tak")
}
}

}

0 comments on commit 2f8683b

Please sign in to comment.