============================================================================= MINIMAL REPRO TEST (ISSUE #688) =============================================================================
(t *testing.T)
| 724 | // ============================================================================= |
| 725 | |
| 726 | func TestModuleBuilder_RuntimeClosePanic_Minimal(t *testing.T) { |
| 727 | // Regression stress test for issue #688. Historically, closing the runtime after |
| 728 | // importing a native module could randomly trigger a QuickJS abort in rt.Close(). |
| 729 | // |
| 730 | // If QuickJS triggers an assertion/abort during rt.Close(), `go test` will terminate. |
| 731 | const attempts = 50 |
| 732 | for i := 1; i <= attempts; i++ { |
| 733 | t.Run(fmt.Sprintf("attempt_%d", i), func(t *testing.T) { |
| 734 | // Use an inner scope so defers run per-iteration. |
| 735 | rt := NewRuntime(WithModuleImport(true)) |
| 736 | defer rt.Close() |
| 737 | |
| 738 | ctx := rt.NewContext() |
| 739 | defer ctx.Close() |
| 740 | |
| 741 | fooFunc := ctx.NewFunction(func(ctx *Context, this *Value, args []*Value) *Value { |
| 742 | fmt.Println("foo") |
| 743 | return ctx.NewUndefined() |
| 744 | }) |
| 745 | defer fooFunc.Free() |
| 746 | |
| 747 | module := NewModuleBuilder("testmodule") |
| 748 | module.Export("foo", fooFunc) |
| 749 | require.NoError(t, module.Build(ctx)) |
| 750 | |
| 751 | script := ` |
| 752 | import * as testmodule from "testmodule"; |
| 753 | |
| 754 | testmodule.foo(); |
| 755 | ` |
| 756 | |
| 757 | result := ctx.Eval(script, EvalFlagStrict(true), EvalAwait(true)) |
| 758 | defer result.Free() |
| 759 | if result.IsException() { |
| 760 | panic(ctx.Exception()) |
| 761 | } |
| 762 | }) |
| 763 | } |
| 764 | } |
nothing calls this directly
no test coverage detected