@@ -35,7 +35,7 @@ final class TestFeatureProvider private (
3535 private val eventsHubRef : Ref [Hub [ProviderEvent ]],
3636 private [openfeature] val statusRef : Ref [ProviderStatus ],
3737 private val initLatch : Option [CountDownLatch ],
38- private val initDone : Option [CountDownLatch ]
38+ private [testkit] val initDone : Option [CountDownLatch ]
3939) extends EventProvider {
4040
4141 @ scala.annotation.nowarn(" msg=deprecated" )
@@ -51,7 +51,9 @@ final class TestFeatureProvider private (
5151 case None => ()
5252 }
5353 state.set(ProviderState .READY )
54- initDone.foreach(_.countDown()) // Signal that initialize() has completed
54+ // Note: initDone is NOT counted down here. It is counted down by the event bridge's
55+ // readyHandler when the Java SDK fires PROVIDER_READY, ensuring the SDK has fully
56+ // processed the initialization before setStatus(Ready) returns.
5557 }
5658
5759 override def shutdown (): Unit = {
@@ -196,8 +198,9 @@ final class TestFeatureProvider private (
196198 case ProviderStatus .Ready =>
197199 state.set(ProviderState .READY )
198200 initLatch.foreach(_.countDown())
199- // Wait for the Java SDK's background initialize() thread to complete, ensuring
200- // the provider is fully registered before evaluations are attempted.
201+ // Wait for the event bridge to receive PROVIDER_READY from the Java SDK.
202+ // This confirms the SDK has fully processed the initialization and the
203+ // provider is registered as ready — no sleep needed.
201204 initDone.foreach(_.await())
202205 case ProviderStatus .NotReady => state.set(ProviderState .NOT_READY )
203206 case ProviderStatus .Error => state.set(ProviderState .ERROR )
@@ -380,7 +383,13 @@ object TestFeatureProvider {
380383 api = OpenFeatureAPIFactory .create()
381384 domain = s " test-async- ${java.util.UUID .randomUUID()}"
382385 featureFlags <- FeatureFlags
383- .fromProviderWithDomainAsync(testProvider, domain, testProvider.statusRef, api = Some (api))
386+ .fromProviderWithDomainAsync(
387+ testProvider,
388+ domain,
389+ testProvider.statusRef,
390+ api = Some (api),
391+ onReady = testProvider.initDone
392+ )
384393 .build
385394 .map(_.get)
386395 } yield (testProvider, featureFlags)
0 commit comments