playwright/tests/config/remote-server-impl.js
Dmitry Gozman 155bb7fcae
fix: wait for cleanup on double SIGINT (#13411)
This is a speculative fix to leftover tmp directories.
When users issues SIGINT twice, we enter `gracefullyClose()`
twice, and shortcut the second time. It turns out, we do
not wait for directories removal.

Note: it is unknown how often we reach this codepath in practice.
2022-04-07 19:20:54 -07:00

40 lines
1.2 KiB
JavaScript

const cluster = require('cluster');
async function start() {
const { browserTypeName, launchOptions, stallOnClose, disconnectOnSIGHUP } = JSON.parse(process.argv[2]);
if (stallOnClose) {
launchOptions.__testHookGracefullyClose = () => {
console.log(`(stalled=>true)`);
return new Promise(() => { });
};
}
const playwright = require('playwright-core');
if (disconnectOnSIGHUP)
launchOptions.handleSIGHUP = false;
const browserServer = await playwright[browserTypeName].launchServer(launchOptions);
if (disconnectOnSIGHUP)
process.on('SIGHUP', () => browserServer._disconnectForTest());
browserServer.on('close', (exitCode, signal) => {
console.log(`(exitCode=>${exitCode})`);
console.log(`(signal=>${signal})`);
});
console.log(`(tempDir=>${browserServer._artifactsDirForTest})`);
console.log(`(pid=>${browserServer.process().pid})`);
console.log(`(wsEndpoint=>${browserServer.wsEndpoint()})`);
}
process.on('uncaughtException', error => console.log(error));
process.on('unhandledRejection', reason => console.log(reason));
if (cluster.isWorker || !JSON.parse(process.argv[2]).inCluster) {
start();
} else {
cluster.fork();
cluster.on('exit', (worker, code, signal) => {
process.exit(0);
});
}