Skip to content

Commit

Permalink
test: remove a snapshot blob from test-inspect-address-in-use.js
Browse files Browse the repository at this point in the history
This removes a snapshot blob generated by
`test/parallel/test-inspect-address-in-use.js`.

Signed-off-by: Daeyeon Jeong <daeyeon.dev@gmail.com>
PR-URL: #45132
Fixes: #45017
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com>
  • Loading branch information
daeyeon authored and danielleadams committed Dec 30, 2022
1 parent 922f01f commit 5851412
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions test/parallel/test-inspect-address-in-use.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
'use strict';
const common = require('../common');
common.skipIfInspectorDisabled();

const { spawnSync } = require('child_process');
const { createServer } = require('http');
const assert = require('assert');
const tmpdir = require('../common/tmpdir');
const fixtures = require('../common/fixtures');
const entry = fixtures.path('empty.js');
const { Worker } = require('worker_threads');

function testOnServerListen(fn) {
const server = createServer((socket) => {
socket.end('echo');
});

server.on('listening', () => {
fn(server);
server.close();
});
server.listen(0, '127.0.0.1');
}

function testChildProcess(getArgs, exitCode, options) {
testOnServerListen((server) => {
const { port } = server.address();
const child = spawnSync(process.execPath, getArgs(port), options);
const stderr = child.stderr.toString().trim();
const stdout = child.stdout.toString().trim();
console.log('[STDERR]');
console.log(stderr);
console.log('[STDOUT]');
console.log(stdout);
const match = stderr.match(
/Starting inspector on 127\.0\.0\.1:(\d+) failed: address already in use/
);
assert.notStrictEqual(match, null);
assert.strictEqual(match[1], port + '');
assert.strictEqual(child.status, exitCode);
});
}

tmpdir.refresh();

testChildProcess(
(port) => [`--inspect=${port}`, '--build-snapshot', entry], 0,
{ cwd: tmpdir.path });

testChildProcess(
(port) => [`--inspect=${port}`, entry], 0);

testOnServerListen((server) => {
const { port } = server.address();
const worker = new Worker(entry, {
execArgv: [`--inspect=${port}`]
});

worker.on('error', common.mustNotCall());

worker.on('exit', common.mustCall((code) => {
assert.strictEqual(code, 0);
}));
});

0 comments on commit 5851412

Please sign in to comment.