Repository navigation
Wait for the evaluator runtime before asserting in DDEvaluatorTest shutdown test - #13864
Draft
colin-higgins wants to merge 1 commit into
Draft
colin-higgins wants to merge 1 commit into
colin-higgins wants to merge 1 commit into
Conversation
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>
Contributor
Contributor
🟢 Java Benchmark SLOs — All performance SLOs passed
PR vs. master results
Commit: 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What Does This Do
Makes
DDEvaluatorTest.testShutdownWhileInitializationWaitsForConfiguration()wait until the evaluator'sinitializehas assigned its runtime before the test asserts onevaluator.runtime(). This is a test-only change: it adds four lines (a comment andsynchronized (evaluator) {}) right after thesubscribedlatch wait. All existing assertions are unchanged.Motivation
Root cause:
DDEvaluator.initializeholds the evaluator's monitor while it callsFeatureFlagsRuntime.acquire(...), and assignsthis.runtime = acquiredonly afteracquirereturns.acquirestarts the runtime, andRemoteConfigurationService.startsubscribes through the test's mockedbridge.remoteConfiguration(). That mock lambda callssubscribed.countDown(). So the latch can open while the executor thread is still insideinitialize, beforeruntimeis assigned.other.initialize(0, MILLISECONDS, null)uses a different monitor and returns right away. The volatile, unsynchronizedevaluator.runtime()can then still benull: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
runtimeis guaranteed to be assigned. This removes the race instead of making it less likely.Impact (Datadog Flaky Test Management):
com.datadog.openfeature.DDEvaluatorTest.testShutdownWhileInitializationWaitsForConfiguration().759017606e2db1af. Attempt-to-fix ID:K659GS(DD_K659GS).Additional Notes
Testing (run in the Bits Code session, as reported by the session):
acquireand theruntimeassignment, limited to the executor'spool-*threads (local experiment only, since reverted withgit checkout). With that delay,./gradlew :dd-openfeature:test --tests 'com.datadog.openfeature.DDEvaluatorTest.testShutdownWhileInitializationWaitsForConfiguration' --rerunfailed on the original test with the CI error atDDEvaluatorTest.java:217. It passed with the fix. A delay on every thread did not reproduce the failure, because the same delay also slowedother.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, afterspotlessApply.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
type: bug fix,comp: openfeature,tag: flaky test,tag: ai generatedandtag: no release notes(test-only).Jira ticket: N/A
PR by Bits - View session in Datadog
Comment @DataDog to request changes