// all required conditions to close request are met.
// The method must be called in reqs.mutex critical section.
func (reqs *ReqsCollection) closeRequest(req *boruta.ReqInfo) {
+ req.State = boruta.DONE
+ if req.Job == nil {
+ // TODO log logic error, but continue service.
+ return
+ }
worker := req.Job.WorkerUUID
reqs.jobs.Finish(worker)
- req.State = boruta.DONE
}
// CloseRequest is part of implementation of Requests interface.
job, err := reqs.jobs.Get(worker)
if err != nil {
- panic("no job related to running worker")
+ // Nothing to be done on requests or jobs level, when worker had no job assigned.
+ // It is not an error situation if Worker state transition:
+ // RUN->MAINTENANCE or RUN->FAIL happens and a request is not run
+ // by any Job. It can occur e.g. when worker is already booked for
+ // a Job (in RUN state) and creation of Job is not yet completed
+ // or failed.
+ return
}
reqID := job.Req
assert.Equal(boruta.ReqState(boruta.DONE), rqueue.requests[reqid].State)
rqueue.mutex.RUnlock()
+ // Add another another valid request.
+ reqid, err = rqueue.NewRequest(req.Caps, req.Priority, req.Owner, req.ValidAfter, req.Deadline)
+ assert.Nil(err)
+ assert.EqualValues(3, reqid)
+ // Simulate situation where request is in PROGRESS state, but no job for it exists.
+ reqinfo, err = rqueue.GetRequestInfo(reqid)
+ assert.Nil(err)
+ rqueue.mutex.Lock()
+ rqueue.requests[reqid].State = boruta.INPROGRESS
+ rqueue.requests[reqid].Job = nil
+ rqueue.queue.removeRequest(&reqinfo)
+ rqueue.mutex.Unlock()
+ // Close request.
+ err = rqueue.CloseRequest(reqid)
+ assert.Nil(err)
+ rqueue.mutex.RLock()
+ assert.EqualValues(3, len(rqueue.requests))
+ assert.Equal(boruta.ReqState(boruta.DONE), rqueue.requests[reqid].State)
+ rqueue.mutex.RUnlock()
+
// Simulation for the rest of states.
states := [...]boruta.ReqState{boruta.INVALID, boruta.CANCEL, boruta.TIMEOUT, boruta.DONE,
boruta.FAILED}
reqid, err = rqueue.NewRequest(req.Caps, req.Priority, req.Owner, req.ValidAfter, req.Deadline)
assert.Nil(err)
- assert.EqualValues(3, reqid)
+ assert.EqualValues(4, reqid)
reqinfo, err = rqueue.GetRequestInfo(reqid)
assert.Nil(err)
rqueue.mutex.Lock()
rqueue.mutex.RLock()
defer rqueue.mutex.RUnlock()
- assert.EqualValues(3, len(rqueue.requests))
+ assert.EqualValues(4, len(rqueue.requests))
assert.EqualValues(0, rqueue.queue.length)
}
})
})
Describe("OnWorkerFail", func() {
- It("should panic if jobs.Get fails", func() {
+ It("should return if jobs.Get fails", func() {
jm.EXPECT().Get(testWorker).Return(nil, testErr)
- Expect(func() {
- R.OnWorkerFail(testWorker)
- }).To(Panic())
+ R.OnWorkerFail(testWorker)
})
It("should panic if failing worker was processing unknown Job", func() {
noReq := boruta.ReqID(0)