-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: kill hook when the command is stuck (#2469)
- Loading branch information
Showing
4 changed files
with
100 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package cmd | ||
|
||
import ( | ||
"runtime" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func Test_launchHook_errors(t *testing.T) { | ||
if runtime.GOOS == "windows" { | ||
t.Skip("skipping test on Windows") | ||
} | ||
|
||
testCases := []struct { | ||
desc string | ||
hook string | ||
timeout time.Duration | ||
expected string | ||
}{ | ||
{ | ||
desc: "kill the hook", | ||
hook: "sleep 5", | ||
timeout: 1 * time.Second, | ||
expected: "hook timed out", | ||
}, | ||
{ | ||
desc: "context timeout on Start", | ||
hook: "echo foo", | ||
timeout: 1 * time.Nanosecond, | ||
expected: "start command: context deadline exceeded", | ||
}, | ||
{ | ||
desc: "multiple short sleeps", | ||
hook: "./testdata/sleepy.sh", | ||
timeout: 1 * time.Second, | ||
expected: "hook timed out", | ||
}, | ||
{ | ||
desc: "long sleep", | ||
hook: "./testdata/sleeping_beauty.sh", | ||
timeout: 1 * time.Second, | ||
expected: "hook timed out", | ||
}, | ||
} | ||
|
||
for _, test := range testCases { | ||
t.Run(test.desc, func(t *testing.T) { | ||
t.Parallel() | ||
|
||
err := launchHook(test.hook, test.timeout, map[string]string{}) | ||
require.EqualError(t, err, test.expected) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/bash -e | ||
|
||
sleep 50 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/bin/bash -e | ||
|
||
for i in `seq 1 10` | ||
do | ||
echo $i | ||
sleep 0.2 | ||
done |