File tree Expand file tree Collapse file tree 4 files changed +12
-11
lines changed Expand file tree Collapse file tree 4 files changed +12
-11
lines changed Original file line number Diff line number Diff line change 20
20
// USE OR OTHER DEALINGS IN THE SOFTWARE.
21
21
22
22
'use strict' ;
23
- const common = require ( '../common' ) ;
23
+ require ( '../common' ) ;
24
24
const assert = require ( 'assert' ) ;
25
25
const cluster = require ( 'cluster' ) ;
26
26
const net = require ( 'net' ) ;
@@ -60,7 +60,7 @@ if (cluster.isWorker) {
60
60
maybeReply ( ) ;
61
61
} ) ;
62
62
63
- server . listen ( common . PORT , '127.0.0.1' ) ;
63
+ server . listen ( 0 , '127.0.0.1' ) ;
64
64
} else if ( cluster . isMaster ) {
65
65
66
66
const checks = {
@@ -109,9 +109,9 @@ if (cluster.isWorker) {
109
109
} ) ;
110
110
111
111
// When a TCP server is listening in the worker connect to it
112
- worker . on ( 'listening' , function ( ) {
112
+ worker . on ( 'listening' , function ( address ) {
113
113
114
- client = net . connect ( common . PORT , function ( ) {
114
+ client = net . connect ( address . port , function ( ) {
115
115
// Send message to worker.
116
116
worker . send ( 'message from master' ) ;
117
117
} ) ;
Original file line number Diff line number Diff line change @@ -23,10 +23,10 @@ if (cluster.isMaster) {
23
23
} else {
24
24
const net = require ( 'net' ) ;
25
25
const server = net . createServer ( ) ;
26
- server . listen ( common . PORT , common . mustCall ( ( ) => {
26
+ server . listen ( 0 , common . mustCall ( ( ) => {
27
27
if ( cluster . worker . id === 2 ) {
28
28
server . close ( ( ) => {
29
- server . listen ( common . PORT , common . mustCall ( ( ) => {
29
+ server . listen ( 0 , common . mustCall ( ( ) => {
30
30
server . close ( ( ) => {
31
31
process . disconnect ( ) ;
32
32
} ) ;
Original file line number Diff line number Diff line change @@ -23,10 +23,10 @@ if (cluster.isMaster) {
23
23
} else {
24
24
const net = require ( 'net' ) ;
25
25
const server = net . createServer ( ) ;
26
- server . listen ( common . PORT , common . mustCall ( ( ) => {
26
+ server . listen ( 0 , common . mustCall ( ( ) => {
27
27
if ( cluster . worker . id === 2 ) {
28
28
server . close ( ( ) => {
29
- server . listen ( common . PORT , common . mustCall ( ( ) => {
29
+ server . listen ( 0 , common . mustCall ( ( ) => {
30
30
server . close ( ( ) => {
31
31
process . disconnect ( ) ;
32
32
} ) ;
Original file line number Diff line number Diff line change @@ -31,16 +31,17 @@ if (cluster.isMaster) {
31
31
// Hog the TCP port so that when the worker tries to bind, it'll fail.
32
32
const server = net . createServer ( common . mustNotCall ( ) ) ;
33
33
34
- server . listen ( common . PORT , common . mustCall ( ( ) => {
35
- const worker = cluster . fork ( ) ;
34
+ server . listen ( 0 , common . mustCall ( ( ) => {
35
+ const worker = cluster . fork ( { PORT : server . address ( ) . port } ) ;
36
36
worker . on ( 'exit' , common . mustCall ( ( exitCode ) => {
37
37
assert . strictEqual ( exitCode , 0 ) ;
38
38
server . close ( ) ;
39
39
} ) ) ;
40
40
} ) ) ;
41
41
} else {
42
+ assert ( process . env . PORT ) ;
42
43
const s = net . createServer ( common . mustNotCall ( ) ) ;
43
- s . listen ( common . PORT , common . mustNotCall ( 'listen should have failed' ) ) ;
44
+ s . listen ( process . env . PORT , common . mustNotCall ( 'listen should have failed' ) ) ;
44
45
s . on ( 'error' , common . mustCall ( ( err ) => {
45
46
assert . strictEqual ( err . code , 'EADDRINUSE' ) ;
46
47
process . disconnect ( ) ;
You can’t perform that action at this time.
0 commit comments