Synchronize deadline regression with source inspection

This commit is contained in:
2026-11-01 21:56:13 +00:00
parent 66f5884ab4
commit fcd2e57887
3 changed files with 41 additions and 11 deletions

View File

@@ -14,6 +14,14 @@ import (
releasekit "go.maximumdirect.net/releasekit"
)
// inspectionDeadlineContext models deadline expiration at the readiness signal,
// so unrelated setup time cannot consume the source-inspection test's deadline.
type inspectionDeadlineContext struct{ context.Context }
func (ctx inspectionDeadlineContext) Err() error {
return context.Cause(ctx.Context)
}
func TestBuildSourceInspectionCancellation(t *testing.T) {
const source = `package main
import("fmt";"os";"go.maximumdirect.net/releasekit/buildinfo")
@@ -58,7 +66,9 @@ exec "$INSPECT_GIT" "$@"
var ctx context.Context
var cancel context.CancelFunc
if tc.deadline {
ctx, cancel = context.WithTimeout(context.Background(), 3*time.Second)
parent, expire := context.WithCancelCause(context.Background())
ctx = inspectionDeadlineContext{parent}
cancel = func() { expire(context.DeadlineExceeded) }
} else {
ctx, cancel = context.WithCancel(context.Background())
}
@@ -93,10 +103,13 @@ exec "$INSPECT_GIT" "$@"
case <-ticker.C:
}
}
if !tc.deadline {
cancel()
cancel()
var result outcome
select {
case result = <-done:
case <-timer.C:
t.Fatal("build did not stop after source inspection interruption")
}
result := <-done
want := context.Canceled
if tc.deadline {
want = context.DeadlineExceeded