moby/pkg/signal/signal_linux_test.go
Sebastiaan van Stijn 41cf01fa93
pkg/signal.CatchAll: ignore SIGURG on Linux
Do not handle SIGURG on Linux, as in go1.14+, the go runtime issues
SIGURG as an interrupt to support preemptable system calls on Linux.

This issue was caught in TestCatchAll, which could fail when updating to Go 1.14 or above;

    === Failed
    === FAIL: pkg/signal TestCatchAll (0.01s)
        signal_linux_test.go:32: assertion failed: urgent I/O condition (string) != continued (string)
        signal_linux_test.go:32: assertion failed: continued (string) != hangup (string)
        signal_linux_test.go:32: assertion failed: hangup (string) != child exited (string)
        signal_linux_test.go:32: assertion failed: child exited (string) != illegal instruction (string)
        signal_linux_test.go:32: assertion failed: illegal instruction (string) != floating point exception (string)

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit b7ebf32ba3)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2021-05-20 10:11:39 +02:00

65 lines
1.4 KiB
Go

// +build darwin linux
package signal // import "github.com/docker/docker/pkg/signal"
import (
"os"
"syscall"
"testing"
"time"
"gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp"
)
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 {
if signal, ok := SignalMap[sigStr]; ok {
syscall.Kill(syscall.Getpid(), signal)
s := <-sigs
assert.Check(t, is.Equal(s.String(), signal.String()))
}
}
}
func TestCatchAllIgnoreSigUrg(t *testing.T) {
sigs := make(chan os.Signal, 1)
CatchAll(sigs)
defer StopCatch(sigs)
err := syscall.Kill(syscall.Getpid(), syscall.SIGURG)
assert.NilError(t, err)
timer := time.NewTimer(1 * time.Second)
defer timer.Stop()
select {
case <-timer.C:
case s := <-sigs:
t.Fatalf("expected no signals to be handled, but received %q", s.String())
}
}
func TestStopCatch(t *testing.T) {
signal := SignalMap["HUP"]
channel := make(chan os.Signal, 1)
CatchAll(channel)
syscall.Kill(syscall.Getpid(), signal)
signalString := <-channel
assert.Check(t, is.Equal(signalString.String(), signal.String()))
StopCatch(channel)
_, ok := <-channel
assert.Check(t, is.Equal(ok, false))
}