-
Notifications
You must be signed in to change notification settings - Fork 10
/
immo_test.go
106 lines (86 loc) · 2.76 KB
/
immo_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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package main
import (
"fmt"
"os"
"strconv"
"testing"
"time"
cv "github.com/glycerine/goconvey/convey"
)
func TestImmolateAllWorkers(t *testing.T) {
cv.Convey("When we tell the server 'goq immolateworkers', then the server should request all workers shut themselves (and any jobs they are running) down.", t, func() {
cv.Convey("and the works should in fact ack this and shutdown.", func() {
pid := os.Getpid()
var err error
remote := false
// *** universal test cfg setup
skipbye := false
cfg := NewTestConfig(t)
defer cfg.ByeTestConfig(&skipbye)
// *** end universal test setup
cfg.DebugMode = true // reply to badsig packets
jobserv, jobservPid := HelperNewJobServ(cfg, remote)
time.Sleep(time.Second)
defer CleanupServer(cfg, jobservPid, jobserv, remote, nil)
defer CleanupOutdir(cfg)
nwork := 10
wks := make([]<-chan bool, nwork)
for i := 0; i < nwork; i++ {
w := HelperNewWorkerMonitored(cfg)
afterSend, afterReply := w.NR.MonitorSend, w.NR.MonitorRecv
wks[i] = afterReply
go func(w *Worker) {
w.DoOneJob() // _, err = w.DoOneJob() // makes a data race on err.
w.Destroy() // -race reports error here. Bug: http://code.google.com/p/go/issues/detail?id=8053
}(w)
<-afterSend
}
// We should see nwork workers
iww := 0
for i := 0; i < 3; i++ { // try for up to 3 seconds
snapmap := HelperSnapmap(cfg)
ww, ok := snapmap["waitingWorkers"]
if !ok {
panic(fmt.Sprintf("server stat must include waitingWorkers"))
}
iww, err = strconv.Atoi(ww)
if err != nil {
panic(err)
}
fmt.Printf("\n We should see %d waiting workers now, and we see: %d. snapmap: %#v\n", nwork, iww, snapmap)
if iww == nwork {
break
}
time.Sleep(time.Second) // only getting 8 or 9 out of 10? racing with goq cental's awareness of worker
}
cv.So(iww, cv.ShouldEqual, nwork)
// now immo
sub, err := NewSubmitter(cfg, false)
if err != nil {
panic(err)
}
err = sub.SubmitImmoJob()
if err != nil {
fmt.Printf("[pid %d] error while submitting ImmolateWorkers command to server '%s': %s\n", pid, cfg.JservAddr(), err)
os.Exit(1)
}
fmt.Printf("[pid %d] immolate workers command submitted to server '%s':\n", pid, cfg.JservAddr())
// wait for all workers to receive replies
for i := 0; i < nwork; i++ {
<-wks[i]
}
// check snap again
snapmap2 := HelperSnapmap(cfg)
ww2, ok := snapmap2["waitingWorkers"]
if !ok {
panic(fmt.Sprintf("server stat must include waitingWorkers"))
}
iww2, err := strconv.Atoi(ww2)
if err != nil {
panic(err)
}
fmt.Printf("\n We should see 0 waiting workers now, and we see: %d. snapmap2: %#v\n", iww2, snapmap2)
cv.So(iww2, cv.ShouldEqual, 0)
})
})
}