title: Wait until the supervisor is ready before execute the test
body: <p>I have written a test for my actors as follows:</p>
  
  <pre><code>class DetectorSpec extends BddSpec {
  
      private val sap = new SapMock()
          .withExposedPorts(8080)
          .waitingFor(Wait.forHttp("/"))
  
      private val kafka = new KafkaContainer("5.2.1")
  
  
      sap.start()
      kafka.start()
  
  
      override def afterAll(): Unit = {
          sap.stop()
          kafka.stop()
      }
  
      private def withKafkaOfflineSapOnline(testCode: TestProbe[ServerEvent] =&gt; Unit)
      : Unit = {
  
          val config = ConfigFactory.parseString(
          s"""
              kafka {
                  servers = "127.0.0.1:9092"
              }
              sap {
                  server = "ws://${sap.getContainerIpAddress}:${sap.getMappedPort(8080)}"
              }""")
  
          val testKit = ActorTestKit("testSystem1", config)
          val inbox = testKit.createTestProbe[ServerEvent]("Receiver")
          testKit.spawn(DetectorSupervisor.create(), "DetectorSupervisor")
          testKit.system.receptionist ! Receptionist.Register(ServerStateKey, inbox.ref)
  
          Thread.sleep(4000)
  
          testCode(inbox)
          testKit.shutdownTestKit()
      }
  
  
      feature("Detect Kafka and SAP availability") {
          scenario("SAP is online and Kafka is offline") {
          withKafkaOfflineSapOnline { inbox =&gt;
                  Given("I am waiting for the current state message")
                  When("I am receive the state message")
                  val msg = inbox.receiveMessage(3.second)
                  Then("it should contain `Kafka is offline`")
                  msg should be(ServerOnlineApproved)
              }
          }
  
      }
  }
  </code></pre>
  
  <p>As you can see in the fixture method <code>withKafkaOfflineSapOnline</code>, there is a statement <code>Thread.sleep(4000)</code> to make it sure,
  that actor <code>DetectorSupervisor</code> with they children is ready before the test get started.  </p>
  
  <p>Is there a better way to do it? </p>
  
  <p>Without the <code>Thread.sleep(4000)</code> statement, it seems to be, that the actors are not ready, when the test is starting. </p>