mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
test: unflake some web socket tests (#4673)
Tests were waiting for `framesent` event after awaiting `page.evaluate`. Sometimes, `page.evaluate` took long enough and finished after the `framesent`. Drive-by: small fixes for mode=service test fixture.
This commit is contained in:
parent
12dc04a304
commit
e97ab7e42f
@ -131,6 +131,7 @@ fixtures.playwright.override(async ({ browserName, testWorkerIndex, platform, mo
|
|||||||
const spawnedProcess = childProcess.fork(path.join(__dirname, '..', 'lib', 'service.js'), [String(port)], {
|
const spawnedProcess = childProcess.fork(path.join(__dirname, '..', 'lib', 'service.js'), [String(port)], {
|
||||||
stdio: 'pipe'
|
stdio: 'pipe'
|
||||||
});
|
});
|
||||||
|
spawnedProcess.stderr.pipe(process.stderr);
|
||||||
await new Promise(f => {
|
await new Promise(f => {
|
||||||
spawnedProcess.stdout.on('data', data => {
|
spawnedProcess.stdout.on('data', data => {
|
||||||
if (data.toString().includes('Listening on'))
|
if (data.toString().includes('Listening on'))
|
||||||
@ -144,9 +145,11 @@ fixtures.playwright.override(async ({ browserName, testWorkerIndex, platform, mo
|
|||||||
spawnedProcess.on('exit', onExit);
|
spawnedProcess.on('exit', onExit);
|
||||||
const client = await PlaywrightClient.connect(`ws://localhost:${port}/ws`);
|
const client = await PlaywrightClient.connect(`ws://localhost:${port}/ws`);
|
||||||
await run(client.playwright());
|
await run(client.playwright());
|
||||||
spawnedProcess.removeListener('exit', onExit);
|
|
||||||
await client.close();
|
await client.close();
|
||||||
|
spawnedProcess.removeListener('exit', onExit);
|
||||||
|
const processExited = new Promise(f => spawnedProcess.on('exit', f));
|
||||||
spawnedProcess.kill();
|
spawnedProcess.kill();
|
||||||
|
await processExited;
|
||||||
await teardownCoverage();
|
await teardownCoverage();
|
||||||
} else {
|
} else {
|
||||||
const playwright = require('../index');
|
const playwright = require('../index');
|
||||||
|
@ -108,41 +108,47 @@ it('should emit error', async ({page, server, isFirefox}) => {
|
|||||||
expect(message).toContain(': 400');
|
expect(message).toContain(': 400');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not have stray error events', async ({page, server, isFirefox}) => {
|
it('should not have stray error events', async ({page, server}) => {
|
||||||
const [ws] = await Promise.all([
|
let error;
|
||||||
page.waitForEvent('websocket'),
|
page.on('websocket', ws => ws.on('socketerror', e => error = e));
|
||||||
|
await Promise.all([
|
||||||
|
page.waitForEvent('websocket').then(async ws => {
|
||||||
|
await ws.waitForEvent('framereceived');
|
||||||
|
return ws;
|
||||||
|
}),
|
||||||
page.evaluate(port => {
|
page.evaluate(port => {
|
||||||
(window as any).ws = new WebSocket('ws://localhost:' + port + '/ws');
|
(window as any).ws = new WebSocket('ws://localhost:' + port + '/ws');
|
||||||
}, server.PORT)
|
}, server.PORT)
|
||||||
]);
|
]);
|
||||||
let error;
|
|
||||||
ws.on('socketerror', e => error = e);
|
|
||||||
await ws.waitForEvent('framereceived');
|
|
||||||
await page.evaluate('window.ws.close()');
|
await page.evaluate('window.ws.close()');
|
||||||
expect(error).toBeFalsy();
|
expect(error).toBeFalsy();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should reject waitForEvent on socket close', async ({page, server, isFirefox}) => {
|
it('should reject waitForEvent on socket close', async ({page, server}) => {
|
||||||
const [ws] = await Promise.all([
|
const [ws] = await Promise.all([
|
||||||
page.waitForEvent('websocket'),
|
page.waitForEvent('websocket').then(async ws => {
|
||||||
|
await ws.waitForEvent('framereceived');
|
||||||
|
return ws;
|
||||||
|
}),
|
||||||
page.evaluate(port => {
|
page.evaluate(port => {
|
||||||
(window as any).ws = new WebSocket('ws://localhost:' + port + '/ws');
|
(window as any).ws = new WebSocket('ws://localhost:' + port + '/ws');
|
||||||
}, server.PORT)
|
}, server.PORT)
|
||||||
]);
|
]);
|
||||||
await ws.waitForEvent('framereceived');
|
|
||||||
const error = ws.waitForEvent('framesent').catch(e => e);
|
const error = ws.waitForEvent('framesent').catch(e => e);
|
||||||
await page.evaluate('window.ws.close()');
|
await page.evaluate('window.ws.close()');
|
||||||
expect((await error).message).toContain('Socket closed');
|
expect((await error).message).toContain('Socket closed');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should reject waitForEvent on page close', async ({page, server, isFirefox}) => {
|
it('should reject waitForEvent on page close', async ({page, server}) => {
|
||||||
const [ws] = await Promise.all([
|
const [ws] = await Promise.all([
|
||||||
page.waitForEvent('websocket'),
|
page.waitForEvent('websocket').then(async ws => {
|
||||||
|
await ws.waitForEvent('framereceived');
|
||||||
|
return ws;
|
||||||
|
}),
|
||||||
page.evaluate(port => {
|
page.evaluate(port => {
|
||||||
(window as any).ws = new WebSocket('ws://localhost:' + port + '/ws');
|
(window as any).ws = new WebSocket('ws://localhost:' + port + '/ws');
|
||||||
}, server.PORT)
|
}, server.PORT)
|
||||||
]);
|
]);
|
||||||
await ws.waitForEvent('framereceived');
|
|
||||||
const error = ws.waitForEvent('framesent').catch(e => e);
|
const error = ws.waitForEvent('framesent').catch(e => e);
|
||||||
await page.close();
|
await page.close();
|
||||||
expect((await error).message).toContain('Page closed');
|
expect((await error).message).toContain('Page closed');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user