Preserve validation cancellation during reader shutdown
This commit is contained in:
@@ -7,7 +7,9 @@ import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"syscall"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
@@ -93,6 +95,55 @@ exec sleep 60`)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRunPreservesCancellationDuringReaderShutdown(t *testing.T) {
|
||||
repository := newTreeRepository(t)
|
||||
writeTreeFile(t, repository, "go.mod", []byte("module fixture.example/app\n\ngo 1.25.0\n"))
|
||||
writeTreeFile(t, repository, "main.go", []byte("package app\n\nconst value = 1\n"))
|
||||
commit := commitCandidateTree(t, repository)
|
||||
ready := filepath.Join(t.TempDir(), "shutdown-ready")
|
||||
installLifecycleTools(t, `while IFS= read -r object; do
|
||||
size=$("$RELEASEKIT_REAL_GIT" -C "$PWD" cat-file -s "$object")
|
||||
printf '%s blob %s\n' "$object" "$size"
|
||||
"$RELEASEKIT_REAL_GIT" -C "$PWD" cat-file blob "$object"
|
||||
printf '\n'
|
||||
done
|
||||
printf '%s\n' "$$" > "$RELEASEKIT_GIT_READER_READY"
|
||||
exec sleep 60`)
|
||||
t.Setenv("RELEASEKIT_GIT_READER_READY", ready)
|
||||
ctx, cancel := context.WithCancel(t.Context())
|
||||
defer cancel()
|
||||
result := make(chan error, 1)
|
||||
go func() { result <- Run(ctx, lifecycleRequest(repository, commit)) }()
|
||||
waitForLifecycleFile(t, ready)
|
||||
pidBytes, err := os.ReadFile(ready)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
pid, err := strconv.Atoi(strings.TrimSpace(string(pidBytes)))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
child, err := os.FindProcess(pid)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
cancel()
|
||||
select {
|
||||
case err := <-result:
|
||||
var failure *Failure
|
||||
if !errors.As(err, &failure) || failure.Check != GoFormat || !errors.Is(err, context.Canceled) {
|
||||
t.Fatalf("Run() error = %v, want GoFormat cancellation cause", err)
|
||||
}
|
||||
if err := child.Signal(syscall.Signal(0)); !errors.Is(err, syscall.ESRCH) && !errors.Is(err, os.ErrProcessDone) {
|
||||
t.Fatalf("child signal after Run() = %v, want reaped child", err)
|
||||
}
|
||||
case <-time.After(5 * time.Second):
|
||||
_ = child.Kill()
|
||||
<-result
|
||||
t.Fatal("Run() did not return after cancellation during reader shutdown")
|
||||
}
|
||||
}
|
||||
|
||||
func lifecycleRequest(repository, commit string) Request {
|
||||
return Request{
|
||||
RepositoryDir: repository,
|
||||
|
||||
Reference in New Issue
Block a user