# How to wait until the child actors are active?

**URL:** https://discuss.akka.io/t/how-to-wait-until-the-child-actors-are-active/4974
**Category:** Akka Libraries
**Tags:** akka
**Created:** [September 1, 2019, 1:11pm UTC](https://discuss.akka.io/t/how-to-wait-until-the-child-actors-are-active/4974 "2019-09-01T13:11:50Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![bifunctor](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.akka.io/bifunctor/32/1335_2.png) [@bifunctor](https://discuss.akka.io/u/bifunctor)
#### Post date: [September 1, 2019, 1:11pm UTC](https://discuss.akka.io/t/how-to-wait-until-the-child-actors-are-active/4974/1 "2019-09-01T13:11:50Z")

</div>

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:

```auto
  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:

```auto
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

---

<div class="post-metadata">

### Author: ![patriknw](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.akka.io/patriknw/32/89_2.png) [@patriknw](https://discuss.akka.io/u/patriknw)
#### Post date: [September 1, 2019, 6:56pm UTC](https://discuss.akka.io/t/how-to-wait-until-the-child-actors-are-active/4974/2 "2019-09-01T18:56:10Z")

</div>

Depends on how the child actors are created and why they are not ready immediately. How would the real application handle that they are not ready?

Possible solution could be that the parent stash all incoming messages until children are ready. Another could be to send back a rejection message and let the requestor (the test in this case) retry.

---

<div class="post-metadata">

### Author: ![bifunctor](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.akka.io/bifunctor/32/1335_2.png) [@bifunctor](https://discuss.akka.io/u/bifunctor)
#### Post date: [September 3, 2019, 11:08am UTC](https://discuss.akka.io/t/how-to-wait-until-the-child-actors-are-active/4974/3 "2019-09-03T11:08:29Z")

</div>

@patriknw Thanks so much for your response. I stash all incoming message and when the child is ready, then unstash it.

Thanks
