fix(auth): harden diagnostic cleanup races

This commit is contained in:
2026-08-17 18:41:40 +02:00
parent af16464e68
commit d12b629420
7 changed files with 387 additions and 36 deletions
@@ -0,0 +1,89 @@
package compose
import (
"errors"
"testing"
)
func TestWindowsCancellationTreatsProcessReapedBeforeTreeTerminationAsSuccess(t *testing.T) {
done := make(chan error, 1)
done <- nil
treeCalls := 0
directCalls := 0
err := terminateWindowsProcess(done, func() error {
treeCalls++
return errors.New("tree termination should not run")
}, func() error {
directCalls++
return errors.New("direct termination should not run")
}, 0)
if err != nil {
t.Fatalf("terminateWindowsProcess() error = %v, want nil", err)
}
if treeCalls != 0 || directCalls != 0 {
t.Fatalf("termination calls = tree:%d direct:%d, want none", treeCalls, directCalls)
}
}
func TestWindowsCancellationTreatsProcessReapedAfterTreeTerminationAsSuccess(t *testing.T) {
done := make(chan error, 1)
directCalls := 0
err := terminateWindowsProcess(done, func() error {
done <- nil
return ErrProcessReap
}, func() error {
directCalls++
return errors.New("direct termination should not run")
}, 0)
if err != nil {
t.Fatalf("terminateWindowsProcess() error = %v, want nil", err)
}
if directCalls != 0 {
t.Fatalf("direct termination calls = %d, want 0", directCalls)
}
}
func TestWindowsCancellationTreatsProcessReapedAfterDirectTerminationAsSuccess(t *testing.T) {
done := make(chan error, 1)
directCalls := 0
err := terminateWindowsProcess(done, func() error {
return ErrProcessReap
}, func() error {
directCalls++
done <- nil
return ErrProcessReap
}, 0)
if err != nil {
t.Fatalf("terminateWindowsProcess() error = %v, want nil", err)
}
if directCalls != 1 {
t.Fatalf("direct termination calls = %d, want 1", directCalls)
}
}
func TestWindowsCancellationReportsReapFailureWhenProcessSurvives(t *testing.T) {
done := make(chan error)
treeCalls := 0
directCalls := 0
err := terminateWindowsProcess(done, func() error {
treeCalls++
return ErrProcessReap
}, func() error {
directCalls++
return ErrProcessReap
}, 0)
if !errors.Is(err, ErrProcessReap) {
t.Fatalf("terminateWindowsProcess() error = %v, want ErrProcessReap", err)
}
if treeCalls != 1 || directCalls != 1 {
t.Fatalf("termination calls = tree:%d direct:%d, want one each", treeCalls, directCalls)
}
}