From f589f02107c5079a525c211410329fb33f1335bd Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Tue, 7 Feb 2023 14:38:22 +0000 Subject: [PATCH 1/2] Attempt 1 --- .../browsertracing/backgroundtab-pageload/subject.js | 10 ++++++---- .../browsertracing/backgroundtab-pageload/test.ts | 6 ++++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/packages/integration-tests/suites/tracing/browsertracing/backgroundtab-pageload/subject.js b/packages/integration-tests/suites/tracing/browsertracing/backgroundtab-pageload/subject.js index 7aa69584f070..b657f38ac009 100644 --- a/packages/integration-tests/suites/tracing/browsertracing/backgroundtab-pageload/subject.js +++ b/packages/integration-tests/suites/tracing/browsertracing/backgroundtab-pageload/subject.js @@ -1,6 +1,8 @@ document.getElementById('go-background').addEventListener('click', () => { - Object.defineProperty(document, 'hidden', { value: true, writable: true }); - const ev = document.createEvent('Event'); - ev.initEvent('visibilitychange'); - document.dispatchEvent(ev); + setTimeout(() => { + Object.defineProperty(document, 'hidden', { value: true, writable: true }); + const ev = document.createEvent('Event'); + ev.initEvent('visibilitychange'); + document.dispatchEvent(ev); + }, 250); }); diff --git a/packages/integration-tests/suites/tracing/browsertracing/backgroundtab-pageload/test.ts b/packages/integration-tests/suites/tracing/browsertracing/backgroundtab-pageload/test.ts index 690e6e857409..8df4f0369041 100644 --- a/packages/integration-tests/suites/tracing/browsertracing/backgroundtab-pageload/test.ts +++ b/packages/integration-tests/suites/tracing/browsertracing/backgroundtab-pageload/test.ts @@ -9,9 +9,11 @@ sentryTest('should finish pageload transaction when the page goes background', a await page.goto(url); - void page.click('#go-background'); + const pageloadTransactionPromise = getFirstSentryEnvelopeRequest(page); - const pageloadTransaction = await getFirstSentryEnvelopeRequest(page); + await page.click('#go-background'); + + const pageloadTransaction = await pageloadTransactionPromise; expect(pageloadTransaction.contexts?.trace?.op).toBe('pageload'); expect(pageloadTransaction.contexts?.trace?.status).toBe('cancelled'); From 49a3b5c95358cc5c1eef17c09c49d5c8dabfd8af Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Tue, 7 Feb 2023 14:57:39 +0000 Subject: [PATCH 2/2] Fix approximation flakes --- .../tracing/metrics/web-vitals-cls/test.ts | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/packages/integration-tests/suites/tracing/metrics/web-vitals-cls/test.ts b/packages/integration-tests/suites/tracing/metrics/web-vitals-cls/test.ts index 41bf941f10d3..a445cc967147 100644 --- a/packages/integration-tests/suites/tracing/metrics/web-vitals-cls/test.ts +++ b/packages/integration-tests/suites/tracing/metrics/web-vitals-cls/test.ts @@ -18,7 +18,11 @@ sentryTest('should capture a "GOOD" CLS vital with its source(s).', async ({ get expect(eventData.measurements).toBeDefined(); expect(eventData.measurements?.cls?.value).toBeDefined(); - expect(eventData.measurements?.cls?.value).toBeCloseTo(0.05); + + // Flakey value dependent on timings -> we check for a range + expect(eventData.measurements?.cls?.value).toBeGreaterThan(0.03); + expect(eventData.measurements?.cls?.value).toBeLessThan(0.07); + expect(eventData.tags?.['cls.source.1']).toBe('body > div#content > p#partial'); }); @@ -28,7 +32,11 @@ sentryTest('should capture a "MEH" CLS vital with its source(s).', async ({ getL expect(eventData.measurements).toBeDefined(); expect(eventData.measurements?.cls?.value).toBeDefined(); - expect(eventData.measurements?.cls?.value).toBeCloseTo(0.21); + + // Flakey value dependent on timings -> we check for a range + expect(eventData.measurements?.cls?.value).toBeGreaterThan(0.18); + expect(eventData.measurements?.cls?.value).toBeLessThan(0.23); + expect(eventData.tags?.['cls.source.1']).toBe('body > div#content > p'); }); @@ -38,11 +46,8 @@ sentryTest('should capture a "POOR" CLS vital with its source(s).', async ({ get expect(eventData.measurements).toBeDefined(); expect(eventData.measurements?.cls?.value).toBeDefined(); - // This test in particular seems to be flaky, such that the received value is frequently within 0.006 rather than the - // 0.005 that `toBeCloseTo()` requires. While it's true that each test is retried twice if it fails, in the flaky - // cases all three attempts always seem to come up with the exact same slightly-too-far-away number. Rather than ramp - // down `toBeCloseTo()`'s precision (which would make it accept anything between 0.30 and 0.40), we can just do the - // check manually. + + // Flakey value dependent on timings -> we check for a range expect(eventData.measurements?.cls?.value).toBeGreaterThan(0.34); expect(eventData.measurements?.cls?.value).toBeLessThan(0.36); expect(eventData.tags?.['cls.source.1']).toBe('body > div#content > p');