UNPKG

mqrpc

Version:

💫 Easy RPC over RabbitMQ

31 lines (30 loc) • 1.55 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const ava_1 = require("ava"); const Timer_1 = require("../../lib/Timer"); const _utils_1 = require("../_utils"); 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] #remove ignores unknown entries', t => { t.notThrows(() => t.context.timer.remove('an-id')); }); ava_1.default('[unit] #remove clears all set timeouts for an entry', t => { const startPromise = t.context.timer.addTimeouts('an-id', { id: 'ackTo', length: 25 }); t.context.timer.remove('an-id'); return _utils_1.delay(25).then(() => t.notThrows(Promise.race([startPromise, Promise.resolve(42)]))); }); ava_1.default('[unit] #remove does not afect other entries', t => { const goodPromise = t.context.timer.addTimeouts('an-id', { id: 'ackTo', length: 25 }); const badPromise = t.context.timer.addTimeouts('another-id', { id: 'ackTo', length: 25 }); t.context.timer.remove('an-id'); return _utils_1.delay(25).then(async () => { await t.throws(badPromise); await t.notThrows(Promise.race([goodPromise, Promise.resolve(42)])); }); }); ava_1.default('[unit] #remove removes the existing entry', t => { const firstPromise = t.context.timer.addTimeouts('an-id', { id: 'ackTo', length: 25 }); t.context.timer.remove('an-id'); const secondPromise = t.context.timer.addTimeouts('an-id', { id: 'ackTo', length: 25 }); t.not(firstPromise, secondPromise); });