feat(auth): coordinate canonical projection publication

This commit is contained in:
User
2026-08-21 23:43:37 +02:00
parent 1e2c4e65c5
commit 903c0b4de5
10 changed files with 1272 additions and 8 deletions
@@ -3,6 +3,7 @@
package authprojection
import (
"context"
"errors"
"fmt"
"os"
@@ -11,10 +12,50 @@ import (
"sync"
"syscall"
"testing"
"time"
"golang.org/x/sys/unix"
)
func TestBeginContextReturnsWhenRuntimeFlockIsHeld(t *testing.T) {
spec := testSpec(t)
first, err := Begin(spec, nil, false)
if err != nil {
t.Fatal(err)
}
t.Cleanup(func() { _ = first.Close() })
contended := make(chan error, 1)
restore := setTestHooksForTest(testHooks{beforeFlock: func(fd int) {
if err := unix.Flock(fd, unix.LOCK_EX|unix.LOCK_NB); !errors.Is(err, unix.EWOULDBLOCK) {
contended <- fmt.Errorf("runtime lock contention = %v", err)
return
}
contended <- nil
}})
t.Cleanup(restore)
ctx, cancel := context.WithCancel(context.Background())
result := make(chan error, 1)
go func() {
transaction, err := BeginContext(ctx, spec, nil, false)
if err == nil {
err = transaction.Close()
}
result <- err
}()
if err := <-contended; err != nil {
t.Fatal(err)
}
cancel()
select {
case err := <-result:
if !errors.Is(err, context.Canceled) {
t.Fatalf("BeginContext() error = %v, want context cancellation", err)
}
case <-time.After(2 * time.Second):
t.Fatal("BeginContext() did not return after cancellation")
}
}
func testSpec(t *testing.T) Spec {
t.Helper()
root := t.TempDir()