-
-
Notifications
You must be signed in to change notification settings - Fork 35.5k
Expand file tree
/
Copy pathtest-debugger-pid.js
More file actions
55 lines (47 loc) · 1.71 KB
/
test-debugger-pid.js
File metadata and controls
55 lines (47 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
'use strict';
const common = require('../common');
common.skipIfInspectorDisabled();
const fixtures = require('../common/fixtures');
const startCLI = require('../common/debugger');
const assert = require('assert');
const net = require('net');
const { spawn } = require('child_process');
const script = fixtures.path('debugger', 'alive.js');
// The -p <pid> attach mode uses the default inspector port (9229).
// If that port is already in use, the test will hang. Check first and skip.
function checkPort(port) {
const { promise, resolve, reject } = Promise.withResolvers();
const server = net.createServer();
server.once('error', reject);
server.listen(port, '127.0.0.1', () => server.close(resolve));
return promise;
}
(async () => {
try {
await checkPort(9229);
} catch (e) {
// In the typical case, this test runs in sequential set and depends on
// nothing else bound to port 9229. However, if there's some other failure
// that causes an orphaned process to be left running on port 9229, this
// test was hanging and timing out. Let's arrange to skip instead of hanging.
if (e.code === 'EADDRINUSE') {
common.skip('Port 9229 is already in use');
}
throw e;
}
const target = spawn(process.execPath, [script]);
const cli = startCLI(['-p', `${target.pid}`], [], {}, { randomPort: false });
try {
await cli.waitForPrompt();
await cli.command('sb("alive.js", 3)');
await cli.waitFor(/break/);
await cli.waitForPrompt();
assert.match(cli.output, /> 3 {3}\+\+x;/, 'marks the 3rd line');
} finally {
target.kill();
await Promise.race([
cli.quit(),
new Promise((resolve) => setTimeout(resolve, 5000)),
]);
}
})().then(common.mustCall());