Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 22 additions & 2 deletions example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"net/http/httptest"
"os"
"path/filepath"
"runtime"
"strings"
"sync"
"sync/atomic"
Expand Down Expand Up @@ -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
Expand Down
Loading