-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathjobsession_test.go
323 lines (249 loc) · 9.19 KB
/
jobsession_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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
package drmaa2os_test
import (
"errors"
"os"
"time"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/dgruber/drmaa2interface"
"github.com/dgruber/drmaa2os"
//_ "github.com/dgruber/drmaa2os/pkg/jobtracker/dockertracker"
// test with process tracker
_ "github.com/dgruber/drmaa2os/pkg/jobtracker/simpletracker"
"github.com/dgruber/drmaa2os/pkg/jobtracker/simpletrackerfakes"
)
var _ = Describe("JobSession", func() {
var (
js drmaa2interface.JobSession
jt drmaa2interface.JobTemplate
sm drmaa2interface.SessionManager
)
BeforeEach(func() {
os.Remove("drmaa2ostest")
sm, _ = drmaa2os.NewDefaultSessionManager("drmaa2ostest")
//sm, _ = drmaa2os.NewDockerSessionManager("drmaa2ostest")
var err error
js, err = sm.CreateJobSession("testsession", "")
Ω(err).To(BeNil())
//js = newJobSession("testsession", []jobtracker.JobTracker{simpletracker.New("testsession")})
jt = drmaa2interface.JobTemplate{
RemoteCommand: "/bin/sleep",
Args: []string{"0.1"},
JobCategory: "busybox:latest",
}
})
Describe("standard operations", func() {
It("should return the job session name", func() {
name, err := js.GetSessionName()
Ω(err).Should(BeNil())
Ω(name).Should(Equal("testsession"))
Ω(js.Close()).Should(BeNil())
})
It("should be to get the contact string", func() {
_, err := js.GetContact()
Ω(err).Should(BeNil())
})
It("should be to get the job categories", func() {
categories, err := js.GetJobCategories()
Ω(err).Should(BeNil())
Ω(categories).ShouldNot(BeNil())
Ω(len(categories)).Should(BeNumerically(">=", 0))
})
It("should be able to submit a job and get access to it", func() {
job, err := js.RunJob(jt)
Ω(err).Should(BeNil())
template, errTempl := job.GetJobTemplate()
Ω(errTempl).Should(BeNil())
Ω(template).Should(Equal(jt))
// check if job template is filled out
Ω(template.RemoteCommand).Should(Equal(jt.RemoteCommand))
Ω(template.JobCategory).Should(Equal(jt.JobCategory))
Ω(template.Args[0]).Should(Equal(jt.Args[0]))
filter := drmaa2interface.CreateJobInfo()
filter.ID = job.GetID()
jobs, errJobs := js.GetJobs(filter)
Ω(errJobs).Should(BeNil())
Ω(len(jobs)).Should(BeNumerically("==", 1))
})
It("should be able to wait for a started job", func() {
job, err := js.RunJob(jt)
Ω(err).Should(BeNil())
jobid := job.GetID()
var jobs []drmaa2interface.Job
jobs = append(jobs, job)
// it should fail to wait for a job when no job is given
_, err = js.WaitAnyStarted([]drmaa2interface.Job{}, time.Second*1)
Ω(err).ShouldNot(BeNil())
j, err := js.WaitAnyStarted(jobs, time.Second*2)
Ω(err).Should(BeNil())
Ω(j.GetID()).Should(Equal(jobid))
//Ω(j.GetState()).Should(Equal(drmaa2interface.Failed))
Ω(js.Close()).Should(BeNil())
})
It("should be able to wait for a finished job", func() {
job, err := js.RunJob(jt)
Ω(err).Should(BeNil())
jobid := job.GetID()
j, err := js.WaitAnyTerminated([]drmaa2interface.Job{job}, time.Second*30)
Ω(err).Should(BeNil())
Ω(j.GetID()).Should(Equal(jobid))
//Ω(j.GetState()).Should(Equal(drmaa2interface.Done))
Ω(js.Close()).Should(BeNil())
})
})
Describe("GetJobs operation", func() {
It("should return ni jobs when no filter is applied and no jobs are submitted", func() {
jobs, err := js.GetJobs(drmaa2interface.CreateJobInfo())
Ω(err).Should(BeNil())
Ω(len(jobs)).Should(BeNumerically("==", 0))
})
It("should return only jobs specified by the filter", func() {
job, err := js.RunJob(drmaa2interface.JobTemplate{
RemoteCommand: "/bin/bash",
Args: []string{"-c", `exit 0`},
JobName: "goodjob",
AccountingID: "account1",
})
Ω(err).Should(BeNil())
Ω(job.WaitTerminated(drmaa2interface.InfiniteTime)).To(BeNil())
job, err = js.RunJob(drmaa2interface.JobTemplate{
RemoteCommand: "/bin/bash",
Args: []string{"-c", `exit 1`},
JobName: "badjob",
AccountingID: "account1",
})
Ω(err).Should(BeNil())
Ω(job.WaitTerminated(drmaa2interface.InfiniteTime)).To(BeNil())
// no filter
jobList, err := js.GetJobs(drmaa2interface.CreateJobInfo())
Ω(err).Should(BeNil())
Ω(len(jobList)).Should(BeNumerically("==", 2))
filter := drmaa2interface.CreateJobInfo()
filter.ExitStatus = 0
// only goodjob should be returned
jobList, err = js.GetJobs(filter)
Ω(err).Should(BeNil())
Ω(len(jobList)).Should(BeNumerically("==", 1))
Ω(jobList[0].GetState().String()).Should(Equal(drmaa2interface.Done.String()))
// only badjob should be returned
filter.ExitStatus = 1
jobList, err = js.GetJobs(filter)
Ω(err).Should(BeNil())
Ω(len(jobList)).Should(BeNumerically("==", 1))
Ω(jobList[0].GetState().String()).Should(Equal(drmaa2interface.Failed.String()))
})
})
Describe("Basic error cases", func() {
It("should fail to run a job with broken job template", func() {
job, err := js.RunJob(drmaa2interface.JobTemplate{})
Ω(err).ShouldNot(BeNil())
Ω(job).Should(BeNil())
})
It("should fail to create a job array with broken job template", func() {
ajob, err := js.RunBulkJobs(drmaa2interface.JobTemplate{}, 1, 10, 1, 1)
Ω(err).ShouldNot(BeNil())
Ω(ajob).Should(BeNil())
})
It("should fail to close a job session two times", func() {
err := js.Close()
Ω(err).Should(BeNil())
err = js.Close()
Ω(err).Should(Equal(drmaa2os.ErrorInvalidSession))
})
It("should return the error string", func() {
err := drmaa2os.ErrorUnsupportedOperation
Ω(err.Error()).Should(Equal("This optional function is not suppported."))
})
})
Describe("waitAny with fakes", func() {
It("should return when one job is running", func() {
job1 := simpletrackerfakes.NewFakeJob(drmaa2interface.Running, "", time.Millisecond*100)
job2 := simpletrackerfakes.NewFakeJob(drmaa2interface.Running, "", time.Millisecond*5000)
var array []drmaa2interface.Job
array = append(array, job1)
array = append(array, job2)
job, err := js.WaitAnyStarted(array, time.Second*4)
Ω(err).Should(BeNil())
Ω(job.GetState()).Should(Equal(drmaa2interface.Running))
})
It("should return with an error when timeout is reached", func() {
job1 := simpletrackerfakes.NewFakeJob(drmaa2interface.Running, "", time.Millisecond*2000)
job2 := simpletrackerfakes.NewFakeJob(drmaa2interface.Running, "", time.Millisecond*1500)
var array []drmaa2interface.Job
array = append(array, job1)
array = append(array, job2)
job, err := js.WaitAnyStarted(array, time.Second*1)
Ω(err).ShouldNot(BeNil())
Ω(job).Should(BeNil())
})
It("should return with an error when all job wait calls errors immediately", func() {
job1 := simpletrackerfakes.NewFakeJob(drmaa2interface.Running, "immediate error", time.Millisecond*2000)
job2 := simpletrackerfakes.NewFakeJob(drmaa2interface.Running, "immediate error", time.Millisecond*1500)
var array []drmaa2interface.Job
array = append(array, job1)
array = append(array, job2)
job, err := js.WaitAnyStarted(array, time.Second*1)
Ω(err).ShouldNot(BeNil())
Ω(err).Should(Equal(errors.New("Error waiting for jobs")))
Ω(job).Should(BeNil())
})
})
Describe("basic job array functionality", func() {
It("should be possible to submit a job array (bulk job)", func() {
arrayjob, err := js.RunBulkJobs(jt, 1, 10, 1, 2)
Ω(err).Should(BeNil())
jobid := arrayjob.GetID()
Ω(jobid).ShouldNot(Equal(""))
jobs := arrayjob.GetJobs()
Ω(len(jobs)).Should(Equal(10))
j, err := js.WaitAnyTerminated(jobs, time.Second*20)
Ω(err).Should(BeNil())
//Ω(j.GetID()).Should(ContainSubstring(jobid))
//Ω(jobid).Should(ContainSubstring(j.GetID()))
Ω(j.GetState()).Should(Equal(drmaa2interface.Done))
Ω(js.Close()).Should(BeNil())
})
It("should be possible to submit a job array with limited parallel execution", func() {
jt := drmaa2interface.JobTemplate{
RemoteCommand: "sleep",
Args: []string{"0"},
}
arrayjob, _ := js.RunBulkJobs(jt, 1, 10, 1, 5)
//Ω(err).Should(BeNil())
jobs := arrayjob.GetJobs()
Ω(len(jobs)).Should(Equal(10))
for i := 0; i < 10; i++ {
_, err := js.WaitAnyTerminated(jobs, time.Second*20)
Ω(err).Should(BeNil())
}
Ω(js.Close()).Should(BeNil())
})
It("should be possible to terminate a job array (bulk job)", func() {
amount := 10
jt := drmaa2interface.JobTemplate{
RemoteCommand: "/bin/sh",
Args: []string{"-c", "for i in $(seq 1 10); do echo $i; sleep 1; done"},
JobCategory: "busybox:latest",
}
arrayjob, err := js.RunBulkJobs(jt, 1, amount, 1, 2)
Ω(err).Should(BeNil())
jobid := arrayjob.GetID()
Ω(jobid).ShouldNot(Equal(""))
tasks := arrayjob.GetJobs()
Expect(len(tasks)).Should(Equal(amount))
err = arrayjob.Terminate()
Ω(err).Should(BeNil())
for _, j := range tasks {
err = j.WaitTerminated(time.Second * 2)
Ω(err).Should(BeNil())
Ω(j.GetState().String()).Should(Equal(drmaa2interface.Failed.String()))
}
Ω(js.Close()).Should(BeNil())
})
It("should error when job array is not found", func() {
aj, err := js.GetJobArray("doesNotExist")
Ω(err).ShouldNot(BeNil())
Ω(aj).Should(BeNil())
})
})
})