-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevent_windows_test.go
68 lines (55 loc) · 1.62 KB
/
event_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
68
package jasper
import (
"context"
"os"
"strconv"
"testing"
"time"
"github.com/tychoish/fun/assert"
"github.com/tychoish/fun/assert/check"
"github.com/tychoish/jasper/options"
)
const (
mongodStartupTime = 15 * time.Second
mongodShutdownEventPrefix = "Global\\Mongo_"
)
func TestMongodShutdownEvent(t *testing.T) {
for procName, makeProc := range map[string]ProcessConstructor{
"Basic": newBasicProcess,
"Blocking": newBlockingProcess,
} {
t.Run(procName, func(t *testing.T) {
if testing.Short() {
t.Skip("skipping mongod shutdown event tests in short mode")
}
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
var opts options.Create
dir, mongodPath := downloadMongoDB(t)
defer os.RemoveAll(dir)
optslist, dbPaths, err := setupMongods(1, mongodPath)
assert.NotError(t, err)
defer removeDBPaths(dbPaths)
assert.Equal(t, 1, len(optslist))
opts = optslist[0]
logger := &options.LoggerConfig{}
assert.NotError(t, logger.Set(&options.DefaultLoggerOptions{
Base: options.BaseOptions{
Format: options.LogFormatPlain,
},
}))
opts.Output.Loggers = []*options.LoggerConfig{logger}
proc, err := makeProc(ctx, &opts)
assert.NotError(t, err)
// Give mongod time to start up its signal processing thread.
time.Sleep(mongodStartupTime)
pid := proc.Info(ctx).PID
mongodShutdownEvent := mongodShutdownEventPrefix + strconv.Itoa(pid)
assert.NotError(t, SignalEvent(ctx, mongodShutdownEvent))
exitCode, err := proc.Wait(ctx)
check.NotError(t, err)
check.Zero(t, exitCode)
check.True(t, !proc.Running(ctx))
})
}
}