github.com/ssdev-go/moby@v17.12.1-ce-rc2+incompatible/pkg/signal/signal_linux_test.go (about) 1 // +build darwin linux 2 3 package signal 4 5 import ( 6 "os" 7 "syscall" 8 "testing" 9 "time" 10 11 "github.com/stretchr/testify/assert" 12 ) 13 14 func TestCatchAll(t *testing.T) { 15 sigs := make(chan os.Signal, 1) 16 CatchAll(sigs) 17 defer StopCatch(sigs) 18 19 listOfSignals := map[string]string{ 20 "CONT": syscall.SIGCONT.String(), 21 "HUP": syscall.SIGHUP.String(), 22 "CHLD": syscall.SIGCHLD.String(), 23 "ILL": syscall.SIGILL.String(), 24 "FPE": syscall.SIGFPE.String(), 25 "CLD": syscall.SIGCLD.String(), 26 } 27 28 for sigStr := range listOfSignals { 29 signal, ok := SignalMap[sigStr] 30 if ok { 31 go func() { 32 time.Sleep(1 * time.Millisecond) 33 syscall.Kill(syscall.Getpid(), signal) 34 }() 35 36 s := <-sigs 37 assert.EqualValues(t, s.String(), signal.String()) 38 } 39 40 } 41 } 42 43 func TestStopCatch(t *testing.T) { 44 signal := SignalMap["HUP"] 45 channel := make(chan os.Signal, 1) 46 CatchAll(channel) 47 go func() { 48 49 time.Sleep(1 * time.Millisecond) 50 syscall.Kill(syscall.Getpid(), signal) 51 }() 52 signalString := <-channel 53 assert.EqualValues(t, signalString.String(), signal.String()) 54 55 StopCatch(channel) 56 _, ok := <-channel 57 assert.EqualValues(t, ok, false) 58 }