Skip to content

Make AsyncReadyLayerSpec deterministic via TestClock#117

Merged
EtaCassiopeia merged 1 commit into
mainfrom
test/asyncreadylayer-deterministic
May 13, 2026
Merged

Make AsyncReadyLayerSpec deterministic via TestClock#117
EtaCassiopeia merged 1 commit into
mainfrom
test/asyncreadylayer-deterministic

Conversation

@EtaCassiopeia
Copy link
Copy Markdown
Owner

@EtaCassiopeia EtaCassiopeia commented May 13, 2026

Summary

AsyncReadyLayerSpec was racing wall-clock timing. The test under `@@ TestAspect.withLiveClock` asserted that providerStatus starts as NotReady then transitions to Ready after a 50ms async delay. On slow CI runners, layer construction itself could take longer than 50ms, causing the first providerStatus read to already see Ready and the assertion to fail. Previously hit in #116's CI run (#25769211402).

Fix

Removed withLiveClock and replaced ZIO.sleep with TestClock.adjust. The forked transition fiber inside asyncReadyLayer uses ZIO.sleep(initDelay), which under TestClock suspends indefinitely until the clock is explicitly advanced. This eliminates the race:

  1. Layer constructs. Transition fiber forks and suspends on TestClock.sleep(50.millis).
  2. Test reads status → guaranteed NotReady.
  3. Test calls TestClock.adjust(60.millis) → fiber's sleep elapses, fiber flips status.
  4. Test polls via repeatUntil(_ == Ready) to await the flip (bounded by a 5s live-clock timeout for safety).

Side benefit: the suite now runs in ~160ms instead of ~1.5s (no live-clock sleeps).

Files

  • testkit/src/test/scala/zio/openfeature/testkit/AsyncReadyLayerSpec.scala

@EtaCassiopeia EtaCassiopeia merged commit e679c1a into main May 13, 2026
1 check passed
@EtaCassiopeia EtaCassiopeia deleted the test/asyncreadylayer-deterministic branch May 13, 2026 00:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant