Skip to content

Commit

Permalink
test(worker): add test cases for getBlockTimeout method (#2493)
Browse files Browse the repository at this point in the history
  • Loading branch information
roggervalf authored Mar 28, 2024
1 parent b8d7ebf commit 1613ba9
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/commands/moveToActive-11.lua
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,6 @@ end

-- Return the timestamp for the next delayed job if any.
local nextTimestamp = getNextDelayedTimestamp(delayedKey)
if (nextTimestamp ~= nil) then return {0, 0, 0, nextTimestamp} end
if nextTimestamp ~= nil then return {0, 0, 0, nextTimestamp} end

return {0, 0, 0, 0}
61 changes: 61 additions & 0 deletions tests/test_worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -893,6 +893,67 @@ describe('workers', function () {
});
});

describe('when calling getBlockTimeout', () => {
describe('when blockUntil is 0', () => {
describe('when drainDelay is greater than minimumBlockTimeout', () => {
it('returns drainDelay', async () => {
const worker = new Worker(queueName, async () => {}, {
connection,
prefix,
autorun: false,
});

expect(worker['getBlockTimeout'](0)).to.be.equal(5);
worker.close();
});
});

describe('when drainDelay is lower than minimumBlockTimeout', () => {
it('returns drainDelay', async () => {
const worker = new Worker(queueName, async () => {}, {
connection,
drainDelay: 0.00001,
prefix,
autorun: false,
});

expect(worker['getBlockTimeout'](0)).to.be.equal(0.001);
worker.close();
});
});
});

describe('when blockUntil is greater than 0', () => {
describe('when blockUntil is lower than date now value', () => {
it('returns minimumBlockTimeout', async () => {
const worker = new Worker(queueName, async () => {}, {
connection,
prefix,
autorun: false,
});

expect(worker['getBlockTimeout'](Date.now() - 1)).to.be.equal(0.001);
worker.close();
});
});

describe('when blockUntil is greater than date now value', () => {
it('returns delay value greater than minimumBlockTimeout', async () => {
const worker = new Worker(queueName, async () => {}, {
connection,
prefix,
autorun: false,
});

expect(worker['getBlockTimeout'](Date.now() + 100)).to.be.greaterThan(
0.001,
);
worker.close();
});
});
});
});

describe('when sharing connection', () => {
it('should not fail', async () => {
const queueName2 = `test-${v4()}`;
Expand Down

0 comments on commit 1613ba9

Please sign in to comment.