diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e960dd0..db950bc 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -29,7 +29,7 @@ jobs: # Star* module's pipeline. Pinned to a commit SHA for supply-chain safety; # bump the pin when meta's workflow changes (Dependabot github-actions can # automate this). - uses: 1set/meta/.github/workflows/go-ci.yml@23f088bcd6dce16c93e0056d7b70b4f4434208e8 + uses: 1set/meta/.github/workflows/go-ci.yml@6b334e6a2762acaeefcea9fc7d3e86964e9246be with: go-floor: "1.20" doc-coverage: true diff --git a/example_test.go b/example_test.go index c095c0a..b8e67e5 100644 --- a/example_test.go +++ b/example_test.go @@ -8,6 +8,7 @@ import ( "net/http/httptest" "os" "path/filepath" + "runtime" "strings" "sync" "sync/atomic" @@ -2626,19 +2627,38 @@ func TestNestedBeginHonorsTimeout(t *testing.T) { } begin := beginV.(*starlark.Builtin) th := &starlark.Thread{} // Background context, like a default starlet Run - if _, err := starlark.Call(th, begin, nil, nil); err != nil { - t.Fatalf("first begin: %v", err) // holds the sole connection + first, err := starlark.Call(th, begin, nil, nil) + if err != nil { + t.Fatalf("first begin: %v", err) } + defer func() { + rollback, err := first.(starlark.HasAttrs).Attr("rollback") + if err != nil { + t.Errorf("rollback attr: %v", err) + return + } + if _, err := starlark.Call(th, rollback.(*starlark.Builtin), nil, nil); err != nil { + t.Errorf("rollback first transaction: %v", err) + } + }() + // An abandoned transaction is finalized and releases its connection. Keep + // this handle live while the second begin waits, and force a collection so + // the assertion does not depend on when the runtime happens to run GC. + runtime.GC() + done := make(chan error, 1) go func() { _, e := starlark.Call(th, begin, nil, nil); done <- e }() select { case e := <-done: if e == nil { t.Error("second begin unexpectedly succeeded on a single-connection DB") + } else if !strings.Contains(e.Error(), context.DeadlineExceeded.Error()) { + t.Errorf("second begin: %v, want the per-operation deadline", e) } case <-time.After(5 * time.Second): t.Error("second begin blocked >5s — the per-operation timeout was not honored") } + runtime.KeepAlive(first) } // raceTestRun uniquifies registered-function names across test invocations (the