Skip to content

Commit

Permalink
Fix race in js/promises package's tests (#3183)
Browse files Browse the repository at this point in the history
The original tests were interacting with the runtime and the event loop
from outside the eventloop.
  • Loading branch information
mstoykov authored Jul 11, 2023
1 parent 373d185 commit c66c1be
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions js/promises/promises_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -32,6 +27,9 @@ func TestNew(t *testing.T) {
err => { throw "unexpected error: " + err },
)
`)
go func() {
resolve("resolved")
}()

return err
})
Expand All @@ -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)

Expand All @@ -60,6 +53,9 @@ func TestNew(t *testing.T) {
err => { if (err !== "rejected") { throw "unexpected error: " + err } },
)
`)
go func() {
reject("rejected")
}()

return err
})
Expand Down

0 comments on commit c66c1be

Please sign in to comment.