From c66c1be338dde01a1c3f5f36a4e28692573ac017 Mon Sep 17 00:00:00 2001 From: Mihail Stoykov <312246+mstoykov@users.noreply.github.com> Date: Tue, 11 Jul 2023 10:33:19 +0300 Subject: [PATCH] Fix race in js/promises package's tests (#3183) The original tests were interacting with the runtime and the event loop from outside the eventloop. --- js/promises/promises_test.go | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/js/promises/promises_test.go b/js/promises/promises_test.go index 7ba32d8691e..e0cc4281d5e 100644 --- a/js/promises/promises_test.go +++ b/js/promises/promises_test.go @@ -15,13 +15,8 @@ func TestNew(t *testing.T) { t.Parallel() runtime := modulestest.NewRuntime(t) - promise, resolve, _ := New(runtime.VU) - - go func() { - resolve("resolved") - }() - err := runtime.EventLoop.Start(func() error { + promise, resolve, _ := New(runtime.VU) err := runtime.VU.Runtime().Set("promise", promise) require.NoError(t, err) @@ -32,6 +27,9 @@ func TestNew(t *testing.T) { err => { throw "unexpected error: " + err }, ) `) + go func() { + resolve("resolved") + }() return err }) @@ -43,13 +41,8 @@ func TestNew(t *testing.T) { t.Parallel() runtime := modulestest.NewRuntime(t) - promise, _, reject := New(runtime.VU) - - go func() { - reject("rejected") - }() - err := runtime.EventLoop.Start(func() error { + promise, _, reject := New(runtime.VU) err := runtime.VU.Runtime().Set("promise", promise) require.NoError(t, err) @@ -60,6 +53,9 @@ func TestNew(t *testing.T) { err => { if (err !== "rejected") { throw "unexpected error: " + err } }, ) `) + go func() { + reject("rejected") + }() return err })