node/test/parallel/test-process-execve-socket.js
Paolo Insogna 13a9d4c160
Some checks are pending
Coverage Linux (without intl) / coverage-linux-without-intl (push) Waiting to run
Coverage Linux / coverage-linux (push) Waiting to run
Coverage Windows / coverage-windows (push) Waiting to run
Test and upload documentation to artifacts / build-docs (push) Waiting to run
Linters / lint-addon-docs (push) Waiting to run
Linters / lint-cpp (push) Waiting to run
Linters / format-cpp (push) Waiting to run
Linters / lint-js-and-md (push) Waiting to run
Linters / lint-py (push) Waiting to run
Linters / lint-yaml (push) Waiting to run
Linters / lint-sh (push) Waiting to run
Linters / lint-codeowners (push) Waiting to run
Linters / lint-pr-url (push) Waiting to run
Linters / lint-readme (push) Waiting to run
Notify on Push / Notify on Force Push on `main` (push) Waiting to run
Notify on Push / Notify on Push on `main` that lacks metadata (push) Waiting to run
Scorecard supply-chain security / Scorecard analysis (push) Waiting to run
process: add execve
PR-URL: https://github.com/nodejs/node/pull/56496
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
Reviewed-By: Bryan English <bryan@bryanenglish.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2025-03-21 21:36:41 +01:00

50 lines
1.3 KiB
JavaScript

'use strict';
const { mustCall, mustNotCall, skip, isWindows } = require('../common');
const { fail, ok } = require('assert');
const { createServer } = require('net');
const { isMainThread } = require('worker_threads');
if (!isMainThread) {
skip('process.execve is not available in Workers');
} else if (isWindows) {
skip('process.execve is not available in Windows');
}
if (process.argv[2] === 'replaced') {
const port = parseInt(process.env.PORT, 10);
ok(Number.isInteger(port));
const server = createServer();
server.on('error', mustNotCall());
server.listen(port, mustCall(() => {
server.close();
}));
} else {
// Create a new socket server
const server = createServer();
server.on('close', mustNotCall());
server.listen(0, mustCall(() => {
const port = server.address().port;
// Try to create a second server on the same port. It should fail.
const server2 = createServer();
server2.on('error', mustCall(() => {
process.execve(
process.execPath,
[process.execPath, __filename, 'replaced'],
{ ...process.env, PORT: port.toString() }
);
// If process.execve succeed, this should never be executed.
fail('process.execve failed');
}));
server2.listen(port, mustCall(() => {
fail('server2.listen unexpectedly succeeded');
}));
}));
}