From 6cdc42bc65d99b0a7aa619a6fe9d016b5e3bcd26 Mon Sep 17 00:00:00 2001 From: "sentry-junior[bot]" <264270552+sentry-junior[bot]@users.noreply.github.com> Date: Thu, 22 Oct 2026 17:05:20 +0000 Subject: [PATCH] test(core): Wait for the transaction capture in idle timeout tests 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 --- .../test/java/io/sentry/SentryTracerTest.kt | 34 +++++++++++-------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/sentry/src/test/java/io/sentry/SentryTracerTest.kt b/sentry/src/test/java/io/sentry/SentryTracerTest.kt index 7c6324db0a7..95f19344243 100644 --- a/sentry/src/test/java/io/sentry/SentryTracerTest.kt +++ b/sentry/src/test/java/io/sentry/SentryTracerTest.kt @@ -1160,9 +1160,11 @@ class SentryTracerTest { val span = transaction.startChild("op") span.finish() - await.untilFalse(transaction.isFinishTimerRunning) - - verify(fixture.scopes).captureTransaction(anyOrNull(), anyOrNull(), anyOrNull(), anyOrNull()) + // finish() clears isFinishTimerRunning before it captures the transaction, so wait for the + // capture itself + await.untilAsserted { + verify(fixture.scopes).captureTransaction(anyOrNull(), anyOrNull(), anyOrNull(), anyOrNull()) + } } @Test @@ -1221,18 +1223,20 @@ class SentryTracerTest { val span2 = transaction.startChild("op2") as Span span2.finish() - await.untilFalse(transaction.isFinishTimerRunning) - - verify(fixture.scopes) - .captureTransaction( - check { - assertEquals(2, it.spans.size) - assertEquals(transaction.root.finishDate, span2.finishDate) - }, - anyOrNull(), - anyOrNull(), - anyOrNull(), - ) + // finish() clears isFinishTimerRunning before it captures the transaction, so wait for the + // capture itself + await.untilAsserted { + verify(fixture.scopes) + .captureTransaction( + check { + assertEquals(2, it.spans.size) + assertEquals(transaction.root.finishDate, span2.finishDate) + }, + anyOrNull(), + anyOrNull(), + anyOrNull(), + ) + } } @Test