1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00
moby--moby/pkg/signal/signal_linux_test.go
Daniel Nephin 4f0d95fa6e Add canonical import comment
Signed-off-by: Daniel Nephin <dnephin@docker.com>
2018-02-05 16:51:57 -05:00

58 lines
1.2 KiB
Go

// +build darwin linux
package signal // import "github.com/docker/docker/pkg/signal"
import (
"os"
"syscall"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestCatchAll(t *testing.T) {
sigs := make(chan os.Signal, 1)
CatchAll(sigs)
defer StopCatch(sigs)
listOfSignals := map[string]string{
"CONT": syscall.SIGCONT.String(),
"HUP": syscall.SIGHUP.String(),
"CHLD": syscall.SIGCHLD.String(),
"ILL": syscall.SIGILL.String(),
"FPE": syscall.SIGFPE.String(),
"CLD": syscall.SIGCLD.String(),
}
for sigStr := range listOfSignals {
signal, ok := SignalMap[sigStr]
if ok {
go func() {
time.Sleep(1 * time.Millisecond)
syscall.Kill(syscall.Getpid(), signal)
}()
s := <-sigs
assert.EqualValues(t, s.String(), signal.String())
}
}
}
func TestStopCatch(t *testing.T) {
signal := SignalMap["HUP"]
channel := make(chan os.Signal, 1)
CatchAll(channel)
go func() {
time.Sleep(1 * time.Millisecond)
syscall.Kill(syscall.Getpid(), signal)
}()
signalString := <-channel
assert.EqualValues(t, signalString.String(), signal.String())
StopCatch(channel)
_, ok := <-channel
assert.EqualValues(t, ok, false)
}