Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/app/launcher/cmd/launcher/binary.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
32 changes: 25 additions & 7 deletions pkg/app/launcher/cmd/launcher/binary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
})
}
}