Skip to content

Commit ee3c8ed

Browse files
committed
address CR
1 parent 0867dfa commit ee3c8ed

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

docs/configuration.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export const config = {
4545
- `timeout` — default per-test timeout in seconds; a test is killed if it stops responding.
4646
- `mocha`[Mocha options](https://mochajs.org/#configuring-mocha-nodejs), including extra reporters. See [Reporters](/reports).
4747
- `workerInitializationDelay` — delay in milliseconds between spinning up parallel workers to prevent CPU spikes and stagger browser startup. Defaults to `200`. Set to `0` to disable.
48+
- `workerInitializationMaxDelay` — maximum total delay (in milliseconds) for worker initialization staggering. Defaults to `10000` (10 s). Set to `0` to disable capping.
4849

4950
**BDD**
5051

lib/workers.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -512,15 +512,22 @@ class Workers extends EventEmitter {
512512
? this.codecept.config.workerInitializationDelay
513513
: 200
514514

515+
// Maximum total stagger window (default 10 seconds). Allows capping total delay regardless of worker count.
516+
const maxStagger = this.codecept.config.workerInitializationMaxDelay ?? 10000
517+
// Compute effective per-worker delay to keep total stagger within maxStagger.
518+
const effectiveDelay = staggerDelay > 0
519+
? Math.min(staggerDelay, Math.floor(maxStagger / Math.max(1, this.workers.length - 1)))
520+
: 0
521+
515522
for (const worker of this.workers) {
516523
const workerThread = createWorker(worker, this.isPoolMode)
517524
this._listenWorkerEvents(workerThread)
518525
workerThreads.push(workerThread)
519526

520527
// Stagger worker creation to prevent CPU spikes
521528
// from massive V8 isolate creation and naturally stagger browser init
522-
if (this.workers.length > 1 && staggerDelay > 0) {
523-
await new Promise(resolve => setTimeout(resolve, staggerDelay))
529+
if (this.workers.length > 1 && effectiveDelay > 0) {
530+
await new Promise(resolve => setTimeout(resolve, effectiveDelay))
524531
}
525532
}
526533

0 commit comments

Comments
 (0)