added test files

This commit is contained in:
KS Jannette
2026-05-19 03:49:03 -04:00
parent 749d544165
commit 700b7ad457
7 changed files with 292 additions and 11 deletions

View File

@@ -0,0 +1,38 @@
package os
import (
"context"
"os"
"syscall"
"testing"
"time"
"go.uber.org/zap"
)
func TestSignalListener_CancelsOnSIGTERM(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
canceled := make(chan struct{})
go func() {
<-ctx.Done()
close(canceled)
}()
SignalListener(zap.NewNop(), cancel)
proc, err := os.FindProcess(os.Getpid())
if err != nil {
t.Fatalf("FindProcess: %v", err)
}
if err := proc.Signal(syscall.SIGTERM); err != nil {
t.Fatalf("Signal SIGTERM: %v", err)
}
select {
case <-canceled:
case <-time.After(2 * time.Second):
t.Fatal("context was not canceled after SIGTERM")
}
}