forked from glycerine/goq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
immo_test.go
96 lines (77 loc) · 2.51 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
package main
import (
"fmt"
"os"
"strconv"
"testing"
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()
defer cfg.ByeTestConfig(&skipbye)
// *** end universal test setup
cfg.DebugMode = true // reply to badsig packets
jobserv, jobservPid := HelperNewJobServ(cfg, remote)
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.NS.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
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)
cv.So(iww, cv.ShouldEqual, nwork)
// now immo
sub, err := NewSubmitter(GenAddress(), 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)
})
})
}