-
Notifications
You must be signed in to change notification settings - Fork 0
/
triggers_windows_test.go
67 lines (57 loc) · 2.12 KB
/
triggers_windows_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package jasper
import (
"context"
"syscall"
"testing"
"github.com/tychoish/fun/assert"
"github.com/tychoish/fun/assert/check"
"github.com/tychoish/jasper/options"
"github.com/tychoish/jasper/testutil"
)
func TestCleanTerminationSignalTrigger(t *testing.T) {
for procName, makeProc := range map[string]ProcessConstructor{
"Basic": newBasicProcess,
"Blocking": newBlockingProcess,
} {
t.Run(procName, func(t *testing.T) {
for testName, testCase := range map[string]func(context.Context, *options.Create, ProcessConstructor){
"CleanTerminationRunsForSIGTERM": func(ctx context.Context, opts *options.Create, makep ProcessConstructor) {
proc, err := makep(ctx, opts)
assert.NotError(t, err)
trigger := makeCleanTerminationSignalTrigger()
check.True(t, trigger(proc.Info(ctx), syscall.SIGTERM))
exitCode, err := proc.Wait(ctx)
check.NotError(t, err)
check.Zero(t, exitCode)
check.True(t, !proc.Running(ctx))
// Subsequent executions of trigger should fail.
check.True(t, !trigger(proc.Info(ctx), syscall.SIGTERM))
},
"CleanTerminationIgnoresNonSIGTERM": func(ctx context.Context, opts *options.Create, makep ProcessConstructor) {
proc, err := makep(ctx, opts)
assert.NotError(t, err)
trigger := makeCleanTerminationSignalTrigger()
check.True(t, !trigger(proc.Info(ctx), syscall.SIGHUP))
check.True(t, proc.Running(ctx))
check.NotError(t, proc.Signal(ctx, syscall.SIGKILL))
},
"CleanTerminationFailsForExitedProcess": func(ctx context.Context, opts *options.Create, makep ProcessConstructor) {
opts = testutil.TrueCreateOpts()
proc, err := makep(ctx, opts)
assert.NotError(t, err)
exitCode, err := proc.Wait(ctx)
check.NotError(t, err)
check.Zero(t, exitCode)
trigger := makeCleanTerminationSignalTrigger()
check.True(t, !trigger(proc.Info(ctx), syscall.SIGTERM))
},
} {
t.Run(testName, func(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), testutil.TestTimeout)
defer cancel()
testCase(ctx, testutil.SleepCreateOpts(1), makeProc)
})
}
})
}
}