Skip to content

Commit 9fd7158

Browse files
committed
shorten tests
1 parent 45606f8 commit 9fd7158

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

timeout_test.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func TestRunSimple(t *testing.T) {
7373
{
7474
name: "timed out",
7575
cmd: exec.Command(shellcmd, shellflag, fmt.Sprintf("%s -sleep 3", stubCmd)),
76-
duration: 1 * time.Second,
76+
duration: 100 * time.Millisecond,
7777
signal: os.Interrupt,
7878
expectedExit: 124,
7979
},
@@ -82,29 +82,29 @@ func TestRunSimple(t *testing.T) {
8282
cmd: exec.Command(shellcmd, shellflag, fmt.Sprintf("%s -sleep 3", stubCmd)),
8383
duration: time.Duration(0.1 * float64(time.Second)),
8484
preserveStatus: true,
85-
expectedExit: 128 + 15,
85+
expectedExit: 128 + int(syscall.SIGTERM),
8686
skipOnWin: true,
8787
},
8888
{
8989
name: "preserve status (signal trapd)",
9090
cmd: exec.Command(stubCmd, "-trap", "SIGTERM", "-trap-exit", "23", "-sleep", "3"),
91-
duration: 1 * time.Second,
91+
duration: 100 * time.Millisecond,
9292
preserveStatus: true,
9393
expectedExit: 23,
9494
skipOnWin: true,
9595
},
9696
{
9797
name: "kill after",
9898
cmd: exec.Command(stubCmd, "-trap", "SIGTERM", "-sleep", "3"),
99-
duration: 1 * time.Second,
100-
killAfter: 1 * time.Second,
99+
duration: 100 * time.Millisecond,
100+
killAfter: 100 * time.Microsecond,
101101
signal: syscall.SIGTERM,
102102
expectedExit: exitKilled,
103103
},
104104
{
105105
name: "trap sigterm but exited before kill after",
106-
cmd: exec.Command(stubCmd, "-trap", "SIGTERM", "-sleep", "3"),
107-
duration: 1 * time.Second,
106+
cmd: exec.Command(stubCmd, "-trap", "SIGTERM", "-sleep", "0.8"),
107+
duration: 100 * time.Millisecond,
108108
killAfter: 5 * time.Second,
109109
signal: syscall.SIGTERM,
110110
preserveStatus: true,

timeout_unix_test.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111

1212
func TestRunSimple_withStop(t *testing.T) {
1313
tio := &Timeout{
14-
Duration: 2 * time.Second,
14+
Duration: 100 * time.Microsecond,
1515
KillAfter: 1 * time.Second,
1616
Cmd: exec.Command(shellcmd, shellflag, "sleep 10"),
1717
}
@@ -22,7 +22,7 @@ func TestRunSimple_withStop(t *testing.T) {
2222
tio.Cmd.Process.Signal(syscall.SIGSTOP)
2323
st := <-ch
2424

25-
expect := 128 + 15
25+
expect := 128 + int(syscall.SIGTERM)
2626
if st.Code != expect {
2727
t.Errorf("exit code invalid. out: %d, expect: %d", st.Code, expect)
2828
}
@@ -43,16 +43,16 @@ func TestRunCommand_signaled(t *testing.T) {
4343
},
4444
{
4545
name: "termed by sigterm",
46-
cmd: exec.Command("sleep", "3"),
47-
exit: 143,
46+
cmd: exec.Command("sleep", "1"),
47+
exit: 128 + int(syscall.SIGTERM),
4848
signaled: true,
4949
},
5050
}
5151

5252
for _, tc := range testCases {
5353
t.Run(tc.name, func(t *testing.T) {
5454
tio := &Timeout{
55-
Duration: time.Second,
55+
Duration: 100 * time.Millisecond,
5656
KillAfter: 3 * time.Second,
5757
Cmd: tc.cmd,
5858
}

0 commit comments

Comments
 (0)