From a97bdd057ec743b93e200e5773ec8bb0d1cb4de9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Miri=C4=87?= Date: Wed, 21 Jun 2023 12:40:44 +0200 Subject: [PATCH] Wait for IterStart and IterEnd events to be processed 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. --- js/runner.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/js/runner.go b/js/runner.go index 382e3b7f4d97..9f727d3d0c50 100644 --- a/js/runner.go +++ b/js/runner.go @@ -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) @@ -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