Skip to content

Wait for the evaluator runtime before asserting in DDEvaluatorTest shutdown test - #13864

Draft
colin-higgins wants to merge 1 commit into
masterfrom
dd/automated/flaky-fix-openfeature-evaluator-runtime-publication-2026-12-06
Draft

colin-higgins wants to merge 1 commit into
masterfrom
dd/automated/flaky-fix-openfeature-evaluator-runtime-publication-2026-12-06

Conversation

@colin-higgins

@colin-higgins colin-higgins commented Dec 6, 2026 •

Copy link
Copy Markdown
Member

What Does This Do

Makes DDEvaluatorTest.testShutdownWhileInitializationWaitsForConfiguration() wait until the evaluator's initialize has assigned its runtime before the test asserts on evaluator.runtime(). This is a test-only change: it adds four lines (a comment and synchronized (evaluator) {}) right after the subscribed latch wait. All existing assertions are unchanged.

Motivation

Root cause: DDEvaluator.initialize holds the evaluator's monitor while it calls FeatureFlagsRuntime.acquire(...), and assigns this.runtime = acquired only after acquire returns. acquire starts the runtime, and RemoteConfigurationService.start subscribes through the test's mocked bridge.remoteConfiguration(). That mock lambda calls subscribed.countDown(). So the latch can open while the executor thread is still inside initialize, before runtime is assigned. other.initialize(0, MILLISECONDS, null) uses a different monitor and returns right away. The volatile, unsynchronized evaluator.runtime() can then still be null:

org.opentest4j.AssertionFailedError: expected: <com.datadog.openfeature.internal.FeatureFlagsRuntime@...> but was: <null>
  at com.datadog.openfeature.DDEvaluatorTest.testShutdownWhileInitializationWaitsForConfiguration(DDEvaluatorTest.java:217)

The latch is released while the executor thread holds the evaluator's monitor. The main thread can therefore take that monitor only after the initialization block has finished, so runtime is guaranteed to be assigned. This removes the race instead of making it less likely.

Impact (Datadog Flaky Test Management):

  • Family: 1 test, com.datadog.openfeature.DDEvaluatorTest.testShutdownWhileInitializationWaitsForConfiguration().
  • Representative fingerprint: 759017606e2db1af. Attempt-to-fix ID: K659GS (DD_K659GS).
  • CI impact: FTM reports a 1.83% failure rate, 20 failed pipelines and about 89h of CI time lost. Test events show failing attempts in 145 distinct pipelines over 30 days, on master and feature branches, across JVMs (for example Semeru 17).
  • FTM: https://app.datadoghq.com/ci/test/flaky?query=fingerprint_fqn%3A759017606e2db1af

Additional Notes

Testing (run in the Bits Code session, as reported by the session):

  • Race reproduced: I temporarily added a delay between acquire and the runtime assignment, limited to the executor's pool-* threads (local experiment only, since reverted with git checkout). With that delay, ./gradlew :dd-openfeature:test --tests 'com.datadog.openfeature.DDEvaluatorTest.testShutdownWhileInitializationWaitsForConfiguration' --rerun failed on the original test with the CI error at DDEvaluatorTest.java:217. It passed with the fix. A delay on every thread did not reproduce the failure, because the same delay also slowed other.initialize.
  • ./gradlew :dd-openfeature:test --tests 'com.datadog.openfeature.DDEvaluatorTest' --rerun, 5 runs on unmodified production code: all passed, 125 tests and 0 failures each time.
  • ./gradlew :dd-openfeature:spotlessCheck: passed, after spotlessApply.
  • Only the session's default JVM was used. Other JVMs are left to CI.

Alternatives considered: Moving the runtime assignment ahead of the subscription in production code would change DDEvaluator's initialization semantics for a test-only ordering issue. A sleep or a longer wait would only make the failure less likely.

Risks: Very low. Only the test changes, with no production changes. There are no sleeps, timeout changes, relaxed assertions or quarantines. SpotBugs is not applied to test tasks, so the empty synchronized block does not trigger a detector.

Prepared in Bits Code session: https://app.datadoghq.com/code/fcb342a9-a54b-4488-82db-97966225aa90

This PR was opened by the dd-trace Flaky-Test ROI Recommender via Bits Code.

Contributor Checklist

  • Title follows the contribution guidelines. Labels: type: bug fix, comp: openfeature, tag: flaky test, tag: ai generated and tag: no release notes (test-only).
  • No source files were added, moved or deleted, so no CODEOWNERS change is needed.
  • No configuration flags or public documentation changes.

Jira ticket: N/A


PR by Bits - View session in Datadog

Comment @DataDog to request changes

The Remote Configuration subscription fires inside the evaluator's
synchronized initialization, before it assigns its runtime, so the test
could read a null runtime. Wait for the evaluator to release its monitor
before comparing runtimes.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-authored-by: colin-higgins <1801443+colin-higgins@users.noreply.github.com>
@datadog-official

Copy link
Copy Markdown
Contributor

View session in Datadog

Bits Code status: ✅ Done

CI Auto-fix: Disabled | Enable

Comment @DataDog to request changes

@datadog-datadog-prod-us1 datadog-datadog-prod-us1 Bot added Bits AI comp: openfeature OpenFeature tag: ai generated Largely based on code generated by an AI or LLM tag: flaky test Flaky tests tag: no release notes Changes to exclude from release notes type: bug fix Bug fix labels Dec 6, 2026
@datadog-official

Copy link
Copy Markdown
Contributor

🎯 Code Coverage (details)
• Patch Coverage: 100.00%
• Overall Coverage: 92.36% (+30.40%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: e2a42d5 | Docs | Give us feedback!

@dd-octo-sts

dd-octo-sts Bot commented Dec 6, 2026

Copy link
Copy Markdown
Contributor

🟢 Java Benchmark SLOs — All performance SLOs passed

Suite Status
Startup 🟢 pass

SLO thresholds are defined here based on automatically generated metrics. A warning is raised when results are within 5% of the threshold.

PR vs. master results
Scenario Candidate master Δ (95% CI of mean)
startup:insecure-bank:iast:Agent 14.12 s 13.99 s [+0.1%; +1.9%] (maybe worse)
startup:insecure-bank:tracing:Agent 13.02 s 13.04 s [-0.8%; +0.4%] (no difference)
startup:petclinic:appsec:Agent 16.75 s 17.15 s [-6.6%; +1.9%] (no difference)
startup:petclinic:iast:Agent 17.24 s 17.22 s [-0.6%; +0.8%] (no difference)
startup:petclinic:profiling:Agent 16.98 s 16.93 s [-0.8%; +1.4%] (no difference)
startup:petclinic:sca:Agent 17.25 s 17.00 s [+0.7%; +2.3%] (maybe worse)
startup:petclinic:tracing:Agent 15.87 s 16.23 s [-6.4%; +1.9%] (no difference)

Commit: e2a42d55 · CI Pipeline · Benchmarking Platform UI


Load and DaCapo benchmarks can be triggered manually in the GitLab pipeline. Results will appear in the Benchmarking Platform UI after completion.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bits AI comp: openfeature OpenFeature tag: ai generated Largely based on code generated by an AI or LLM tag: flaky test Flaky tests tag: no release notes Changes to exclude from release notes type: bug fix Bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants