test: create a page in fixture tests to exercise browser processes (#3745)
We currently launch and then close the empty browser. This does not trigger many codepaths related to web page process creation and browser context. With opening and navigating a page, we do a more real-life test. This exposes an issue from #3740.
This commit is contained in:
parent
d3c677792c
commit
f232f34dae
|
|
@ -17,18 +17,42 @@
|
||||||
|
|
||||||
import { it, expect, describe, options } from './playwright.fixtures';
|
import { it, expect, describe, options } from './playwright.fixtures';
|
||||||
import './remoteServer.fixture';
|
import './remoteServer.fixture';
|
||||||
|
import { registerFixture } from '@playwright/test-runner';
|
||||||
|
|
||||||
import { execSync } from 'child_process';
|
import { execSync } from 'child_process';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
|
||||||
|
declare global {
|
||||||
|
interface TestState {
|
||||||
|
connectedRemoteServer: TestState['remoteServer'];
|
||||||
|
stallingConnectedRemoteServer: TestState['stallingRemoteServer'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
registerFixture('connectedRemoteServer', async ({browserType, remoteServer, server}, test) => {
|
||||||
|
const browser = await browserType.connect({ wsEndpoint: remoteServer.wsEndpoint() });
|
||||||
|
const page = await browser.newPage();
|
||||||
|
await page.goto(server.EMPTY_PAGE);
|
||||||
|
await test(remoteServer);
|
||||||
|
await browser.close();
|
||||||
|
});
|
||||||
|
|
||||||
|
registerFixture('stallingConnectedRemoteServer', async ({browserType, stallingRemoteServer, server}, test) => {
|
||||||
|
const browser = await browserType.connect({ wsEndpoint: stallingRemoteServer.wsEndpoint() });
|
||||||
|
const page = await browser.newPage();
|
||||||
|
await page.goto(server.EMPTY_PAGE);
|
||||||
|
await test(stallingRemoteServer);
|
||||||
|
await browser.close();
|
||||||
|
});
|
||||||
|
|
||||||
it('should close the browser when the node process closes', test => {
|
it('should close the browser when the node process closes', test => {
|
||||||
test.slow();
|
test.slow();
|
||||||
}, async ({remoteServer}) => {
|
}, async ({connectedRemoteServer}) => {
|
||||||
if (WIN)
|
if (WIN)
|
||||||
execSync(`taskkill /pid ${remoteServer.child().pid} /T /F`);
|
execSync(`taskkill /pid ${connectedRemoteServer.child().pid} /T /F`);
|
||||||
else
|
else
|
||||||
process.kill(remoteServer.child().pid);
|
process.kill(connectedRemoteServer.child().pid);
|
||||||
expect(await remoteServer.childExitCode()).toBe(WIN ? 1 : 0);
|
expect(await connectedRemoteServer.childExitCode()).toBe(WIN ? 1 : 0);
|
||||||
// We might not get browser exitCode in time when killing the parent node process,
|
// We might not get browser exitCode in time when killing the parent node process,
|
||||||
// so we don't check it here.
|
// so we don't check it here.
|
||||||
});
|
});
|
||||||
|
|
@ -38,73 +62,70 @@ describe('fixtures', suite => {
|
||||||
suite.slow();
|
suite.slow();
|
||||||
}, () => {
|
}, () => {
|
||||||
// Cannot reliably send signals on Windows.
|
// Cannot reliably send signals on Windows.
|
||||||
it('should report browser close signal', async ({remoteServer}) => {
|
it('should report browser close signal', async ({connectedRemoteServer}) => {
|
||||||
const pid = await remoteServer.out('pid');
|
const pid = await connectedRemoteServer.out('pid');
|
||||||
process.kill(-pid, 'SIGTERM');
|
process.kill(-pid, 'SIGTERM');
|
||||||
expect(await remoteServer.out('exitCode')).toBe('null');
|
expect(await connectedRemoteServer.out('exitCode')).toBe('null');
|
||||||
expect(await remoteServer.out('signal')).toBe('SIGTERM');
|
expect(await connectedRemoteServer.out('signal')).toBe('SIGTERM');
|
||||||
process.kill(remoteServer.child().pid);
|
process.kill(connectedRemoteServer.child().pid);
|
||||||
await remoteServer.childExitCode();
|
await connectedRemoteServer.childExitCode();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should report browser close signal 2', async ({remoteServer}) => {
|
it('should report browser close signal 2', async ({connectedRemoteServer}) => {
|
||||||
const pid = await remoteServer.out('pid');
|
const pid = await connectedRemoteServer.out('pid');
|
||||||
process.kill(-pid, 'SIGKILL');
|
process.kill(-pid, 'SIGKILL');
|
||||||
expect(await remoteServer.out('exitCode')).toBe('null');
|
expect(await connectedRemoteServer.out('exitCode')).toBe('null');
|
||||||
expect(await remoteServer.out('signal')).toBe('SIGKILL');
|
expect(await connectedRemoteServer.out('signal')).toBe('SIGKILL');
|
||||||
process.kill(remoteServer.child().pid);
|
process.kill(connectedRemoteServer.child().pid);
|
||||||
await remoteServer.childExitCode();
|
await connectedRemoteServer.childExitCode();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should close the browser on SIGINT', async ({remoteServer}) => {
|
it('should close the browser on SIGINT', async ({connectedRemoteServer}) => {
|
||||||
process.kill(remoteServer.child().pid, 'SIGINT');
|
process.kill(connectedRemoteServer.child().pid, 'SIGINT');
|
||||||
expect(await remoteServer.out('exitCode')).toBe('0');
|
expect(await connectedRemoteServer.out('exitCode')).toBe('0');
|
||||||
expect(await remoteServer.out('signal')).toBe('null');
|
expect(await connectedRemoteServer.out('signal')).toBe('null');
|
||||||
expect(await remoteServer.childExitCode()).toBe(130);
|
expect(await connectedRemoteServer.childExitCode()).toBe(130);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should close the browser on SIGTERM', async ({remoteServer}) => {
|
it('should close the browser on SIGTERM', async ({connectedRemoteServer}) => {
|
||||||
process.kill(remoteServer.child().pid, 'SIGTERM');
|
process.kill(connectedRemoteServer.child().pid, 'SIGTERM');
|
||||||
expect(await remoteServer.out('exitCode')).toBe('0');
|
expect(await connectedRemoteServer.out('exitCode')).toBe('0');
|
||||||
expect(await remoteServer.out('signal')).toBe('null');
|
expect(await connectedRemoteServer.out('signal')).toBe('null');
|
||||||
expect(await remoteServer.childExitCode()).toBe(0);
|
expect(await connectedRemoteServer.childExitCode()).toBe(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should close the browser on SIGHUP', async ({remoteServer}) => {
|
it('should close the browser on SIGHUP', async ({connectedRemoteServer}) => {
|
||||||
process.kill(remoteServer.child().pid, 'SIGHUP');
|
process.kill(connectedRemoteServer.child().pid, 'SIGHUP');
|
||||||
expect(await remoteServer.out('exitCode')).toBe('0');
|
expect(await connectedRemoteServer.out('exitCode')).toBe('0');
|
||||||
expect(await remoteServer.out('signal')).toBe('null');
|
expect(await connectedRemoteServer.out('signal')).toBe('null');
|
||||||
expect(await remoteServer.childExitCode()).toBe(0);
|
expect(await connectedRemoteServer.childExitCode()).toBe(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should kill the browser on double SIGINT', async ({stallingRemoteServer}) => {
|
it('should kill the browser on double SIGINT', async ({stallingConnectedRemoteServer}) => {
|
||||||
const remoteServer = stallingRemoteServer;
|
process.kill(stallingConnectedRemoteServer.child().pid, 'SIGINT');
|
||||||
process.kill(remoteServer.child().pid, 'SIGINT');
|
await stallingConnectedRemoteServer.out('stalled');
|
||||||
await remoteServer.out('stalled');
|
process.kill(stallingConnectedRemoteServer.child().pid, 'SIGINT');
|
||||||
process.kill(remoteServer.child().pid, 'SIGINT');
|
expect(await stallingConnectedRemoteServer.out('exitCode')).toBe('null');
|
||||||
expect(await remoteServer.out('exitCode')).toBe('null');
|
expect(await stallingConnectedRemoteServer.out('signal')).toBe('SIGKILL');
|
||||||
expect(await remoteServer.out('signal')).toBe('SIGKILL');
|
expect(await stallingConnectedRemoteServer.childExitCode()).toBe(130);
|
||||||
expect(await remoteServer.childExitCode()).toBe(130);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should kill the browser on SIGINT + SIGTERM', async ({stallingRemoteServer}) => {
|
it('should kill the browser on SIGINT + SIGTERM', async ({stallingConnectedRemoteServer}) => {
|
||||||
const remoteServer = stallingRemoteServer;
|
process.kill(stallingConnectedRemoteServer.child().pid, 'SIGINT');
|
||||||
process.kill(remoteServer.child().pid, 'SIGINT');
|
await stallingConnectedRemoteServer.out('stalled');
|
||||||
await remoteServer.out('stalled');
|
process.kill(stallingConnectedRemoteServer.child().pid, 'SIGTERM');
|
||||||
process.kill(remoteServer.child().pid, 'SIGTERM');
|
expect(await stallingConnectedRemoteServer.out('exitCode')).toBe('null');
|
||||||
expect(await remoteServer.out('exitCode')).toBe('null');
|
expect(await stallingConnectedRemoteServer.out('signal')).toBe('SIGKILL');
|
||||||
expect(await remoteServer.out('signal')).toBe('SIGKILL');
|
expect(await stallingConnectedRemoteServer.childExitCode()).toBe(0);
|
||||||
expect(await remoteServer.childExitCode()).toBe(0);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should kill the browser on SIGTERM + SIGINT', async ({stallingRemoteServer}) => {
|
it('should kill the browser on SIGTERM + SIGINT', async ({stallingConnectedRemoteServer}) => {
|
||||||
const remoteServer = stallingRemoteServer;
|
process.kill(stallingConnectedRemoteServer.child().pid, 'SIGTERM');
|
||||||
process.kill(remoteServer.child().pid, 'SIGTERM');
|
await stallingConnectedRemoteServer.out('stalled');
|
||||||
await remoteServer.out('stalled');
|
process.kill(stallingConnectedRemoteServer.child().pid, 'SIGINT');
|
||||||
process.kill(remoteServer.child().pid, 'SIGINT');
|
expect(await stallingConnectedRemoteServer.out('exitCode')).toBe('null');
|
||||||
expect(await remoteServer.out('exitCode')).toBe('null');
|
expect(await stallingConnectedRemoteServer.out('signal')).toBe('SIGKILL');
|
||||||
expect(await remoteServer.out('signal')).toBe('SIGKILL');
|
expect(await stallingConnectedRemoteServer.childExitCode()).toBe(130);
|
||||||
expect(await remoteServer.childExitCode()).toBe(130);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue