Skip to content

Add comprehensive unit tests for RequestTelemetry#3

Open
devin-ai-integration[bot] wants to merge 1 commit intomasterfrom
test/request-telemetry-coverage
Open

Add comprehensive unit tests for RequestTelemetry#3
devin-ai-integration[bot] wants to merge 1 commit intomasterfrom
test/request-telemetry-coverage

Conversation

@devin-ai-integration
Copy link
Copy Markdown

@devin-ai-integration devin-ai-integration bot commented Apr 12, 2026

Why?

RequestTelemetry manages the X-Stripe-Client-Telemetry header used to report request duration metrics back to Stripe. While the existing TelemetryTest exercises telemetry end-to-end through the HTTP layer (via MockWebServer), the RequestTelemetry class itself had no direct unit tests covering its internal enqueue/poll logic, toggle behavior, queue bounds, or edge cases.

What?

Adds RequestTelemetryTest.java in the com.stripe.net package (same package as the class under test, since RequestTelemetry is package-private) with 11 unit tests:

  • Enqueue/poll semantics — empty poll, basic enqueue→poll round-trip, queue drain behavior
  • Usage field — usage list included in JSON payload; empty list normalized to null (omitted from JSON)
  • Telemetry toggle — enqueue skipped when Stripe.enableTelemetry = false; poll returns empty when disabled at poll time (but still consumes the queue entry)
  • Null request ID — enqueue silently skipped
  • Queue capacity — bounded at 100 entries (hardcoded to match MAX_REQUEST_METRICS_QUEUE_SIZE)
  • Deprecated getHeaderValue — returns empty when header already present; returns telemetry when absent

No production code changes.

Reviewer notes:

  • RequestTelemetry uses a shared static ConcurrentLinkedQueue. The setUp() method drains it before each test to isolate state, but this is worth verifying is sufficient if the test runner parallelizes within-class tests.
  • testQueueBoundedAtMaxSize hardcodes 100 to match the private MAX_REQUEST_METRICS_QUEUE_SIZE constant — if that constant changes, this test will fail (which is arguably desirable).

See Also

  • Existing end-to-end telemetry tests: src/test/java/com/stripe/functional/TelemetryTest.java
  • Related PR: #2 (fixes ClassCastException in error parsing — separate change)

Link to Devin session: https://app.devin.ai/sessions/c1b674151bf44bf5beb6dff50488e9d3
Requested by: @kllyjsn


Open with Devin

The RequestTelemetry class manages the X-Stripe-Client-Telemetry header
used to report request metrics back to Stripe. While functional telemetry
is tested end-to-end in TelemetryTest, the class itself had no direct
unit tests covering its internal logic.

This adds 11 focused unit tests covering:

Enqueue/poll semantics:
- pollPayload returns empty when nothing is enqueued
- Enqueue followed by poll returns valid JSON payload
- Poll drains the queue (second poll returns empty)

Usage field handling:
- Usage list is included in the payload when provided
- Empty usage list is normalized to null (absent in JSON)

Telemetry toggle:
- Enqueue is silently ignored when telemetry is disabled
- Poll returns empty when telemetry is disabled at poll time
  (but still consumes the queue entry)

Edge cases:
- Null requestId causes enqueue to be silently skipped
- Queue is bounded at MAX_REQUEST_METRICS_QUEUE_SIZE (100)

Deprecated API:
- getHeaderValue returns empty when header is already present
- getHeaderValue returns telemetry when header is absent

Co-Authored-By: Jason Kelley <kllyjsn@gmail.com>
@devin-ai-integration
Copy link
Copy Markdown
Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

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