Reserve and Reserve-with-timeout commands return RESERVED instead of DEADLINE_SOON if there are ready jobs
I have 4 jobs in the ready state with a ttr of 2 inserted before this test.
it('should reserve a job and afterwards call reserve in the safety margin of the job and return the deadline soon error', async () => {
await client.reserve();
await new Promise(f => setTimeout(f, 1500));
await expect(client.reserve()).to.be.rejectedWith("[Unexpected reserve error: DEADLINE_SOON] A job reserved by this client will reach its deadline soon, release it first.");
});Instead of returning the DEADLINE_SOON error, one of the other three jobs is reserved instead.
If I understand the C code right, it returns DEADLINE_SOON if there are no ready jobs in the watched tubes but the protocol just says:
During the TTR of a reserved job, the last second is kept by the server as a safety margin, during which the client will not be made to wait for another job. If the client issues a reserve command during the safety margin, or if the safety margin arrives while the client is waiting on a reserve command, the server will respond with:
DEADLINE_SOON\r\n
It is nowhere mentioned that there can't be any ready jobs in the watched tubes. The safety margin arriving while the client is waiting implies that there are no ready jobs, but the client issuing a reserve command during the safety margin does not.
Source: beanstalkd/beanstalkd