Skip to content

Commit cea58ff

Browse files
authored
test(browser): Make browser profiling test less flaky (#20664)
Fixes #20638 Hopefully this reduces flakiness, by increasing timeouts etc. and making sure things run longer.
1 parent a08fc2c commit cea58ff

2 files changed

Lines changed: 8 additions & 8 deletions

File tree

  • dev-packages/browser-integration-tests/suites/profiling/traceLifecycleMode_overlapping-spans

dev-packages/browser-integration-tests/suites/profiling/traceLifecycleMode_overlapping-spans/subject.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ import { browserProfilingIntegration } from '@sentry/browser';
33

44
window.Sentry = Sentry;
55

6-
Sentry.init({
6+
const client = Sentry.init({
77
dsn: 'https://public@dsn.ingest.sentry.io/1337',
88
integrations: [browserProfilingIntegration()],
99
tracesSampleRate: 1,
1010
profileSessionSampleRate: 1,
1111
profileLifecycle: 'trace',
1212
});
1313

14-
function largeSum(amount = 1000000) {
14+
function largeSum(amount) {
1515
let sum = 0;
1616
for (let i = 0; i < amount; i++) {
1717
sum += Math.sqrt(i) * Math.sin(i);
@@ -28,7 +28,8 @@ function fibonacci(n) {
2828
let firstSpan;
2929

3030
Sentry.startSpanManual({ name: 'root-largeSum-1', parentSpan: null, forceTransaction: true }, span => {
31-
largeSum();
31+
// Enough iterations that largeSum stays on-stack across several profiler ticks (10ms interval); otherwise sampling can miss it entirely.
32+
largeSum(2_500_000);
3233
firstSpan = span;
3334
});
3435

@@ -39,14 +40,13 @@ await Sentry.startSpanManual({ name: 'root-fibonacci-2', parentSpan: null, force
3940
console.log('child span');
4041
});
4142

42-
// Timeout to prevent flaky tests. Integration samples every 20ms, if function is too fast it might not get sampled
43-
await new Promise(resolve => setTimeout(resolve, 21));
43+
// Profiler uses a 10ms sample interval — wait long enough for multiple ticks
44+
await new Promise(resolve => setTimeout(resolve, 40));
4445
span.end();
4546
});
4647

47-
await new Promise(r => setTimeout(r, 21));
48+
await new Promise(r => setTimeout(r, 40));
4849

4950
firstSpan.end();
5051

51-
const client = Sentry.getClient();
5252
await client?.flush(5000);

dev-packages/browser-integration-tests/suites/profiling/traceLifecycleMode_overlapping-spans/test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ sentryTest(
4343
const profileChunkEnvelopes = await getMultipleSentryEnvelopeRequests<ProfileChunkEnvelope>(
4444
page,
4545
1,
46-
{ url, envelopeType: 'profile_chunk', timeout: 5000 },
46+
{ url, envelopeType: 'profile_chunk', timeout: 15_000 },
4747
properFullEnvelopeRequestParser,
4848
);
4949

0 commit comments

Comments
 (0)