I'm looking at the below testing code and I believe it is incorrect.
"send the event to our test actor" in {
val testA = TestActorRef[TestEventSource]
testA ! RegisterListener(testActor)
testA.underlyingActor.sendEvent("Fibonacci")
expectMsg("Fibonacci")
}
Specifically, `testA.underlyingActor.sendEvent("Fibonacci")` could be executed before the testA actor has a chance to process the RegisterListener message, because the two are ran on different threads.
There's a little trick involved in the TestActorRef - and the book doesn't make this clear at all - it overrides the dispatcher to use the CallingThreadDispatcher. So, there's no race condition here.