@@ -33,9 +33,14 @@ export interface INewCoordinatorOptions {
33
33
supportCodeRequiredModules : string [ ]
34
34
}
35
35
36
+ const enum WorkerState {
37
+ 'idle' ,
38
+ 'closed' ,
39
+ 'running' ,
40
+ }
41
+
36
42
interface IWorker {
37
- closed : boolean
38
- idle : boolean
43
+ state : WorkerState
39
44
process : ChildProcess
40
45
id : string
41
46
}
@@ -104,7 +109,7 @@ export default class Coordinator {
104
109
this . remapDefinitionIds ( envelope . testCase )
105
110
}
106
111
if ( doesHaveValue ( envelope . testCaseFinished ) ) {
107
- worker . idle = true
112
+ worker . state = WorkerState . idle
108
113
this . inProgressPickles = _ . omit ( this . inProgressPickles , worker . id )
109
114
this . parseTestCaseResult ( envelope . testCaseFinished )
110
115
}
@@ -155,10 +160,10 @@ export default class Coordinator {
155
160
awakenWorkers ( ) : void {
156
161
const workers = _ . values ( this . workers )
157
162
_ . each ( workers , ( worker ) : boolean => {
158
- if ( worker . idle ) {
163
+ if ( worker . state === WorkerState . idle ) {
159
164
this . giveWork ( worker )
160
165
}
161
- return ! worker . idle
166
+ return worker . state !== WorkerState . idle
162
167
} )
163
168
}
164
169
@@ -172,13 +177,13 @@ export default class Coordinator {
172
177
} ) ,
173
178
stdio : [ 'inherit' , 'inherit' , 'inherit' , 'ipc' ] ,
174
179
} )
175
- const worker = { closed : false , idle : true , process : workerProcess , id }
180
+ const worker = { state : WorkerState . idle , process : workerProcess , id }
176
181
this . workers [ id ] = worker
177
182
worker . process . on ( 'message' , ( message : ICoordinatorReport ) => {
178
183
this . parseWorkerMessage ( worker , message )
179
184
} )
180
185
worker . process . on ( 'close' , ( exitCode ) => {
181
- worker . closed = true
186
+ worker . state = WorkerState . closed
182
187
this . onWorkerProcessClose ( exitCode )
183
188
} )
184
189
const initializeCommand : IWorkerCommand = {
@@ -196,7 +201,7 @@ export default class Coordinator {
196
201
if ( exitCode !== 0 ) {
197
202
this . success = false
198
203
}
199
- if ( _ . every ( this . workers , ' closed' ) ) {
204
+ if ( _ . every ( this . workers , ( { state } ) => state === WorkerState . closed ) ) {
200
205
this . eventBroadcaster . emit (
201
206
'envelope' ,
202
207
messages . Envelope . fromObject ( {
@@ -260,8 +265,8 @@ export default class Coordinator {
260
265
261
266
giveWork ( worker : IWorker ) : void {
262
267
if ( this . nextPickleIdIndex >= this . pickleIds . length ) {
263
- worker . idle = false
264
268
const finalizeCommand : IWorkerCommand = { finalize : true }
269
+ worker . state = WorkerState . running
265
270
worker . process . send ( finalizeCommand )
266
271
return
267
272
}
@@ -295,7 +300,7 @@ export default class Coordinator {
295
300
gherkinDocument,
296
301
} ,
297
302
}
298
- worker . idle = false
303
+ worker . state = WorkerState . running
299
304
worker . process . send ( runCommand )
300
305
}
301
306
0 commit comments