Adjust test for CloseRequest.
Change-Id: I0bc0399206f3285cdd8e20eacf1a5d25815e54f7
Signed-off-by: Lukasz Wojciechowski <l.wojciechow@partner.samsung.com>
}
// Finish closes the job execution, breaks the tunnel to Dryad and removes job
-// from jobs collection. It is a part of JobsManager interface implementation.
+// from jobs collection.
+// The Dryad should be notified and prepared for next job with key regeneration.
+// It is a part of JobsManager interface implementation.
func (m *JobsManagerImpl) Finish(worker WorkerUUID) error {
+ defer m.workers.PrepareWorker(worker, true)
m.mutex.Lock()
defer m.mutex.Unlock()
ttm.EXPECT().Create(nil, ip).Return(nil),
ttm.EXPECT().Addr().Return(addr),
ttm.EXPECT().Close(),
+ w.EXPECT().PrepareWorker(worker, true),
)
err := jm.Create(req, worker)
Expect(jm.(*JobsManagerImpl).jobs).To(BeEmpty())
})
It("should fail to finish nonexistent job", func() {
+ w.EXPECT().PrepareWorker(worker, true)
err := jm.Finish(worker)
Expect(err).To(Equal(NotFoundError("Job")))
})
// all required conditions to close request are met.
// The method must be called in reqs.mutex critical section.
func (reqs *ReqsCollection) closeRequest(req *ReqInfo) {
+ worker := req.Job.WorkerUUID
+ reqs.jobs.Finish(worker)
req.State = DONE
- // TODO(mwereski): release worker
}
// CloseRequest is part of implementation of Requests interface.
Describe("With RequestsManager created", func() {
var ctrl *gomock.Controller
var wm *MockWorkersManager
+ var jm *MockJobsManager
var R *ReqsCollection
testErr := errors.New("Test Error")
BeforeEach(func() {
ctrl = gomock.NewController(GinkgoT())
wm = NewMockWorkersManager(ctrl)
- R = NewRequestQueue(wm, nil)
+ jm = NewMockJobsManager(ctrl)
+ R = NewRequestQueue(wm, jm)
})
AfterEach(func() {
R.Finish()
Expect(err).To(Equal(ErrModificationForbidden))
})
It("should close request and release worker", func() {
+ testWorker := WorkerUUID("TestWorker")
R.mutex.Lock()
rinfo.State = INPROGRESS
rinfo.Job = &JobInfo{
- Timeout: time.Now().AddDate(0, 0, -1),
+ Timeout: time.Now().AddDate(0, 0, -1),
+ WorkerUUID: testWorker,
}
R.mutex.Unlock()
+ gomock.InOrder(
+ jm.EXPECT().Finish(testWorker),
+ )
err := R.Close(req)
Expect(err).NotTo(HaveOccurred())
Expect(rinfo.State).To(Equal(DONE))
- // TODO verify releasing worker when implemented
})
})
Describe("Run", func() {
}
func TestCloseRequest(t *testing.T) {
- assert, rqueue, ctrl, _ := initTest(t)
+ assert, rqueue, ctrl, jm := initTest(t)
defer finiTest(rqueue, ctrl)
+
req := requestsTests[0].req
+ jobInfo := JobInfo{
+ WorkerUUID: "Test WorkerUUID",
+ }
// Add valid request to the queue.
reqid, err := rqueue.NewRequest(req.Caps, req.Priority, req.Owner, req.ValidAfter, req.Deadline)
assert.Nil(err)
rqueue.mutex.Lock()
rqueue.requests[reqid].State = INPROGRESS
+ rqueue.requests[reqid].Job = &jobInfo
rqueue.queue.removeRequest(&reqinfo)
rqueue.mutex.Unlock()
// Close request.
+ gomock.InOrder(
+ jm.EXPECT().Finish(jobInfo.WorkerUUID),
+ )
err = rqueue.CloseRequest(reqid)
assert.Nil(err)
rqueue.mutex.RLock()
func TestAcquireWorker(t *testing.T) {
assert, rqueue, ctrl, jm := initTest(t)
defer finiTest(rqueue, ctrl)
-
req := requestsTests[0].req
empty := AccessInfo{}
testErr := errors.New("Test Error")