-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: harden test-dgram-bind-shared-ports
* add `mustCall` and `mustNotCall` to all callbacks * added `known_issue` for port binding PR-URL: #13100 Refs: #13055 Refs: #12999 Refs: #13526 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
- Loading branch information
Showing
2 changed files
with
125 additions
and
31 deletions.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
test/known_issues/test-dgram-bind-shared-ports-after-port-0.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
|
||
// This test should fail because at present `cluster` does not know how to share | ||
// a socket when `worker1` binds with `port: 0`, and others try to bind to the | ||
// assigned port number from `worker1` | ||
// | ||
// *Note*: since this is a `known_issue` we try to swallow all errors except | ||
// the one we are interested in | ||
|
||
const assert = require('assert'); | ||
const cluster = require('cluster'); | ||
const dgram = require('dgram'); | ||
const BYE = 'bye'; | ||
|
||
if (cluster.isMaster) { | ||
const worker1 = cluster.fork(); | ||
|
||
// verify that Windows doesn't support this scenario | ||
worker1.on('error', (err) => { | ||
if (err.code === 'ENOTSUP') throw err; | ||
}); | ||
|
||
worker1.on('message', (msg) => { | ||
if (typeof msg !== 'object') process.exit(0); | ||
if (msg.message !== 'success') process.exit(0); | ||
if (typeof msg.port1 !== 'number') process.exit(0); | ||
|
||
const worker2 = cluster.fork({ PRT1: msg.port1 }); | ||
worker2.on('message', () => process.exit(0)); | ||
worker2.on('exit', (code, signal) => { | ||
// this is the droid we are looking for | ||
assert.strictEqual(code, 0); | ||
assert.strictEqual(signal, null); | ||
}); | ||
|
||
// cleanup anyway | ||
process.on('exit', () => { | ||
worker1.send(BYE); | ||
worker2.send(BYE); | ||
}); | ||
}); | ||
// end master code | ||
} else { | ||
// worker code | ||
process.on('message', (msg) => msg === BYE && process.exit(0)); | ||
|
||
// first worker will bind to '0', second will try the assigned port and fail | ||
const PRT1 = process.env.PRT1 || 0; | ||
const socket1 = dgram.createSocket('udp4', () => {}); | ||
socket1.on('error', PRT1 === 0 ? () => {} : assert.fail); | ||
socket1.bind( | ||
{ address: common.localhostIPv4, port: PRT1, exclusive: false }, | ||
() => process.send({ message: 'success', port1: socket1.address().port }) | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters