Skip to content

Commit ca90bea

Browse files
committed
Fix tests
1 parent 03ffe0b commit ca90bea

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

modules/process/manager_test.go

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package process
22

33
import (
4+
"context"
45
"os/exec"
56
"testing"
67
"time"
@@ -11,20 +12,35 @@ import (
1112
func TestManager_Add(t *testing.T) {
1213
pm := Manager{Processes: make(map[int64]*Process)}
1314

14-
pid := pm.Add("foo", exec.Command("foo"))
15+
pid := pm.Add("foo", exec.Command("foo"), nil)
1516
assert.Equal(t, int64(1), pid, "expected to get pid 1 got %d", pid)
1617

17-
pid = pm.Add("bar", exec.Command("bar"))
18+
pid = pm.Add("bar", exec.Command("bar"), nil)
1819
assert.Equal(t, int64(2), pid, "expected to get pid 2 got %d", pid)
1920
}
2021

22+
func TestManager_Cancel(t *testing.T) {
23+
pm := Manager{Processes: make(map[int64]*Process)}
24+
25+
ctx, cancel := context.WithCancel(context.Background())
26+
pid := pm.Add("foo", exec.Command("foo"), cancel)
27+
28+
pm.Cancel(pid)
29+
30+
select {
31+
case <-ctx.Done():
32+
default:
33+
assert.Fail(t, "Cancel should cancel the provided context")
34+
}
35+
}
36+
2137
func TestManager_Remove(t *testing.T) {
2238
pm := Manager{Processes: make(map[int64]*Process)}
2339

24-
pid1 := pm.Add("foo", exec.Command("foo"))
40+
pid1 := pm.Add("foo", exec.Command("foo"), nil)
2541
assert.Equal(t, int64(1), pid1, "expected to get pid 1 got %d", pid1)
2642

27-
pid2 := pm.Add("bar", exec.Command("bar"))
43+
pid2 := pm.Add("bar", exec.Command("bar"), nil)
2844
assert.Equal(t, int64(2), pid2, "expected to get pid 2 got %d", pid2)
2945

3046
pm.Remove(pid2)

0 commit comments

Comments
 (0)