Skip to content

Commit

Permalink
Added test
Browse files Browse the repository at this point in the history
  • Loading branch information
cmaglie committed Jun 4, 2024
1 parent 4ac75f3 commit d7db0c8
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions process_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ package paths

import (
"context"
"runtime"
"testing"
"time"

Expand All @@ -54,3 +55,20 @@ func TestProcessWithinContext(t *testing.T) {
require.Less(t, time.Since(start), 500*time.Millisecond)
cancel()
}

func TestKillProcessGroupOnLinux(t *testing.T) {
if runtime.GOOS != "linux" {
t.Skip("skipping test on non-linux system")
}

p, err := NewProcess(nil, "bash", "-c", "sleep 5 ; echo -n 5")
require.NoError(t, err)
start := time.Now()
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()

_, _, err = p.RunAndCaptureOutput(ctx)
require.EqualError(t, err, "signal: killed")
// Assert that the process was killed within the timeout
require.Less(t, time.Since(start), 2*time.Second)
}

0 comments on commit d7db0c8

Please sign in to comment.