-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathmonitoringsession_test.go
169 lines (122 loc) · 4.33 KB
/
monitoringsession_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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
package drmaa2os_test
import (
"fmt"
"github.com/dgruber/drmaa2interface"
"github.com/dgruber/drmaa2os"
"os"
// test with process tracker
_ "github.com/dgruber/drmaa2os/pkg/jobtracker/simpletracker"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
var _ = Describe("MonitoringSession", func() {
var (
sm drmaa2interface.SessionManager
)
BeforeEach(func() {
os.Remove("drmaa2ostest")
sm, _ = drmaa2os.NewDefaultSessionManager("drmaa2ostest")
})
Describe("Monitoring Session", func() {
Context("Monitoring Session is implemented for process backend", func() {
It("should create a usable monitoring session", func() {
ms, err := sm.OpenMonitoringSession("test")
Ω(err).Should(BeNil())
Ω(ms).ShouldNot(BeNil())
machines, err := ms.GetAllMachines(nil)
Ω(err).Should(BeNil())
Ω(machines).ShouldNot(BeNil())
jobs, err := ms.GetAllJobs(drmaa2interface.CreateJobInfo())
Ω(err).Should(BeNil())
Ω(jobs).ShouldNot(BeNil())
queues, err := ms.GetAllQueues(nil)
Ω(err).Should(BeNil())
Ω(queues).ShouldNot(BeNil())
// reservations are not yet supported
reservations, err := ms.GetAllReservations()
Ω(err).ShouldNot(BeNil())
Ω(reservations).Should(BeNil())
err = ms.CloseMonitoringSession()
Ω(err).Should(BeNil())
})
})
Context("Monitoring Session jobs", func() {
It("should fail to manipulate the jobs as they are read only (for now)", func() {
ms, err := sm.OpenMonitoringSession("test")
Ω(err).Should(BeNil())
Ω(ms).ShouldNot(BeNil())
jobs, err := ms.GetAllJobs(drmaa2interface.CreateJobInfo())
Ω(err).Should(BeNil())
// maninulation must fail
Ω(jobs[0].Suspend()).ShouldNot(BeNil())
Ω(jobs[0].Resume()).ShouldNot(BeNil())
Ω(jobs[0].Hold()).ShouldNot(BeNil())
Ω(jobs[0].Terminate()).ShouldNot(BeNil())
Ω(jobs[0].Release()).ShouldNot(BeNil())
// reaping a monitoring job must fail
Ω(jobs[0].Reap()).ShouldNot(BeNil())
})
It("should get the state of a job", func() {
ms, err := sm.OpenMonitoringSession("test")
Ω(err).Should(BeNil())
Ω(ms).ShouldNot(BeNil())
jobs, err := ms.GetAllJobs(drmaa2interface.CreateJobInfo())
Ω(err).Should(BeNil())
Ω(jobs[0].GetState().String()).Should(Equal(drmaa2interface.Running.String()))
jobInfo, err := jobs[0].GetJobInfo()
fmt.Printf("%v", jobInfo)
Ω(err).Should(BeNil())
Ω(jobInfo.ID).ShouldNot(Equal(""))
})
})
Context("Filter", func() {
It("should filter for a job with a specific ID", func() {
ms, err := sm.OpenMonitoringSession("testFilter")
Ω(err).Should(BeNil())
Ω(ms).ShouldNot(BeNil())
jobs, err := ms.GetAllJobs(drmaa2interface.CreateJobInfo())
Ω(err).Should(BeNil())
Ω(jobs).ShouldNot(BeNil())
Ω(len(jobs)).Should(BeNumerically(">=", 0))
filter := drmaa2interface.CreateJobInfo()
filter.ID = jobs[0].GetID()
// hopefully the process is still running :)
filteredJobs, err := ms.GetAllJobs(filter)
Ω(err).Should(BeNil())
Ω(filteredJobs).ShouldNot(BeNil())
Ω(len(filteredJobs)).Should(BeNumerically("==", 1))
Ω(filteredJobs[0].GetID()).Should(Equal(filter.ID))
})
It("should filter for the local machine", func() {
ms, err := sm.OpenMonitoringSession("test")
Ω(err).Should(BeNil())
Ω(ms).ShouldNot(BeNil())
machines, err := ms.GetAllMachines(nil)
Ω(err).Should(BeNil())
Ω(machines).ShouldNot(BeNil())
Ω(len(machines)).Should(BeNumerically("==", 1))
filteredMachines, err := ms.GetAllMachines([]string{"XXX"})
Ω(err).Should(BeNil())
Ω(len(filteredMachines)).Should(BeNumerically("==", 0))
filteredMachines2, err := ms.GetAllMachines([]string{machines[0].Name})
Ω(err).Should(BeNil())
Ω(len(filteredMachines2)).Should(BeNumerically("==", 1))
})
It("should filter for queues", func() {
ms, err := sm.OpenMonitoringSession("test")
Ω(err).Should(BeNil())
Ω(ms).ShouldNot(BeNil())
// there are no queues for processes
queues, err := ms.GetAllQueues(nil)
Ω(err).Should(BeNil())
Ω(queues).ShouldNot(BeNil())
queues, err = ms.GetAllQueues([]string{})
Ω(err).Should(BeNil())
Ω(queues).ShouldNot(BeNil())
queues, err = ms.GetAllQueues([]string{"X"})
Ω(err).Should(BeNil())
Ω(queues).ShouldNot(BeNil())
})
})
})
})