From a8a49200fc7f1ec98010a3861a66b790e49ecc5c Mon Sep 17 00:00:00 2001 From: Dylan Thacker-Smith Date: Mon, 22 Nov 2021 09:45:00 -0500 Subject: [PATCH] Fix flaky TestIsolateTermination test failure (#236) --- isolate_test.go | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/isolate_test.go b/isolate_test.go index c06f4397..a6cca8e5 100644 --- a/isolate_test.go +++ b/isolate_test.go @@ -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() @@ -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() @@ -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") {