Skip to content

RUM-13141: Add integration test for OkHttp resource timing feature#3428

Merged
hamorillo merged 3 commits into
developfrom
hector.morilloprieto/RUM-13141
May 13, 2026
Merged

RUM-13141: Add integration test for OkHttp resource timing feature#3428
hamorillo merged 3 commits into
developfrom
hector.morilloprieto/RUM-13141

Conversation

@hamorillo

Copy link
Copy Markdown
Contributor

What does this PR do?

Adds an end-to-end integration test, ResourceTimingIntegrationTest, under reliability/single-fit/okhttp. The test wires DatadogInterceptor and DatadogEventListener.Factory on a real OkHttpClient against a MockWebServer and asserts that RUM resource events carry the timing breakdown sub-objects (dns / connect / first_byte / download).

Four cases:

  • Single HTTP request populates the full timing breakdown and omits the ssl section.
  • An HTTP 4xx response still produces a resource event with timings via the early-flush path in DatadogEventListener.responseHeadersEnd.
  • A dropped socket (SocketPolicy.DISCONNECT_AT_START) produces a RUM error event (not a resource event) with error.resource.url populated.
  • Five concurrent requests to the same URL each produce a distinct resource event with its own non-zero timing breakdown.

Motivation

The interceptor and the listener are independent OkHttp components that must agree on the ResourceId derived from the request tag for timing events to reach the correct resource scope. They also need to remain isolated under concurrent requests to the same URL. Both behaviors live at the integration seam and are not exercised by the existing unit tests of either component (which mock the GlobalRumMonitor). Past regressions in this area went out unnoticed; this test closes that coverage gap.

Review checklist (to be filled by reviewers)

  • Feature or bugfix MUST have appropriate tests (unit, integration, e2e)
  • Make sure you discussed the feature or bugfix with the maintaining team in an Issue
  • Make sure each commit and the PR mention the Issue number (cf the CONTRIBUTING doc)

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1ac1acc736

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@codecov-commenter

codecov-commenter commented May 11, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 72.03%. Comparing base (dcc5eb4) to head (a43824e).
⚠️ Report is 5 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #3428      +/-   ##
===========================================
- Coverage    72.08%   72.03%   -0.04%     
===========================================
  Files          961      961              
  Lines        35418    35418              
  Branches      5883     5883              
===========================================
- Hits         25528    25513      -15     
- Misses        8279     8287       +8     
- Partials      1611     1618       +7     

see 39 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@hamorillo
hamorillo force-pushed the hector.morilloprieto/RUM-13141 branch from 1ac1acc to ae32359 Compare May 11, 2026 13:51
@hamorillo

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 👍

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Wires DatadogInterceptor and DatadogEventListener.Factory on a real OkHttpClient against a MockWebServer and asserts the RUM resource event JSON carries the timing breakdown sub-objects (dns / connect / first_byte / download). Covers the integration that unit tests cannot reach: the interceptor and the listener must agree on the ResourceId derived from the request tag for timings to reach the correct resource scope, and concurrent requests to the same URL must remain isolated.

Test cases:
- single HTTP request populates the full timing breakdown
- HTTP >= 400 still produces timings via the early-flush path in responseHeadersEnd
- a dropped socket produces a RUM error event (not a resource event) with error.resource populated
- five concurrent requests to the same URL each produce an isolated resource event with its own timing breakdown
@hamorillo
hamorillo force-pushed the hector.morilloprieto/RUM-13141 branch from ae32359 to 22d4d44 Compare May 11, 2026 14:27
@hamorillo
hamorillo marked this pull request as ready for review May 12, 2026 06:34
@hamorillo
hamorillo requested review from a team as code owners May 12, 2026 06:34
0xnm
0xnm previously approved these changes May 12, 2026
}

@AfterEach
fun `tear down`() {

@0xnm 0xnm May 12, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor: it is probably worth to clean up GlobalRumMonitor as well (reflection will be needed)

it is not done in other similar tests, so probably not a big deal (we are just leaving fake values in the static property after the test).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. In a43824ea43824e, I created a helper method and invoked it in similar cases to clean up just the sdkCore instance used in that test

hamorillo added 2 commits May 12, 2026 10:14
Pin asserted URLs to the full request URL via mockServer.url(path) rather than checking only that the hostname is present. Deserialize the network-failure error event into a typed ErrorEvent model so field access is type-checked instead of navigating raw JSON. Use executor.execute in the concurrent test since the returned Future was unused and submit silently swallows uncaught exceptions.
…y/okhttp tests

Datadog.stopInstance only triggers RumFeature.onStop (which in turn calls GlobalRumMonitor.unregister) for real DatadogCore instances. With a StubSDKCore the cast fails silently and the monitor entry leaks into the static registry for the rest of the JVM. Add a shared reliability-test helper that mutates GlobalRumMonitor.registeredMonitors via field reflection, and call it from @AfterEach in every reliability/okhttp test that uses StubSDKCore. Field-based reflection is used because GlobalRumMonitor.unregister is internal and its JVM name is mangled with the SDK module suffix; the private map field name is stable.
@hamorillo
hamorillo merged commit 3ff8bf7 into develop May 13, 2026
27 checks passed
@hamorillo
hamorillo deleted the hector.morilloprieto/RUM-13141 branch May 13, 2026 06:47
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.

3 participants