Skip to content

test: Fix some flaky tests #7597

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,30 +1,35 @@
const transaction = Sentry.startTransaction({ name: 'test_transaction_1' });
const span_1 = transaction.startChild({
op: 'span_1',
data: {
foo: 'bar',
baz: [1, 2, 3],
},
});
for (let i = 0; i < 2000; i++);
async function run() {
const transaction = Sentry.startTransaction({ name: 'test_transaction_1' });
const span_1 = transaction.startChild({
op: 'span_1',
data: {
foo: 'bar',
baz: [1, 2, 3],
},
});

// span_1 finishes
span_1.finish();
await new Promise(resolve => setTimeout(resolve, 1));

// span_2 doesn't finish
const span_2 = transaction.startChild({ op: 'span_2' });
for (let i = 0; i < 4000; i++);
// span_1 finishes
span_1.finish();

const span_3 = transaction.startChild({ op: 'span_3' });
for (let i = 0; i < 4000; i++);
// span_2 doesn't finish
const span_2 = transaction.startChild({ op: 'span_2' });
await new Promise(resolve => setTimeout(resolve, 1));

// span_4 is the child of span_3 but doesn't finish.
const span_4 = span_3.startChild({ op: 'span_4', data: { qux: 'quux' } });
const span_3 = transaction.startChild({ op: 'span_3' });
await new Promise(resolve => setTimeout(resolve, 1));

// span_5 is another child of span_3 but finishes.
const span_5 = span_3.startChild({ op: 'span_5' }).finish();
// span_4 is the child of span_3 but doesn't finish.
const span_4 = span_3.startChild({ op: 'span_4', data: { qux: 'quux' } });

// span_3 also finishes
span_3.finish();
// span_5 is another child of span_3 but finishes.
const span_5 = span_3.startChild({ op: 'span_5' }).finish();

transaction.finish();
// span_3 also finishes
span_3.finish();

transaction.finish();
}

run();
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ sentryTest(
const eventData = await getFirstSentryEnvelopeRequest<Event>(page, url);
const frames = eventData.exception?.values?.[0].stacktrace?.frames;

expect(eventData).toBeDefined();
expect(eventData.exception?.values).toBeDefined();
expect(frames).toBeDefined();

runInChromium(() => {
expect(frames).toMatchObject([
{ function: '?' },
Expand Down Expand Up @@ -57,6 +61,9 @@ sentryTest(

const eventData = await getFirstSentryEnvelopeRequest<Event>(page, url);

expect(eventData).toBeDefined();
expect(eventData.exception?.values).toBeDefined();
expect(eventData.exception?.values?.[0].stacktrace).toBeDefined();
expect(eventData.exception?.values?.[0].stacktrace?.frames).toMatchObject(
Array(7).fill({ filename: expect.stringMatching(/^file:\/?/) }),
);
Expand Down