Skip to content

Commit

Permalink
Fix flaky TestIsolateTermination test failure (rogchap#236)
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanahsmith committed Nov 22, 2021
1 parent ef77cad commit a8a4920
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions isolate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@ import (
"math/rand"
"strings"
"testing"
"time"

v8 "rogchap.com/v8go"
)

func TestIsolateTermination(t *testing.T) {
func TestIsolateTerminateExecution(t *testing.T) {
t.Parallel()
iso := v8.NewIsolate()
defer iso.Dispose()
Expand All @@ -27,6 +26,9 @@ func TestIsolateTermination(t *testing.T) {
var terminating bool
fooFn := v8.NewFunctionTemplate(iso, func(info *v8.FunctionCallbackInfo) *v8.Value {
loop, _ := info.Args()[0].AsFunction()
go func() {
iso.TerminateExecution()
}()
loop.Call(v8.Undefined(iso))

terminating = iso.IsExecutionTerminating()
Expand All @@ -39,12 +41,6 @@ func TestIsolateTermination(t *testing.T) {
ctx := v8.NewContext(iso, global)
defer ctx.Close()

go func() {
// [RC] find a better way to know when a script has started execution
time.Sleep(time.Millisecond)
iso.TerminateExecution()
}()

script := `function loop() { while (true) { } }; foo(loop);`
_, e := ctx.RunScript(script, "forever.js")
if e == nil || !strings.HasPrefix(e.Error(), "ExecutionTerminated") {
Expand Down

0 comments on commit a8a4920

Please sign in to comment.