Skip to content

Wait for the deferred profiling integration swap in DeferredProfilingContextIntegrationTest - #13629

Draft
cgcote wants to merge 1 commit into
masterfrom
dd/automated/flaky-fix-deferred-profiling-context-2026-11-22
Draft

cgcote wants to merge 1 commit into
masterfrom
dd/automated/flaky-fix-deferred-profiling-context-2026-11-22

Conversation

@cgcote

@cgcote cgcote commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

What Does This Do

Makes DeferredProfilingContextIntegrationTest.deferredConstructionDoesNotRunOnTheCallingThread() wait until the deferred profiling integration has actually been swapped in before it asserts on the result. This is a test-only change, and all existing assertions are unchanged.

Motivation

Root cause: The test waited on FakeProcessContext.registered. In Agent.deferDdprofContextIntegration, the deferred factory calls registerProcessContext(classLoader) first, which releases that latch, and only then constructs DatadogProfilingIntegration (Agent.java:1561-1562). DeferredProfilingContextIntegration.initialize() swaps the delegate only after factory.call() returns. So the test thread could wake up between registration and construction, and fail with:

AssertionFailedError: expected: <1> but was: <0>
  at DeferredProfilingContextIntegrationTest.deferredConstructionDoesNotRunOnTheCallingThread(DeferredProfilingContextIntegrationTest.java:72)

The test now registers integration.whenAvailable(available::countDown) before it releases the gate, and waits on that latch. The callback is queued under the same lock as the delegate write, so it runs only after the swap. The now-unused FakeProcessContext.registered latch is removed.

Impact (Datadog Flaky Test Management):

  • Family: 1 test, datadog.trace.bootstrap.DeferredProfilingContextIntegrationTest.deferredConstructionDoesNotRunOnTheCallingThread().
  • Representative fingerprint: e8567673b55aae2b. Attempt-to-fix ID: PXS9RZ (DD_PXS9RZ).
  • CI impact: FTM reports a 0.22% failure rate, 4 failed pipelines and about 3.6h of CI time lost, on master and the merge queue.
  • FTM: https://app.datadoghq.com/ci/test/flaky?query=fingerprint_fqn%3Ae8567673b55aae2b

Additional Notes

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

  • Race reproduced: I temporarily added a delay between registerProcessContext and construction (local experiment only, since reverted). With that delay, the original test failed with expected: <1> but was: <0> at line 72. The fixed test passed with the same delay: 9 tests, 0 failures.
  • ./gradlew :dd-java-agent:agent-bootstrap:test --tests 'datadog.trace.bootstrap.DeferredProfilingContextIntegrationTest' --rerun, 5 runs on unmodified production code: all passed, 9 tests and 0 failures each time.
  • ./gradlew :dd-java-agent:agent-bootstrap:spotlessCheck: passed.
  • Only the session's local JVM was used. Other JVMs are left to CI.

Risks: Very low. Only the test changes, and there are no production code changes. There are no sleeps, timeout changes, relaxed assertions or quarantines.

Prepared in Bits Code session: https://app.datadoghq.com/code/6c755f89-8f5b-4850-aea7-dc3c6e85191b

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

Contributor Checklist

  • Title follows the contribution guidelines. Labels still need to be added: a type: label, a comp: label, 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 deferred factory registers the process context before constructing
the integration, and the delegate is swapped only after construction
returns. Awaiting the registration latch could therefore wake the test
thread before construction completed, failing the constructions == 1
assertion. Await whenAvailable instead, which fires after the swap, and
drop the now-unused registration latch.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-authored-by: cgcote <5115638+cgcote@users.noreply.github.com>
@datadog-prod-us1-4

Copy link
Copy Markdown

View session in Datadog

Bits Code status: ✅ Done

CI Auto-fix: Disabled | Enable

Comment @DataDog to request changes

@datadog-prod-us1-4

Copy link
Copy Markdown

🎯 Code Coverage (details)
• Patch Coverage: 100.00%
• Overall Coverage: 41.57% (-19.40%)

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

@dd-octo-sts

dd-octo-sts Bot commented Nov 22, 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.04 s 14.01 s [-0.6%; +1.0%] (no difference)
startup:insecure-bank:tracing:Agent 12.89 s 13.02 s [-1.6%; -0.3%] (maybe better)
startup:petclinic:appsec:Agent 17.30 s 17.12 s [-0.0%; +2.0%] (no difference)
startup:petclinic:iast:Agent 17.15 s 17.11 s [-0.6%; +1.1%] (no difference)
startup:petclinic:profiling:Agent 16.19 s 16.81 s [-8.0%; +0.7%] (no difference)
startup:petclinic:sca:Agent 17.31 s 17.09 s [+0.3%; +2.2%] (maybe worse)
startup:petclinic:tracing:Agent 16.24 s 16.40 s [-1.9%; -0.0%] (maybe better)

Commit: 82e65cec · 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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants