From 9389c241424f1afa77b66447eb33fd9a948c9862 Mon Sep 17 00:00:00 2001 From: Onur Temizkan Date: Wed, 19 Jan 2022 21:36:14 +0000 Subject: [PATCH 1/2] test(tracing): Add `connection.rtt` tests. --- .../metrics/connection-rtt/template.hbs | 11 +++ .../tracing/metrics/connection-rtt/test.ts | 81 +++++++++++++++++++ 2 files changed, 92 insertions(+) create mode 100644 packages/integration-tests/suites/tracing/metrics/connection-rtt/template.hbs create mode 100644 packages/integration-tests/suites/tracing/metrics/connection-rtt/test.ts diff --git a/packages/integration-tests/suites/tracing/metrics/connection-rtt/template.hbs b/packages/integration-tests/suites/tracing/metrics/connection-rtt/template.hbs new file mode 100644 index 000000000000..c798102c2014 --- /dev/null +++ b/packages/integration-tests/suites/tracing/metrics/connection-rtt/template.hbs @@ -0,0 +1,11 @@ + + + + + + + + +
Rendered
+ + diff --git a/packages/integration-tests/suites/tracing/metrics/connection-rtt/test.ts b/packages/integration-tests/suites/tracing/metrics/connection-rtt/test.ts new file mode 100644 index 000000000000..9c08a176a35a --- /dev/null +++ b/packages/integration-tests/suites/tracing/metrics/connection-rtt/test.ts @@ -0,0 +1,81 @@ +import { expect, Page } from '@playwright/test'; + +import { sentryTest } from '../../../../utils/fixtures'; +import { getSentryTransactionRequest } from '../../../../utils/helpers'; + +sentryTest('should capture a `connection.rtt` metric.', async ({ getLocalTestPath, page }) => { + const url = await getLocalTestPath({ testDir: __dirname }); + const eventData = await getSentryTransactionRequest(page, url); + + expect(eventData.measurements).toBeDefined(); + expect(eventData.measurements?.['connection.rtt']?.value).toBe(0); +}); + +async function createSessionWithLatency(page: Page, latency: number) { + const session = await page.context().newCDPSession(page); + await session.send('Network.emulateNetworkConditions', { + offline: false, + latency: latency, + downloadThroughput: (25 * 1024) / 8, + uploadThroughput: (5 * 1024) / 8, + }); + + return session; +} + +sentryTest( + 'should capture a `connection.rtt` metric with emulated value 200ms on Chromium.', + async ({ browserName, getLocalTestPath, page }) => { + if (browserName !== 'chromium') { + sentryTest.skip(); + } + + const session = await createSessionWithLatency(page, 200); + + const url = await getLocalTestPath({ testDir: __dirname }); + const eventData = await getSentryTransactionRequest(page, url); + + await session.detach(); + + expect(eventData.measurements).toBeDefined(); + expect(eventData.measurements?.['connection.rtt']?.value).toBe(200); + }, +); + +sentryTest( + 'should capture a `connection.rtt` metric with emulated value 100ms on Chromium.', + async ({ browserName, getLocalTestPath, page }) => { + if (browserName !== 'chromium') { + sentryTest.skip(); + } + + const session = await createSessionWithLatency(page, 100); + + const url = await getLocalTestPath({ testDir: __dirname }); + const eventData = await getSentryTransactionRequest(page, url); + + await session.detach(); + + expect(eventData.measurements).toBeDefined(); + expect(eventData.measurements?.['connection.rtt']?.value).toBe(100); + }, +); + +sentryTest( + 'should capture a `connection.rtt` metric with emulated value 50ms on Chromium.', + async ({ browserName, getLocalTestPath, page }) => { + if (browserName !== 'chromium') { + sentryTest.skip(); + } + + const session = await createSessionWithLatency(page, 50); + + const url = await getLocalTestPath({ testDir: __dirname }); + const eventData = await getSentryTransactionRequest(page, url); + + await session.detach(); + + expect(eventData.measurements).toBeDefined(); + expect(eventData.measurements?.['connection.rtt']?.value).toBe(50); + }, +); From 2e45c60db24fd6f6ec3ac84c08168299736fbfcb Mon Sep 17 00:00:00 2001 From: Onur Temizkan Date: Wed, 19 Jan 2022 21:54:47 +0000 Subject: [PATCH 2/2] Run `connection.rtt` tests only on Chromium. --- .../tracing/metrics/connection-rtt/test.ts | 36 ++++++++----------- 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/packages/integration-tests/suites/tracing/metrics/connection-rtt/test.ts b/packages/integration-tests/suites/tracing/metrics/connection-rtt/test.ts index 9c08a176a35a..834ed8b695f1 100644 --- a/packages/integration-tests/suites/tracing/metrics/connection-rtt/test.ts +++ b/packages/integration-tests/suites/tracing/metrics/connection-rtt/test.ts @@ -3,12 +3,10 @@ import { expect, Page } from '@playwright/test'; import { sentryTest } from '../../../../utils/fixtures'; import { getSentryTransactionRequest } from '../../../../utils/helpers'; -sentryTest('should capture a `connection.rtt` metric.', async ({ getLocalTestPath, page }) => { - const url = await getLocalTestPath({ testDir: __dirname }); - const eventData = await getSentryTransactionRequest(page, url); - - expect(eventData.measurements).toBeDefined(); - expect(eventData.measurements?.['connection.rtt']?.value).toBe(0); +sentryTest.beforeEach(({ browserName }) => { + if (browserName !== 'chromium') { + sentryTest.skip(); + } }); async function createSessionWithLatency(page: Page, latency: number) { @@ -23,13 +21,17 @@ async function createSessionWithLatency(page: Page, latency: number) { return session; } +sentryTest('should capture a `connection.rtt` metric.', async ({ getLocalTestPath, page }) => { + const url = await getLocalTestPath({ testDir: __dirname }); + const eventData = await getSentryTransactionRequest(page, url); + + expect(eventData.measurements).toBeDefined(); + expect(eventData.measurements?.['connection.rtt']?.value).toBe(0); +}); + sentryTest( 'should capture a `connection.rtt` metric with emulated value 200ms on Chromium.', - async ({ browserName, getLocalTestPath, page }) => { - if (browserName !== 'chromium') { - sentryTest.skip(); - } - + async ({ getLocalTestPath, page }) => { const session = await createSessionWithLatency(page, 200); const url = await getLocalTestPath({ testDir: __dirname }); @@ -44,11 +46,7 @@ sentryTest( sentryTest( 'should capture a `connection.rtt` metric with emulated value 100ms on Chromium.', - async ({ browserName, getLocalTestPath, page }) => { - if (browserName !== 'chromium') { - sentryTest.skip(); - } - + async ({ getLocalTestPath, page }) => { const session = await createSessionWithLatency(page, 100); const url = await getLocalTestPath({ testDir: __dirname }); @@ -63,11 +61,7 @@ sentryTest( sentryTest( 'should capture a `connection.rtt` metric with emulated value 50ms on Chromium.', - async ({ browserName, getLocalTestPath, page }) => { - if (browserName !== 'chromium') { - sentryTest.skip(); - } - + async ({ getLocalTestPath, page }) => { const session = await createSessionWithLatency(page, 50); const url = await getLocalTestPath({ testDir: __dirname });