Skip to content

Commit d7db0c8

Browse files
committed
Added test
1 parent 4ac75f3 commit d7db0c8

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

Diff for: process_test.go

+18
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ package paths
3131

3232
import (
3333
"context"
34+
"runtime"
3435
"testing"
3536
"time"
3637

@@ -54,3 +55,20 @@ func TestProcessWithinContext(t *testing.T) {
5455
require.Less(t, time.Since(start), 500*time.Millisecond)
5556
cancel()
5657
}
58+
59+
func TestKillProcessGroupOnLinux(t *testing.T) {
60+
if runtime.GOOS != "linux" {
61+
t.Skip("skipping test on non-linux system")
62+
}
63+
64+
p, err := NewProcess(nil, "bash", "-c", "sleep 5 ; echo -n 5")
65+
require.NoError(t, err)
66+
start := time.Now()
67+
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
68+
defer cancel()
69+
70+
_, _, err = p.RunAndCaptureOutput(ctx)
71+
require.EqualError(t, err, "signal: killed")
72+
// Assert that the process was killed within the timeout
73+
require.Less(t, time.Since(start), 2*time.Second)
74+
}

0 commit comments

Comments
 (0)