Skip to content

test(core): Wait for the transaction capture in idle timeout tests - #6360

Draft
sentry-junior[bot] wants to merge 1 commit into
mainfrom
test/tracer-idle-timeout-race
Draft

sentry-junior[bot] wants to merge 1 commit into
mainfrom
test/tracer-idle-timeout-race

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

📜 Description

Two idle-timeout tests in SentryTracerTest now wait for captureTransaction itself (await.untilAsserted { verify(...) }) instead of waiting for isFinishTimerRunning to become false:

  • when idle transaction with children, finishes the transaction after the idle timeout
  • when trimEnd, trims idle transaction time to the latest child timestamp

💡 Motivation and Context

Between Oct 15 and Oct 22, when idle transaction with children… failed 3 times with Wanted but not invoked: scopes.captureTransaction(...).

When the idle timer fires, it calls SentryTracer.finish(). finish() calls cancelIdleTimer(), which clears isIdleFinishTimerRunning before captureTransaction runs. As a result, await.untilFalse(isFinishTimerRunning) could return while the timer thread was still finishing. The trimEnd test uses the same pattern.

💚 How did you test it?

Locally (JDK 21), :sentry:test --tests io.sentry.SentryTracerTest:

  • To widen the race window, I temporarily added a 300ms sleep in finish() right before captureTransaction (not committed). With that sleep, both tests fail on main and pass with this PR. No other SentryTracerTest test failed under the sleep.
  • Without the sleep, all 115 tests pass.

📝 Checklist

  • I added GH Issue ID & Linear ID
  • I added tests to verify the changes.
  • No new PII added or SDK only sends newly added PII if sendDefaultPII is enabled.
  • I updated the docs if needed.
  • I updated the wizard if needed.
  • Review from the native team if needed.
  • No breaking change or entry added to the changelog.
  • No breaking change for hybrid SDKs or communicated to hybrid SDKs.
  • Public API changes reviewed by another Mobile SDK team member or implemented according to the develop docs spec.

🔮 Next steps

None.

#skip-changelog

via no.

--

View Junior Session [Sentry]

SentryTracer.finish() clears isFinishTimerRunning before it calls captureTransaction, so waiting on the flag could return while the timer thread was still finishing. Retry the verify until the capture happens instead.

Co-Authored-By: Nelson Osacky <nelson.osacky@sentry.io>
@sentry

sentry Bot commented Oct 22, 2026

Copy link
Copy Markdown

📲 Install Builds

Android

🔗 App Name App ID Version Configuration
SDK Size io.sentry.tests.size 8.61.1 (1) release

⚙️ sentry-android Build Distribution Settings

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants