Skip to content

Commit

Permalink
Wait for IterStart and IterEnd events to be processed
Browse files Browse the repository at this point in the history
The browser module uses the IterStart and IterEnd events for browser
initialization and shutdown, so we need to wait for them to complete.
There is some concern that this might add some delay to the overall
iteration duration, and not just to the iterations where browsers
processes are managed, but it should be negligible overall. We should
run benchmarks after this change to confirm this.
  • Loading branch information
Ivan Mirić committed Jun 21, 2023
1 parent d275b22 commit a97bdd0
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions js/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -772,7 +772,13 @@ func (u *ActiveVU) RunOnce() error {
VUID: u.ID,
ScenarioName: u.scenarioName,
}
u.moduleVUImpl.events.local.Emit(&event.Event{Type: event.IterStart, Data: eventIterData})

waitEventCtx, waitEventCancel := context.WithTimeout(u.RunContext, 30*time.Minute)
defer waitEventCancel()
waitEventDone := u.moduleVUImpl.events.local.Emit(&event.Event{Type: event.IterStart, Data: eventIterData})
if err := waitEventDone(waitEventCtx); err != nil {
panic(fmt.Sprintf("error waiting for '%s' event processing to complete: %s", event.IterStart, err))
}

// Call the exported function.
_, isFullIteration, totalTime, err := u.runFn(ctx, true, fn, cancel, u.setupData)
Expand All @@ -786,7 +792,12 @@ func (u *ActiveVU) RunOnce() error {
}
eventIterData.Error = err
}
u.moduleVUImpl.events.local.Emit(&event.Event{Type: event.IterEnd, Data: eventIterData})
waitEventCtx, waitEventCancel = context.WithTimeout(u.RunContext, 30*time.Minute)
defer waitEventCancel()
waitEventDone = u.moduleVUImpl.events.local.Emit(&event.Event{Type: event.IterEnd, Data: eventIterData})
if err = waitEventDone(waitEventCtx); err != nil {
panic(fmt.Sprintf("error waiting for '%s' event processing to complete: %s", event.IterEnd, err))
}

// If MinIterationDuration is specified and the iteration wasn't canceled
// and was less than it, sleep for the remainder
Expand Down

0 comments on commit a97bdd0

Please sign in to comment.