@@ -10,6 +10,23 @@ import (
1010 "github.com/replicate/cog-runtime/internal/server"
1111)
1212
13+ func TestShutdownByServerSigInt (t * testing.T ) {
14+ if * legacyCog {
15+ // Compat: legacy Cog doesn't handle SIGINT properly without a TTY
16+ t .SkipNow ()
17+ }
18+ ct := NewCogTest (t , "sleep" )
19+ assert .NoError (t , ct .Start ())
20+
21+ hc := ct .WaitForSetup ()
22+ assert .Equal (t , server .StatusReady .String (), hc .Status )
23+ assert .Equal (t , server .SetupSucceeded , hc .Setup .Status )
24+
25+ must .Do (syscall .Kill (ct .ServerPid (), syscall .SIGINT ))
26+ assert .NoError (t , ct .Cleanup ())
27+ assert .Equal (t , 0 , ct .cmd .ProcessState .ExitCode ())
28+ }
29+
1330func TestShutdownByServerSigTerm (t * testing.T ) {
1431 ct := NewCogTest (t , "sleep" )
1532 assert .NoError (t , ct .Start ())
@@ -32,11 +49,18 @@ func TestShutdownIgnoreSignal(t *testing.T) {
3249 assert .Equal (t , server .StatusReady .String (), hc .Status )
3350 assert .Equal (t , server .SetupSucceeded , hc .Setup .Status )
3451
52+ // Ignore SIGTERM
3553 must .Do (syscall .Kill (ct .ServerPid (), syscall .SIGTERM ))
3654 assert .Nil (t , ct .cmd .ProcessState )
3755 assert .Equal (t , server .StatusReady .String (), ct .HealthCheck ().Status )
3856
39- ct .Shutdown ()
57+ if * legacyCog {
58+ // Compat: legacy Cog doesn't handle SIGINT properly without a TTY
59+ ct .Shutdown ()
60+ } else {
61+ // Handle SIGINT
62+ must .Do (syscall .Kill (ct .ServerPid (), syscall .SIGINT ))
63+ }
4064 assert .NoError (t , ct .Cleanup ())
4165 assert .Equal (t , 0 , ct .cmd .ProcessState .ExitCode ())
4266}
0 commit comments