Hi all
I would like to test my supervisor actor, that spawns two children. The problem is, the test does not wait, until the children of the supervisor actor get started.
I am using ActorTestKit
, to start the supervisor as follows:
private val onlineStoreTest = ActorTestKit("StoreTestOnline", withStoreOnlineConfig())
implicit val system = onlineStoreTest.system.toUntyped
implicit val materializer = ActorMaterializer()(onlineStoreTest.system)
private val communicator = onlineStoreTest.createTestProbe[RpcCmd]("Communicator")
private val trash = onlineStoreTest.createTestProbe[TrashTalk]("TrashTalk")
private val onlineStore = onlineStoreTest.spawn(PersistenceSupervisor(Some(communicator.ref), trash.ref).create, "OnlineStoreActor")
and the test:
Given("a messages receives from KAFKA")
val msg = Message("TEST-KAFKA", "TESTED", """{data: payload}""", KAFKA)
When("write into the store")
onlineStore ! SavePersistenceMessage(SaveMessage(msg))
onlineStore ! SavePersistenceMessage(SaveMessage(msg))
onlineStore ! SavePersistenceMessage(SaveMessage(msg))
And("read the written messages from store")
Then("it should redirect the messages to the communicator")
communicator.receiveMessage(10.seconds) should be(SendMessage(msg))
The problem here is, the children actor in the PersistenceSupervisor
are not ready at the time the test starts. So the test just walk through.
The question is, before the test get started, how to wait until the supervisor and children are completely ready.
Thanks