Skip to content

test(tracing): Add connection.rtt tests. #4423

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 2 commits into from
Jan 20, 2022
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
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<script src="{{htmlWebpackPlugin.options.initialization}}"></script>
</head>
<body>
<div>Rendered</div>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { expect, Page } from '@playwright/test';

import { sentryTest } from '../../../../utils/fixtures';
import { getSentryTransactionRequest } from '../../../../utils/helpers';

sentryTest.beforeEach(({ browserName }) => {
if (browserName !== 'chromium') {
sentryTest.skip();
}
});

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.', 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 ({ getLocalTestPath, page }) => {
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 ({ getLocalTestPath, page }) => {
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 ({ getLocalTestPath, page }) => {
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);
},
);