github.1git.de/docker/cli@v26.1.3+incompatible/cli/command/container/signals_test.go (about) 1 package container 2 3 import ( 4 "context" 5 "os" 6 "testing" 7 "time" 8 9 "github.com/moby/sys/signal" 10 ) 11 12 func TestForwardSignals(t *testing.T) { 13 ctx, cancel := context.WithCancel(context.Background()) 14 defer cancel() 15 16 called := make(chan struct{}) 17 apiClient := &fakeClient{containerKillFunc: func(ctx context.Context, container, signal string) error { 18 close(called) 19 return nil 20 }} 21 22 sigc := make(chan os.Signal) 23 defer close(sigc) 24 25 go ForwardAllSignals(ctx, apiClient, t.Name(), sigc) 26 27 timer := time.NewTimer(30 * time.Second) 28 defer timer.Stop() 29 30 select { 31 case <-timer.C: 32 t.Fatal("timeout waiting to send signal") 33 case sigc <- signal.SignalMap["TERM"]: 34 } 35 if !timer.Stop() { 36 <-timer.C 37 } 38 timer.Reset(30 * time.Second) 39 40 select { 41 case <-called: 42 case <-timer.C: 43 t.Fatal("timeout waiting for signal to be processed") 44 } 45 }