11
"github.com/stretchr/testify/assert"
14
func TestGetManager(t *testing.T) {
23
func TestManager_AddContext(t *testing.T) {
24
pm := Manager{processMap: make(map[IDType]*process), next: 1}
26
ctx, cancel := context.WithCancel(context.Background())
29
p1Ctx, _, finished := pm.AddContext(ctx, "foo")
31
assert.NotEmpty(t, GetContext(p1Ctx).GetPID(), "expected to get non-empty pid")
33
p2Ctx, _, finished := pm.AddContext(p1Ctx, "bar")
36
assert.NotEmpty(t, GetContext(p2Ctx).GetPID(), "expected to get non-empty pid")
38
assert.NotEqual(t, GetContext(p1Ctx).GetPID(), GetContext(p2Ctx).GetPID(), "expected to get different pids %s == %s", GetContext(p2Ctx).GetPID(), GetContext(p1Ctx).GetPID())
39
assert.Equal(t, GetContext(p1Ctx).GetPID(), GetContext(p2Ctx).GetParent().GetPID(), "expected to get pid %s got %s", GetContext(p1Ctx).GetPID(), GetContext(p2Ctx).GetParent().GetPID())
42
func TestManager_Cancel(t *testing.T) {
43
pm := Manager{processMap: make(map[IDType]*process), next: 1}
45
ctx, _, finished := pm.AddContext(context.Background(), "foo")
48
pm.Cancel(GetPID(ctx))
53
assert.FailNow(t, "Cancel should cancel the provided context")
57
ctx, cancel, finished := pm.AddContext(context.Background(), "foo")
65
assert.FailNow(t, "Cancel should cancel the provided context")
70
func TestManager_Remove(t *testing.T) {
71
pm := Manager{processMap: make(map[IDType]*process), next: 1}
73
ctx, cancel := context.WithCancel(context.Background())
76
p1Ctx, _, finished := pm.AddContext(ctx, "foo")
78
assert.NotEmpty(t, GetContext(p1Ctx).GetPID(), "expected to have non-empty PID")
80
p2Ctx, _, finished := pm.AddContext(p1Ctx, "bar")
83
assert.NotEqual(t, GetContext(p1Ctx).GetPID(), GetContext(p2Ctx).GetPID(), "expected to get different pids got %s == %s", GetContext(p2Ctx).GetPID(), GetContext(p1Ctx).GetPID())
87
_, exists := pm.processMap[GetPID(p2Ctx)]
88
assert.False(t, exists, "PID %d is in the list but shouldn't", GetPID(p2Ctx))
91
func TestExecTimeoutNever(t *testing.T) {
94
for i := 1; i < maxLoops; i++ {
95
_, stderr, err := GetManager().ExecTimeout(5*time.Second, "ExecTimeout", "git", "--version")
97
t.Fatalf("git --version: %v(%s)", err, stderr)
102
func TestExecTimeoutAlways(t *testing.T) {
104
for i := 1; i < maxLoops; i++ {
105
_, stderr, err := GetManager().ExecTimeout(100*time.Microsecond, "ExecTimeout", "sleep", "5")
108
t.Fatalf("sleep 5 secs: %v(%s)", err, stderr)