@@ -57,7 +57,6 @@ export default class Coordinator {
57
57
private readonly eventDataCollector : EventDataCollector
58
58
private readonly stopwatch : ITestRunStopwatch
59
59
private onFinish : ( success : boolean ) => void
60
- private nextPickleIdIndex : number
61
60
private readonly options : IRuntimeOptions
62
61
private readonly pickleIds : string [ ]
63
62
private inProgressPickles : Dictionary < messages . IPickle >
@@ -90,7 +89,6 @@ export default class Coordinator {
90
89
this . supportCodePaths = supportCodePaths
91
90
this . supportCodeRequiredModules = supportCodeRequiredModules
92
91
this . pickleIds = pickleIds
93
- this . nextPickleIdIndex = 0
94
92
this . success = true
95
93
this . workers = { }
96
94
this . inProgressPickles = { }
@@ -169,10 +167,7 @@ export default class Coordinator {
169
167
return worker . state !== WorkerState . idle
170
168
} )
171
169
172
- if (
173
- _ . isEmpty ( this . inProgressPickles ) &&
174
- this . pickleIds . length > this . nextPickleIdIndex
175
- ) {
170
+ if ( _ . isEmpty ( this . inProgressPickles ) && this . pickleIds . length > 0 ) {
176
171
this . giveWork ( workers [ 0 ] , true )
177
172
this . idleInterventions ++
178
173
}
@@ -262,54 +257,47 @@ export default class Coordinator {
262
257
}
263
258
264
259
nextPicklePlacement ( ) : IPicklePlacement {
265
- for (
266
- let index = this . nextPickleIdIndex ;
267
- index < this . pickleIds . length ;
268
- index ++
269
- ) {
270
- const pickle = this . eventDataCollector . getPickle ( this . pickleIds [ index ] )
260
+ for ( let index = 0 ; index < this . pickleIds . length ; index ++ ) {
261
+ const placement = this . placementAt ( index )
271
262
if (
272
263
this . supportCodeLibrary . parallelCanAssign (
273
- pickle ,
264
+ placement . pickle ,
274
265
_ . values ( this . inProgressPickles )
275
266
)
276
267
) {
277
- return { index , pickle }
268
+ return placement
278
269
}
279
270
}
280
271
281
272
return null
282
273
}
283
274
275
+ placementAt ( index : number ) : IPicklePlacement {
276
+ return {
277
+ index,
278
+ pickle : this . eventDataCollector . getPickle ( this . pickleIds [ index ] ) ,
279
+ }
280
+ }
281
+
284
282
giveWork ( worker : IWorker , force : boolean = false ) : void {
285
- if ( this . nextPickleIdIndex >= this . pickleIds . length ) {
283
+ if ( this . pickleIds . length < 1 ) {
286
284
const finalizeCommand : IWorkerCommand = { finalize : true }
287
285
worker . state = WorkerState . running
288
286
worker . process . send ( finalizeCommand )
289
287
return
290
288
}
291
289
292
290
const picklePlacement = force
293
- ? {
294
- index : this . nextPickleIdIndex ,
295
- pickle : this . eventDataCollector . getPickle (
296
- this . pickleIds [ this . nextPickleIdIndex ]
297
- ) ,
298
- }
291
+ ? this . placementAt ( 0 )
299
292
: this . nextPicklePlacement ( )
293
+
300
294
if ( picklePlacement === null ) {
301
295
return
302
296
}
303
297
304
- if ( this . nextPickleIdIndex !== picklePlacement . index ) {
305
- this . pickleIds . splice (
306
- picklePlacement . index ,
307
- 0 ,
308
- this . pickleIds . splice ( this . nextPickleIdIndex , 1 ) [ 0 ]
309
- )
310
- }
311
- this . nextPickleIdIndex += 1
312
- const pickle = picklePlacement . pickle
298
+ const { index : nextPickleIndex , pickle } = picklePlacement
299
+
300
+ this . pickleIds . splice ( nextPickleIndex , 1 )
313
301
this . inProgressPickles [ worker . id ] = pickle
314
302
const gherkinDocument = this . eventDataCollector . getGherkinDocument (
315
303
pickle . uri
0 commit comments