mqrpc
Version:
💫 Easy RPC over RabbitMQ
31 lines (30 loc) • 1.5 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const ava_1 = require("ava");
const Timer_1 = require("../../lib/Timer");
const _utils_1 = require("../_utils");
const timeout = { id: 'ackTo', length: 25 };
ava_1.default.beforeEach(t => t.context.timer = new Timer_1.default());
ava_1.default.afterEach(t => t.context.timer.clear());
ava_1.default('[unit] #removeTimeouts throws when the entry does not exist', t => {
t.throws(() => t.context.timer.removeTimeouts('an-id', 'ackTo'));
});
ava_1.default('[unit] #removeTimeouts ignores missing timeouts', t => {
t.context.timer.addTimeouts('an-id', timeout);
t.notThrows(() => t.context.timer.removeTimeouts('an-id', 'otherTo'));
});
ava_1.default('[unit] #removeTimeouts stops & removes the given timeouts', t => {
const promise = t.context.timer.addTimeouts('an-id', timeout, { id: 'otherTo', length: 15 });
t.context.timer.removeTimeouts('an-id', timeout.id, 'otherTo');
return _utils_1.delay(25).then(() => t.notThrows(Promise.race([promise, Promise.resolve(42)])));
});
ava_1.default('[unit] #removeTimeouts does not affect other timeouts in the same entry', t => {
t.plan(2);
const start = Date.now();
const promise = t.context.timer.addTimeouts('an-id', timeout, { id: 'otherTo', length: 15 });
t.context.timer.removeTimeouts('an-id', 'otherTo');
return promise.catch(err => {
t.regex(err.message, /ackTo.*25/);
t.true(Date.now() >= start + 25);
});
});