test: fix multiple connections in inspector test (#23648)

* test: fix multiple connections in inspector test

* debug log
This commit is contained in:
Jeremy Apthorp 2020-05-18 19:05:49 -07:00 committed by GitHub
parent 89441caad4
commit c00103d274
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -172,6 +172,8 @@ describe('node feature', () => {
} else if (child) { } else if (child) {
child.kill(); child.kill();
} }
child = null as any;
exitPromise = null as any;
}); });
it('Supports starting the v8 inspector with --inspect/--inspect-brk', (done) => { it('Supports starting the v8 inspector with --inspect/--inspect-brk', (done) => {
@ -241,7 +243,7 @@ describe('node feature', () => {
}); });
// IPC Electron child process not supported on Windows // IPC Electron child process not supported on Windows
ifit(process.platform !== 'win32')('Does does not crash when quitting with the inspector connected', function (done) { ifit(process.platform !== 'win32')('does not crash when quitting with the inspector connected', function (done) {
child = childProcess.spawn(process.execPath, [path.join(fixtures, 'module', 'delay-exit'), '--inspect=0'], { child = childProcess.spawn(process.execPath, [path.join(fixtures, 'module', 'delay-exit'), '--inspect=0'], {
stdio: ['ipc'] stdio: ['ipc']
}) as childProcess.ChildProcessWithoutNullStreams; }) as childProcess.ChildProcessWithoutNullStreams;
@ -253,29 +255,27 @@ describe('node feature', () => {
}; };
let output = ''; let output = '';
let success = false; const success = false;
function listener (data: Buffer) { function listener (data: Buffer) {
output += data; output += data;
if (output.trim().indexOf('Debugger listening on ws://') > -1 && output.indexOf('\n') > -1) { console.log(data); // NOTE: temporary debug logging to try to catch flake.
const socketMatch = output.trim().match(/(ws:\/\/.+:[0-9]+\/.+?)\n/gm); const match = /^Debugger listening on (ws:\/\/.+:\d+\/.+)\n/m.exec(output.trim());
if (socketMatch && socketMatch[0]) { if (match) {
const w = (webContents as any).create({}) as WebContents; cleanup();
w.loadURL('about:blank') const w = (webContents as any).create({}) as WebContents;
.then(() => w.executeJavaScript(`new Promise(resolve => { w.loadURL('about:blank')
const connection = new WebSocket(${JSON.stringify(socketMatch[0])}) .then(() => w.executeJavaScript(`new Promise(resolve => {
connection.onopen = () => { const connection = new WebSocket(${JSON.stringify(match[1])})
resolve() connection.onopen = () => {
connection.close() resolve()
} connection.close()
})`)) }
.then(() => { })`))
(w as any).destroy(); .then(() => {
child.send('plz-quit'); (w as any).destroy();
success = true; child.send('plz-quit');
cleanup(); done();
done(); });
});
}
} }
} }