Skip to content

Commit 6654b6e

Browse files
committed
Utilizing ParallelAssignmentValidator type for ISupportCodeLibrary.parallelCanAssign
1 member in IWorker to cover all states
1 parent 37b23e1 commit 6654b6e

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

src/runtime/parallel/coordinator.ts

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,14 @@ export interface INewCoordinatorOptions {
3333
supportCodeRequiredModules: string[]
3434
}
3535

36+
const enum WorkerState {
37+
'idle',
38+
'closed',
39+
'running',
40+
}
41+
3642
interface IWorker {
37-
closed: boolean
38-
idle: boolean
43+
state: WorkerState
3944
process: ChildProcess
4045
id: string
4146
}
@@ -104,7 +109,7 @@ export default class Coordinator {
104109
this.remapDefinitionIds(envelope.testCase)
105110
}
106111
if (doesHaveValue(envelope.testCaseFinished)) {
107-
worker.idle = true
112+
worker.state = WorkerState.idle
108113
this.inProgressPickles = _.omit(this.inProgressPickles, worker.id)
109114
this.parseTestCaseResult(envelope.testCaseFinished)
110115
}
@@ -155,10 +160,10 @@ export default class Coordinator {
155160
awakenWorkers(): void {
156161
const workers = _.values(this.workers)
157162
_.each(workers, (worker): boolean => {
158-
if (worker.idle) {
163+
if (worker.state === WorkerState.idle) {
159164
this.giveWork(worker)
160165
}
161-
return !worker.idle
166+
return worker.state !== WorkerState.idle
162167
})
163168
}
164169

@@ -172,13 +177,13 @@ export default class Coordinator {
172177
}),
173178
stdio: ['inherit', 'inherit', 'inherit', 'ipc'],
174179
})
175-
const worker = { closed: false, idle: true, process: workerProcess, id }
180+
const worker = { state: WorkerState.idle, process: workerProcess, id }
176181
this.workers[id] = worker
177182
worker.process.on('message', (message: ICoordinatorReport) => {
178183
this.parseWorkerMessage(worker, message)
179184
})
180185
worker.process.on('close', (exitCode) => {
181-
worker.closed = true
186+
worker.state = WorkerState.closed
182187
this.onWorkerProcessClose(exitCode)
183188
})
184189
const initializeCommand: IWorkerCommand = {
@@ -196,7 +201,7 @@ export default class Coordinator {
196201
if (exitCode !== 0) {
197202
this.success = false
198203
}
199-
if (_.every(this.workers, 'closed')) {
204+
if (_.every(this.workers, ({ state }) => state === WorkerState.closed)) {
200205
this.eventBroadcaster.emit(
201206
'envelope',
202207
messages.Envelope.fromObject({
@@ -260,8 +265,8 @@ export default class Coordinator {
260265

261266
giveWork(worker: IWorker): void {
262267
if (this.nextPickleIdIndex >= this.pickleIds.length) {
263-
worker.idle = false
264268
const finalizeCommand: IWorkerCommand = { finalize: true }
269+
worker.state = WorkerState.running
265270
worker.process.send(finalizeCommand)
266271
return
267272
}
@@ -295,7 +300,7 @@ export default class Coordinator {
295300
gherkinDocument,
296301
},
297302
}
298-
worker.idle = false
303+
worker.state = WorkerState.running
299304
worker.process.send(runCommand)
300305
}
301306

src/support_code_library_builder/types.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,5 @@ export interface ISupportCodeLibrary {
128128
readonly undefinedParameterTypes: messages.IUndefinedParameterType[]
129129
readonly parameterTypeRegistry: ParameterTypeRegistry
130130
readonly World: any
131-
readonly parallelCanAssign: (
132-
pickle: messages.IPickle,
133-
runningPickles: messages.IPickle[]
134-
) => Boolean
131+
readonly parallelCanAssign: ParallelAssignmentValidator
135132
}

0 commit comments

Comments
 (0)