Skip to content

Commit aa51872

Browse files
test(core): Wait for the transaction capture in idle timeout tests (#6360)
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: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com> Co-authored-by: Nelson Osacky <nelson.osacky@sentry.io>
1 parent 44566d5 commit aa51872

1 file changed

Lines changed: 19 additions & 15 deletions

File tree

‎sentry/src/test/java/io/sentry/SentryTracerTest.kt‎

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,9 +1160,11 @@ class SentryTracerTest {
11601160
val span = transaction.startChild("op")
11611161
span.finish()
11621162

1163-
await.untilFalse(transaction.isFinishTimerRunning)
1164-
1165-
verify(fixture.scopes).captureTransaction(anyOrNull(), anyOrNull(), anyOrNull(), anyOrNull())
1163+
// finish() clears isFinishTimerRunning before it captures the transaction, so wait for the
1164+
// capture itself
1165+
await.untilAsserted {
1166+
verify(fixture.scopes).captureTransaction(anyOrNull(), anyOrNull(), anyOrNull(), anyOrNull())
1167+
}
11661168
}
11671169

11681170
@Test
@@ -1221,18 +1223,20 @@ class SentryTracerTest {
12211223
val span2 = transaction.startChild("op2") as Span
12221224
span2.finish()
12231225

1224-
await.untilFalse(transaction.isFinishTimerRunning)
1225-
1226-
verify(fixture.scopes)
1227-
.captureTransaction(
1228-
check {
1229-
assertEquals(2, it.spans.size)
1230-
assertEquals(transaction.root.finishDate, span2.finishDate)
1231-
},
1232-
anyOrNull(),
1233-
anyOrNull(),
1234-
anyOrNull(),
1235-
)
1226+
// finish() clears isFinishTimerRunning before it captures the transaction, so wait for the
1227+
// capture itself
1228+
await.untilAsserted {
1229+
verify(fixture.scopes)
1230+
.captureTransaction(
1231+
check {
1232+
assertEquals(2, it.spans.size)
1233+
assertEquals(transaction.root.finishDate, span2.finishDate)
1234+
},
1235+
anyOrNull(),
1236+
anyOrNull(),
1237+
anyOrNull(),
1238+
)
1239+
}
12361240
}
12371241

12381242
@Test

0 commit comments

Comments
 (0)