@@ -23,7 +23,7 @@ function testRunnerMain() {
23
23
workers : [ { expectedPort : 9230 } ]
24
24
} ) ;
25
25
26
- let port = debuggerPort + offset ++ * 10 ;
26
+ let port = debuggerPort + offset ++ * 5 ;
27
27
28
28
spawnMaster ( {
29
29
execArgv : [ `--inspect=${ port } ` ] ,
@@ -34,81 +34,172 @@ function testRunnerMain() {
34
34
]
35
35
} ) ;
36
36
37
- port = debuggerPort + offset ++ * 10 ;
37
+ port = debuggerPort + offset ++ * 5 ;
38
38
39
39
spawnMaster ( {
40
40
execArgv : [ '--inspect' , `--inspect-port=${ port } ` ] ,
41
41
workers : [ { expectedPort : port + 1 } ]
42
42
} ) ;
43
43
44
- port = debuggerPort + offset ++ * 10 ;
44
+ port = debuggerPort + offset ++ * 5 ;
45
45
46
46
spawnMaster ( {
47
47
execArgv : [ '--inspect' , `--debug-port=${ port } ` ] ,
48
48
workers : [ { expectedPort : port + 1 } ]
49
49
} ) ;
50
50
51
- port = debuggerPort + offset ++ * 10 ;
51
+ port = debuggerPort + offset ++ * 5 ;
52
52
53
53
spawnMaster ( {
54
54
execArgv : [ `--inspect=0.0.0.0:${ port } ` ] ,
55
55
workers : [ { expectedPort : port + 1 , expectedHost : '0.0.0.0' } ]
56
56
} ) ;
57
57
58
- port = debuggerPort + offset ++ * 10 ;
58
+ port = debuggerPort + offset ++ * 5 ;
59
59
60
60
spawnMaster ( {
61
61
execArgv : [ `--inspect=127.0.0.1:${ port } ` ] ,
62
62
workers : [ { expectedPort : port + 1 , expectedHost : '127.0.0.1' } ]
63
63
} ) ;
64
64
65
65
if ( common . hasIPv6 ) {
66
- port = debuggerPort + offset ++ * 10 ;
66
+ port = debuggerPort + offset ++ * 5 ;
67
67
68
68
spawnMaster ( {
69
69
execArgv : [ `--inspect=[::]:${ port } ` ] ,
70
70
workers : [ { expectedPort : port + 1 , expectedHost : '::' } ]
71
71
} ) ;
72
72
73
- port = debuggerPort + offset ++ * 10 ;
73
+ port = debuggerPort + offset ++ * 5 ;
74
74
75
75
spawnMaster ( {
76
76
execArgv : [ `--inspect=[::1]:${ port } ` ] ,
77
77
workers : [ { expectedPort : port + 1 , expectedHost : '::1' } ]
78
78
} ) ;
79
79
}
80
+
81
+ /*
82
+ * Following tests check that port should not increment
83
+ * if developer sets inspector port in cluster.setupMaster arguments.
84
+ */
85
+
86
+ port = debuggerPort + offset ++ * 5 ;
87
+
88
+ spawnMaster ( {
89
+ execArgv : [ `--inspect=${ port } ` ] ,
90
+ workers : [
91
+ { expectedPort : port + 2 } ,
92
+ { expectedPort : port + 4 } ,
93
+ { expectedPort : port + 6 }
94
+ ] ,
95
+ clusterExecArgv : [
96
+ [ `--inspect=${ port + 2 } ` ] ,
97
+ [ `--inspect-port=${ port + 4 } ` ] ,
98
+ [ `--debug-port=${ port + 6 } ` ] ,
99
+ ]
100
+ } ) ;
101
+
102
+ port = debuggerPort + offset ++ * 5 ;
103
+
104
+ spawnMaster ( {
105
+ execArgv : [ ] ,
106
+ workers : [
107
+ { expectedPort : port }
108
+ ] ,
109
+ clusterExecArgv : [
110
+ [ `--inspect=${ port } ` ]
111
+ ]
112
+ } ) ;
113
+
114
+ // Next tests check that inspector port incrementing logic
115
+ // is disabled if zero port passed to workers.
116
+ // Even if supplied execArgv is equal to master's.
117
+
118
+ spawnMaster ( {
119
+ execArgv : [ ] ,
120
+ workers : [
121
+ { expectedInitialPort : 0 } ,
122
+ { expectedInitialPort : 0 } ,
123
+ { expectedInitialPort : 0 }
124
+ ] ,
125
+ clusterExecArgv : [
126
+ [ '--inspect=0' ] ,
127
+ [ '--inspect=0' ] ,
128
+ [ '--inspect=0' ]
129
+ ]
130
+ } ) ;
131
+
132
+ spawnMaster ( {
133
+ execArgv : [ '--inspect=0' ] ,
134
+ workers : [
135
+ { expectedInitialPort : 0 } ,
136
+ { expectedInitialPort : 0 } ,
137
+ { expectedInitialPort : 0 }
138
+ ] ,
139
+ clusterExecArgv : [
140
+ [ '--inspect=0' ] ,
141
+ [ '--inspect=0' ] ,
142
+ [ '--inspect=0' ]
143
+ ]
144
+ } ) ;
145
+
146
+ spawnMaster ( {
147
+ execArgv : [ '--inspect=0' ] ,
148
+ workers : [
149
+ { expectedInitialPort : 0 } ,
150
+ { expectedInitialPort : 0 } ,
151
+ { expectedInitialPort : 0 }
152
+ ] ,
153
+ clusterExecArgv : [
154
+ [ '--inspect' , '--inspect-port=0' ] ,
155
+ [ '--inspect' , '--inspect-port=0' ] ,
156
+ [ '--inspect' , '--inspect-port=0' ]
157
+ ]
158
+ } ) ;
159
+
80
160
}
81
161
82
162
function masterProcessMain ( ) {
83
163
const workers = JSON . parse ( process . env . workers ) ;
164
+ const clusterExecArgv = JSON . parse ( process . env . clusterExecArgv ) ;
165
+
166
+ for ( const [ index , worker ] of workers . entries ( ) ) {
167
+ if ( clusterExecArgv [ index ] ) {
168
+ cluster . setupMaster ( { execArgv : clusterExecArgv [ index ] } ) ;
169
+ }
84
170
85
- for ( const worker of workers ) {
86
171
cluster . fork ( {
87
172
expectedPort : worker . expectedPort ,
173
+ expectedInitialPort : worker . expectedInitialPort ,
88
174
expectedHost : worker . expectedHost
89
175
} ) . on ( 'exit' , common . mustCall ( checkExitCode ) ) ;
90
176
}
91
177
}
92
178
93
179
function workerProcessMain ( ) {
94
- const { expectedPort, expectedHost} = process . env ;
180
+ const { expectedPort, expectedInitialPort, expectedHost} = process . env ;
181
+ const debugOptions = process . binding ( 'config' ) . debugOptions ;
182
+
183
+ if ( + expectedPort ) {
184
+ assert . strictEqual ( process . debugPort , + expectedPort ) ;
185
+ }
95
186
96
- assert . strictEqual ( process . debugPort , + expectedPort ) ;
187
+ if ( + expectedInitialPort ) {
188
+ assert . strictEqual ( debugOptions . port , + expectedInitialPort ) ;
189
+ }
97
190
98
191
if ( expectedHost !== 'undefined' ) {
99
- assert . strictEqual (
100
- process . binding ( 'config' ) . debugOptions . host ,
101
- expectedHost
102
- ) ;
192
+ assert . strictEqual ( debugOptions . host , expectedHost ) ;
103
193
}
104
194
105
195
process . exit ( ) ;
106
196
}
107
197
108
- function spawnMaster ( { execArgv, workers} ) {
198
+ function spawnMaster ( { execArgv, workers, clusterExecArgv = [ ] } ) {
109
199
childProcess . fork ( __filename , {
110
200
env : {
111
201
workers : JSON . stringify ( workers ) ,
202
+ clusterExecArgv : JSON . stringify ( clusterExecArgv ) ,
112
203
testProcess : true
113
204
} ,
114
205
execArgv
0 commit comments