diff --git a/pkg/app/launcher/cmd/launcher/binary.go b/pkg/app/launcher/cmd/launcher/binary.go index b94f3dd47b..d31ff9af7a 100644 --- a/pkg/app/launcher/cmd/launcher/binary.go +++ b/pkg/app/launcher/cmd/launcher/binary.go @@ -50,7 +50,7 @@ func (c *command) GracefulStop(period time.Duration) error { select { case <-timer.C: c.cmd.Process.Kill() - return nil + return <-c.stoppedCh case err := <-c.stoppedCh: return err } diff --git a/pkg/app/launcher/cmd/launcher/binary_test.go b/pkg/app/launcher/cmd/launcher/binary_test.go index 4e66743137..045a682a96 100644 --- a/pkg/app/launcher/cmd/launcher/binary_test.go +++ b/pkg/app/launcher/cmd/launcher/binary_test.go @@ -22,12 +22,30 @@ import ( "github.com/stretchr/testify/require" ) -func TestCommand(t *testing.T) { - cmd, err := runBinary("sh", []string{"sleep", "1m"}) - require.NoError(t, err) - require.NotNil(t, cmd) +func TestGracefulStopCommand(t *testing.T) { + testcases := []struct { + name string + stopAfter time.Duration + }{ + { + name: "graceful stop after very short time", + stopAfter: time.Nanosecond, + }, + { + name: "graceful stop after second", + stopAfter: time.Second, + }, + } - assert.True(t, cmd.IsRunning()) - cmd.GracefulStop(time.Millisecond) - assert.False(t, cmd.IsRunning()) + for _, tc := range testcases { + t.Run(tc.name, func(t *testing.T) { + cmd, err := runBinary("sh", []string{"sleep", "1m"}) + require.NoError(t, err) + require.NotNil(t, cmd) + + assert.True(t, cmd.IsRunning()) + cmd.GracefulStop(tc.stopAfter) + assert.False(t, cmd.IsRunning()) + }) + } }