Skip to content

Commit d34cd99

Browse files
committed
test: skip websocket message time bounds on webkit-wsl
The WSL VM clock drifts relative to the Windows host clock, so the browser-reported message times cannot be compared against the host wall clock. Keep the rest of the assertions (message content, sizes, order).
1 parent dfa429d commit d34cd99

1 file changed

Lines changed: 20 additions & 12 deletions

File tree

tests/library/har-websocket.spec.ts

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ it('should include websocket handshake headers and status', async ({ contextFact
130130
expect(responseHeaderNames).toContain('sec-websocket-accept');
131131
});
132132

133-
async function testWebSocketMessages(contextFactory, server, testInfo, content) {
133+
async function testWebSocketMessages(contextFactory, server, testInfo, content, channel?) {
134134
const incomingText = ['x'.repeat(125), 'x'.repeat(126), 'x'.repeat(2 ** 16)];
135135
const incomingBinary = [(new Array(125)).fill(0x01), (new Array(126)).fill(0x01), (new Array(2 ** 16)).fill(0x01)];
136136
const outgoingText = ['y'.repeat(125), 'y'.repeat(126), 'y'.repeat(2 ** 16)];
@@ -198,23 +198,27 @@ async function testWebSocketMessages(contextFactory, server, testInfo, content)
198198
...outgoingText.map(m => ({ type: 'send', opcode: 1, data: m })),
199199
...outgoingBinary.map(m => ({ type: 'send', opcode: 2, data: m })),
200200
]);
201-
for (const m of messages) {
202-
expect(m.time).toBeGreaterThanOrEqual(beforeMs - 1);
203-
expect(m.time).toBeLessThanOrEqual(afterMs + 1);
201+
// The WSL VM clock drifts relative to the Windows host clock, so the browser-reported
202+
// message times cannot be compared against the host wall clock.
203+
if (channel !== 'webkit-wsl') {
204+
for (const m of messages) {
205+
expect(m.time).toBeGreaterThanOrEqual(beforeMs - 1);
206+
expect(m.time).toBeLessThanOrEqual(afterMs + 1);
207+
}
204208
}
205209
expect(messages[0].time).toBeLessThanOrEqual(messages[1].time);
206210
expect(wsEntry.time).toBeGreaterThanOrEqual(messages[messages.length - 1].time - messages[0].time);
207211
}
208212

209-
it('should embed websocket messages', async ({ contextFactory, server }, testInfo) => {
210-
await testWebSocketMessages(contextFactory, server, testInfo, 'embed');
213+
it('should embed websocket messages', async ({ contextFactory, server, channel }, testInfo) => {
214+
await testWebSocketMessages(contextFactory, server, testInfo, 'embed', channel);
211215
});
212216

213-
it('should attach websocket messages', async ({ contextFactory, server }, testInfo) => {
214-
await testWebSocketMessages(contextFactory, server, testInfo, 'attach');
217+
it('should attach websocket messages', async ({ contextFactory, server, channel }, testInfo) => {
218+
await testWebSocketMessages(contextFactory, server, testInfo, 'attach', channel);
215219
});
216220

217-
it('should attach websocket messages for a still open websocket after stopping', async ({ contextFactory, server }, testInfo) => {
221+
it('should attach websocket messages for a still open websocket after stopping', async ({ contextFactory, server, channel }, testInfo) => {
218222
const incomingText = 'incoming';
219223
const incomingBinary = [0x01, 0x02, 0x03, 0x04];
220224
const outgoingText = 'outgoing';
@@ -271,9 +275,13 @@ it('should attach websocket messages for a still open websocket after stopping',
271275
{ type: 'send', opcode: 2, data: outgoingBinary },
272276
{ type: 'receive', opcode: 2, data: incomingBinary },
273277
]);
274-
for (const m of messages) {
275-
expect(m.time).toBeGreaterThanOrEqual(beforeMs - 1);
276-
expect(m.time).toBeLessThanOrEqual(afterMs + 1);
278+
// The WSL VM clock drifts relative to the Windows host clock, so the browser-reported
279+
// message times cannot be compared against the host wall clock.
280+
if (channel !== 'webkit-wsl') {
281+
for (const m of messages) {
282+
expect(m.time).toBeGreaterThanOrEqual(beforeMs - 1);
283+
expect(m.time).toBeLessThanOrEqual(afterMs + 1);
284+
}
277285
}
278286
expect(messages[0].time).toBeLessThanOrEqual(messages[1].time);
279287
expect(wsEntry.time).toBeGreaterThanOrEqual(messages[messages.length - 1].time - messages[0].time);

0 commit comments

Comments
 (0)