Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: dynamic port in parallel cluster tests #12584

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions test/parallel/test-cluster-message.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
// USE OR OTHER DEALINGS IN THE SOFTWARE.

'use strict';
const common = require('../common');
require('../common');
const assert = require('assert');
const cluster = require('cluster');
const net = require('net');
Expand Down Expand Up @@ -60,7 +60,7 @@ if (cluster.isWorker) {
maybeReply();
});

server.listen(common.PORT, '127.0.0.1');
server.listen(0, '127.0.0.1');
} else if (cluster.isMaster) {

const checks = {
Expand Down Expand Up @@ -109,9 +109,9 @@ if (cluster.isWorker) {
});

// When a TCP server is listening in the worker connect to it
worker.on('listening', function() {
worker.on('listening', function(address) {

client = net.connect(common.PORT, function() {
client = net.connect(address.port, function() {
// Send message to worker.
worker.send('message from master');
});
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-cluster-server-restart-none.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ if (cluster.isMaster) {
} else {
const net = require('net');
const server = net.createServer();
server.listen(common.PORT, common.mustCall(() => {
server.listen(0, common.mustCall(() => {
if (cluster.worker.id === 2) {
server.close(() => {
server.listen(common.PORT, common.mustCall(() => {
server.listen(0, common.mustCall(() => {
server.close(() => {
process.disconnect();
});
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-cluster-server-restart-rr.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ if (cluster.isMaster) {
} else {
const net = require('net');
const server = net.createServer();
server.listen(common.PORT, common.mustCall(() => {
server.listen(0, common.mustCall(() => {
if (cluster.worker.id === 2) {
server.close(() => {
server.listen(common.PORT, common.mustCall(() => {
server.listen(0, common.mustCall(() => {
server.close(() => {
process.disconnect();
});
Expand Down
7 changes: 4 additions & 3 deletions test/parallel/test-cluster-shared-handle-bind-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,17 @@ if (cluster.isMaster) {
// Hog the TCP port so that when the worker tries to bind, it'll fail.
const server = net.createServer(common.mustNotCall());

server.listen(common.PORT, common.mustCall(() => {
const worker = cluster.fork();
server.listen(0, common.mustCall(() => {
const worker = cluster.fork({PORT: server.address().port});
worker.on('exit', common.mustCall((exitCode) => {
assert.strictEqual(exitCode, 0);
server.close();
}));
}));
} else {
assert(process.env.PORT);
const s = net.createServer(common.mustNotCall());
s.listen(common.PORT, common.mustNotCall('listen should have failed'));
s.listen(process.env.PORT, common.mustNotCall('listen should have failed'));
s.on('error', common.mustCall((err) => {
assert.strictEqual(err.code, 'EADDRINUSE');
process.disconnect();
Expand Down