test: try to unflake fixtures tests (#1574)
This commit is contained in:
parent
b4a20140a2
commit
f72b6b4778
|
|
@ -26,7 +26,7 @@ module.exports.describe = function({testRunner, expect, product, browserType, pl
|
||||||
const {it, fit, xit, dit} = testRunner;
|
const {it, fit, xit, dit} = testRunner;
|
||||||
const {beforeAll, beforeEach, afterAll, afterEach} = testRunner;
|
const {beforeAll, beforeEach, afterAll, afterEach} = testRunner;
|
||||||
|
|
||||||
async function testSignal(action) {
|
async function testSignal(action, exitOnClose) {
|
||||||
const options = Object.assign({}, defaultBrowserOptions, {
|
const options = Object.assign({}, defaultBrowserOptions, {
|
||||||
// Disable DUMPIO to cleanly read stdout.
|
// Disable DUMPIO to cleanly read stdout.
|
||||||
dumpio: false,
|
dumpio: false,
|
||||||
|
|
@ -34,7 +34,7 @@ module.exports.describe = function({testRunner, expect, product, browserType, pl
|
||||||
handleSIGTERM: true,
|
handleSIGTERM: true,
|
||||||
handleSIGHUP: true,
|
handleSIGHUP: true,
|
||||||
});
|
});
|
||||||
const res = spawn('node', [path.join(__dirname, 'fixtures', 'closeme.js'), playwrightPath, product, JSON.stringify(options)]);
|
const res = spawn('node', [path.join(__dirname, 'fixtures', 'closeme.js'), playwrightPath, product, JSON.stringify(options), exitOnClose ? 'true' : '']);
|
||||||
let wsEndPointCallback;
|
let wsEndPointCallback;
|
||||||
const wsEndPointPromise = new Promise(x => wsEndPointCallback = x);
|
const wsEndPointPromise = new Promise(x => wsEndPointCallback = x);
|
||||||
let output = '';
|
let output = '';
|
||||||
|
|
@ -42,7 +42,7 @@ module.exports.describe = function({testRunner, expect, product, browserType, pl
|
||||||
let browserSignal = 'none';
|
let browserSignal = 'none';
|
||||||
let browserPid;
|
let browserPid;
|
||||||
res.stdout.on('data', data => {
|
res.stdout.on('data', data => {
|
||||||
output += data;
|
output += data.toString();
|
||||||
// Uncomment to debug these tests.
|
// Uncomment to debug these tests.
|
||||||
// console.log(data.toString());
|
// console.log(data.toString());
|
||||||
let match = output.match(/browserWS:(.+):browserWS/);
|
let match = output.match(/browserWS:(.+):browserWS/);
|
||||||
|
|
@ -94,23 +94,18 @@ module.exports.describe = function({testRunner, expect, product, browserType, pl
|
||||||
// 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.
|
||||||
});
|
});
|
||||||
if (!WIN) {
|
|
||||||
|
describe.skip(WIN)('signals', () => {
|
||||||
// Cannot reliably send signals on Windows.
|
// Cannot reliably send signals on Windows.
|
||||||
it.slow()('should report browser close signal', async () => {
|
it.slow()('should report browser close signal', async () => {
|
||||||
const result = await testSignal((child, browserPid) => {
|
const result = await testSignal((child, browserPid) => process.kill(browserPid), true);
|
||||||
process.kill(browserPid);
|
expect(result.exitCode).toBe(0);
|
||||||
process.kill(child.pid, 'SIGINT');
|
|
||||||
});
|
|
||||||
expect(result.exitCode).toBe(130);
|
|
||||||
expect(result.browserExitCode).toBe('null');
|
expect(result.browserExitCode).toBe('null');
|
||||||
expect(result.browserSignal).toBe('SIGTERM');
|
expect(result.browserSignal).toBe('SIGTERM');
|
||||||
});
|
});
|
||||||
it.slow()('should report browser close signal 2', async () => {
|
it.slow()('should report browser close signal 2', async (state, test) => {
|
||||||
const result = await testSignal((child, browserPid) => {
|
const result = await testSignal((child, browserPid) => process.kill(browserPid, 'SIGKILL'), true);
|
||||||
process.kill(browserPid, 'SIGKILL');
|
expect(result.exitCode).toBe(0);
|
||||||
process.kill(child.pid, 'SIGINT');
|
|
||||||
});
|
|
||||||
expect(result.exitCode).toBe(130);
|
|
||||||
expect(result.browserExitCode).toBe('null');
|
expect(result.browserExitCode).toBe('null');
|
||||||
expect(result.browserSignal).toBe('SIGKILL');
|
expect(result.browserSignal).toBe('SIGKILL');
|
||||||
});
|
});
|
||||||
|
|
@ -159,6 +154,6 @@ module.exports.describe = function({testRunner, expect, product, browserType, pl
|
||||||
// TODO: ideally, we would expect the SIGKILL on the browser from
|
// TODO: ideally, we would expect the SIGKILL on the browser from
|
||||||
// force kill, but that's racy with sending two signals.
|
// force kill, but that's racy with sending two signals.
|
||||||
});
|
});
|
||||||
}
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
||||||
4
test/fixtures/closeme.js
vendored
4
test/fixtures/closeme.js
vendored
|
|
@ -1,8 +1,10 @@
|
||||||
(async() => {
|
(async() => {
|
||||||
const [, , playwrightRoot, product, options] = process.argv;
|
const [, , playwrightRoot, product, options, exitOnClose] = process.argv;
|
||||||
const browserServer = await require(playwrightRoot)[product.toLowerCase()].launchServer(JSON.parse(options));
|
const browserServer = await require(playwrightRoot)[product.toLowerCase()].launchServer(JSON.parse(options));
|
||||||
browserServer.on('close', (exitCode, signal) => {
|
browserServer.on('close', (exitCode, signal) => {
|
||||||
console.log(`browserClose:${exitCode}:${signal}:browserClose`);
|
console.log(`browserClose:${exitCode}:${signal}:browserClose`);
|
||||||
|
if (exitOnClose)
|
||||||
|
process.exit(0);
|
||||||
});
|
});
|
||||||
console.log(`browserPid:${browserServer.process().pid}:browserPid`);
|
console.log(`browserPid:${browserServer.process().pid}:browserPid`);
|
||||||
console.log(`browserWS:${browserServer.wsEndpoint()}:browserWS`);
|
console.log(`browserWS:${browserServer.wsEndpoint()}:browserWS`);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue