test: check that we remove temp directories on process exit (#13494)
This commit is contained in:
parent
95d4041b8b
commit
2a97ad2487
|
|
@ -1,7 +1,8 @@
|
||||||
|
const fs = require('fs');
|
||||||
const cluster = require('cluster');
|
const cluster = require('cluster');
|
||||||
|
|
||||||
async function start() {
|
async function start() {
|
||||||
const { browserTypeName, launchOptions, stallOnClose, disconnectOnSIGHUP } = JSON.parse(process.argv[2]);
|
const { browserTypeName, launchOptions, stallOnClose, disconnectOnSIGHUP, exitOnFile } = JSON.parse(process.argv[2]);
|
||||||
if (stallOnClose) {
|
if (stallOnClose) {
|
||||||
launchOptions.__testHookGracefullyClose = () => {
|
launchOptions.__testHookGracefullyClose = () => {
|
||||||
console.log(`(stalled=>true)`);
|
console.log(`(stalled=>true)`);
|
||||||
|
|
@ -17,6 +18,17 @@ async function start() {
|
||||||
if (disconnectOnSIGHUP)
|
if (disconnectOnSIGHUP)
|
||||||
process.on('SIGHUP', () => browserServer._disconnectForTest());
|
process.on('SIGHUP', () => browserServer._disconnectForTest());
|
||||||
|
|
||||||
|
if (exitOnFile) {
|
||||||
|
(async function waitForFileAndExit() {
|
||||||
|
while (true) {
|
||||||
|
if (fs.existsSync(exitOnFile))
|
||||||
|
break;
|
||||||
|
await new Promise(f => setTimeout(f, 100));
|
||||||
|
}
|
||||||
|
process.exit(42);
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
|
||||||
browserServer.on('close', (exitCode, signal) => {
|
browserServer.on('close', (exitCode, signal) => {
|
||||||
console.log(`(exitCode=>${exitCode})`);
|
console.log(`(exitCode=>${exitCode})`);
|
||||||
console.log(`(signal=>${signal})`);
|
console.log(`(signal=>${signal})`);
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ import type { CommonFixtures, TestChildProcess } from './commonFixtures';
|
||||||
export type RemoteServerOptions = {
|
export type RemoteServerOptions = {
|
||||||
stallOnClose?: boolean;
|
stallOnClose?: boolean;
|
||||||
disconnectOnSIGHUP?: boolean;
|
disconnectOnSIGHUP?: boolean;
|
||||||
|
exitOnFile?: string;
|
||||||
inCluster?: boolean;
|
inCluster?: boolean;
|
||||||
url?: string;
|
url?: string;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -33,9 +33,11 @@ test('should close the browser when the node process closes', async ({ startRemo
|
||||||
});
|
});
|
||||||
|
|
||||||
test.describe('signals', () => {
|
test.describe('signals', () => {
|
||||||
test.skip(({ platform, headless }) => platform === 'win32' || !headless);
|
test.skip(({ platform }) => platform === 'win32');
|
||||||
|
|
||||||
|
test('should report browser close signal', async ({ startRemoteServer, server, headless }) => {
|
||||||
|
test.skip(!headless, 'Wrong exit code in headed');
|
||||||
|
|
||||||
test('should report browser close signal', async ({ startRemoteServer, server }) => {
|
|
||||||
const remoteServer = await startRemoteServer({ url: server.EMPTY_PAGE });
|
const remoteServer = await startRemoteServer({ url: server.EMPTY_PAGE });
|
||||||
const pid = await remoteServer.out('pid');
|
const pid = await remoteServer.out('pid');
|
||||||
process.kill(-pid, 'SIGTERM');
|
process.kill(-pid, 'SIGTERM');
|
||||||
|
|
@ -94,6 +96,18 @@ test.describe('signals', () => {
|
||||||
expect(after).toBe(false);
|
expect(after).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('should remove temp dir on process.exit', async ({ startRemoteServer, server }, testInfo) => {
|
||||||
|
const file = testInfo.outputPath('exit.file');
|
||||||
|
const remoteServer = await startRemoteServer({ url: server.EMPTY_PAGE, exitOnFile: file });
|
||||||
|
const tempDir = await remoteServer.out('tempDir');
|
||||||
|
const before = fs.existsSync(tempDir);
|
||||||
|
fs.writeFileSync(file, 'data', 'utf-8');
|
||||||
|
expect(await remoteServer.childExitCode()).toBe(42);
|
||||||
|
const after = fs.existsSync(tempDir);
|
||||||
|
expect(before).toBe(true);
|
||||||
|
expect(after).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
test('should kill the browser on SIGINT + SIGTERM', async ({ startRemoteServer, server }) => {
|
test('should kill the browser on SIGINT + SIGTERM', async ({ startRemoteServer, server }) => {
|
||||||
const remoteServer = await startRemoteServer({ stallOnClose: true, url: server.EMPTY_PAGE });
|
const remoteServer = await startRemoteServer({ stallOnClose: true, url: server.EMPTY_PAGE });
|
||||||
process.kill(remoteServer.child().pid, 'SIGINT');
|
process.kill(remoteServer.child().pid, 'SIGINT');
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue