Skip to content

Commit 5b0a53e

Browse files
authored
test(tracing): Add connection.rtt tests. (#4423)
1 parent eccc5ab commit 5b0a53e

File tree

2 files changed

+86
-0
lines changed

2 files changed

+86
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8" />
5+
<title></title>
6+
<script src="{{htmlWebpackPlugin.options.initialization}}"></script>
7+
</head>
8+
<body>
9+
<div>Rendered</div>
10+
</body>
11+
</html>
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import { expect, Page } from '@playwright/test';
2+
3+
import { sentryTest } from '../../../../utils/fixtures';
4+
import { getSentryTransactionRequest } from '../../../../utils/helpers';
5+
6+
sentryTest.beforeEach(({ browserName }) => {
7+
if (browserName !== 'chromium') {
8+
sentryTest.skip();
9+
}
10+
});
11+
12+
async function createSessionWithLatency(page: Page, latency: number) {
13+
const session = await page.context().newCDPSession(page);
14+
await session.send('Network.emulateNetworkConditions', {
15+
offline: false,
16+
latency: latency,
17+
downloadThroughput: (25 * 1024) / 8,
18+
uploadThroughput: (5 * 1024) / 8,
19+
});
20+
21+
return session;
22+
}
23+
24+
sentryTest('should capture a `connection.rtt` metric.', async ({ getLocalTestPath, page }) => {
25+
const url = await getLocalTestPath({ testDir: __dirname });
26+
const eventData = await getSentryTransactionRequest(page, url);
27+
28+
expect(eventData.measurements).toBeDefined();
29+
expect(eventData.measurements?.['connection.rtt']?.value).toBe(0);
30+
});
31+
32+
sentryTest(
33+
'should capture a `connection.rtt` metric with emulated value 200ms on Chromium.',
34+
async ({ getLocalTestPath, page }) => {
35+
const session = await createSessionWithLatency(page, 200);
36+
37+
const url = await getLocalTestPath({ testDir: __dirname });
38+
const eventData = await getSentryTransactionRequest(page, url);
39+
40+
await session.detach();
41+
42+
expect(eventData.measurements).toBeDefined();
43+
expect(eventData.measurements?.['connection.rtt']?.value).toBe(200);
44+
},
45+
);
46+
47+
sentryTest(
48+
'should capture a `connection.rtt` metric with emulated value 100ms on Chromium.',
49+
async ({ getLocalTestPath, page }) => {
50+
const session = await createSessionWithLatency(page, 100);
51+
52+
const url = await getLocalTestPath({ testDir: __dirname });
53+
const eventData = await getSentryTransactionRequest(page, url);
54+
55+
await session.detach();
56+
57+
expect(eventData.measurements).toBeDefined();
58+
expect(eventData.measurements?.['connection.rtt']?.value).toBe(100);
59+
},
60+
);
61+
62+
sentryTest(
63+
'should capture a `connection.rtt` metric with emulated value 50ms on Chromium.',
64+
async ({ getLocalTestPath, page }) => {
65+
const session = await createSessionWithLatency(page, 50);
66+
67+
const url = await getLocalTestPath({ testDir: __dirname });
68+
const eventData = await getSentryTransactionRequest(page, url);
69+
70+
await session.detach();
71+
72+
expect(eventData.measurements).toBeDefined();
73+
expect(eventData.measurements?.['connection.rtt']?.value).toBe(50);
74+
},
75+
);

0 commit comments

Comments
 (0)