MCPcopy Create free account
hub / github.com/buke/quickjs-go / TestModuleBuilder_RuntimeClosePanic_Minimal

Function TestModuleBuilder_RuntimeClosePanic_Minimal

module_test.go:726–764  ·  view source on GitHub ↗

============================================================================= MINIMAL REPRO TEST (ISSUE #688) =============================================================================

(t *testing.T)

Source from the content-addressed store, hash-verified

724// =============================================================================
725
726func 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 := `
752import * as testmodule from "testmodule";
753
754testmodule.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}

Callers

nothing calls this directly

Calls 15

CloseMethod · 0.95
NewContextMethod · 0.95
CloseMethod · 0.95
NewFunctionMethod · 0.95
NewUndefinedMethod · 0.95
ExportMethod · 0.95
BuildMethod · 0.95
EvalMethod · 0.95
ExceptionMethod · 0.95
NewRuntimeFunction · 0.85
WithModuleImportFunction · 0.85
NewModuleBuilderFunction · 0.85

Tested by

no test coverage detected