-
Notifications
You must be signed in to change notification settings - Fork 10
/
cancel_test.go
98 lines (74 loc) · 2.68 KB
/
cancel_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
package main
import (
"fmt"
"strconv"
"testing"
cv "github.com/glycerine/goconvey/convey"
)
func TestCancelJobInProgress(t *testing.T) {
cv.Convey("When we ask workers to cancel one job or all jobs in progress,", t, func() {
cv.Convey("they should stay alive but kill their sheparded processes and report back to server.", func() {
//pid := os.Getpid()
var err error
remote := false
// *** universal test cfg setup
skipbye := false
cfg := NewTestConfig(t)
//cfg.SendTimeoutMsec = 5000
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)
// a job that will go forever unless cancelled
j := NewJob()
j.Cmd = "bin/forev.sh"
_, replyjob := HelperSubJobGetReply(j, cfg)
//vv("cancel-test: forev job started: Aboutjid: %d, replyjob: %s\n", replyjob.Aboutjid, replyjob)
// the forev job won't be successful, because it sleeps forever.
// start a (local inproc) worker to do that job
w := HelperNewWorkerMonitored(cfg)
w.AttemptOnlyOneJob()
// make sure worker gets the job before trying to cancel
vv("cancel test: about to wait for MonitorSend")
<-w.NR.MonitorSend
fmt.Printf("\n cancel-test got past MonitorSend\n")
<-w.NR.MonitorRecv
fmt.Printf("\n cancel-test got past MonitorRecv\n")
<-w.MonitorShepJobStart
fmt.Printf("\n cancel-test got past MonitorShepJobStart\n")
// send the cancel
sub, err := NewSubmitter(cfg, false)
if err != nil {
panic(err)
}
fmt.Printf("\n cancel-test got past NewSubmitter()\n")
err = sub.SubmitCancelJob(replyjob.Aboutjid)
if err != nil {
panic(err)
}
fmt.Printf("\n cancel-test got past SubmitCancelJob\n")
<-w.MonitorShepJobDone
fmt.Printf("\n cancel-test got past MonitorShepJobDone\n")
// At this point, there is still a race to get to the jobdone msg with .Cancelled sent
// back to the server before we query stats. So tell server to signal after first
// Cancelled job is received.
<-jobserv.FirstCancelDone // stuck here
fmt.Printf("\n cancel-test got past <-jobserv.FirstCancelDone\n")
// We should see nwork workers
snapmap := HelperSnapmap(cfg)
canned, ok := snapmap["cancelledJobCount"]
if !ok {
panic(fmt.Sprintf("server stat must include cancelledJobCount"))
}
ican, err := strconv.Atoi(canned)
if err != nil {
panic(err)
}
fmt.Printf("\n We should see one cancelled job now, and we see: %d. snapmap: %#v\n", ican, snapmap)
cv.So(ican, cv.ShouldEqual, 1)
w.Destroy()
})
})
}