Files
ThothII/tools/tht/internal/compose/process_termination_test.go
T

90 lines
2.2 KiB
Go

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)
}
}