feat-pipelines #1
@ -155,20 +155,31 @@ describe('PipelineTasksService', () => {
|
|||||||
it('pipeline is busy', async () => {
|
it('pipeline is busy', async () => {
|
||||||
let remainTimes = 3;
|
let remainTimes = 3;
|
||||||
|
|
||||||
const incr = jest
|
let lckValue: string;
|
||||||
.spyOn(redisClient, 'incr')
|
const set = jest
|
||||||
.mockImplementation(() => remainTimes--);
|
.spyOn(redisClient, 'set')
|
||||||
|
.mockImplementation(async (...args) => {
|
||||||
|
if (remainTimes-- > 0) {
|
||||||
|
throw new Error();
|
||||||
|
} else {
|
||||||
|
lckValue = args[3] as string;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const get = jest
|
||||||
|
.spyOn(redisClient, 'get')
|
||||||
|
.mockImplementation(async () => lckValue);
|
||||||
|
const del = jest.spyOn(redisClient, 'del');
|
||||||
const rpop = jest.spyOn(redisClient, 'rpop');
|
const rpop = jest.spyOn(redisClient, 'rpop');
|
||||||
const decr = jest.spyOn(redisClient, 'decr');
|
|
||||||
const add = jest.spyOn(taskQueue, 'add');
|
const add = jest.spyOn(taskQueue, 'add');
|
||||||
|
|
||||||
await service.doNextTask(getBasePipeline());
|
await service.doNextTask(getBasePipeline());
|
||||||
|
|
||||||
expect(rpop).toHaveBeenCalledTimes(1);
|
expect(rpop).toHaveBeenCalledTimes(1);
|
||||||
expect(incr).toHaveBeenCalledTimes(3);
|
expect(set).toHaveBeenCalledTimes(4);
|
||||||
expect(decr).toHaveBeenCalledTimes(3);
|
expect(get).toHaveBeenCalledTimes(1);
|
||||||
|
expect(del).toHaveBeenCalledTimes(1);
|
||||||
expect(add).toHaveBeenCalledWith(getTask());
|
expect(add).toHaveBeenCalledWith(getTask());
|
||||||
});
|
}, 10_000);
|
||||||
it('pipeline always busy and timeout', async () => {
|
it('pipeline always busy and timeout', async () => {
|
||||||
const set = jest
|
const set = jest
|
||||||
.spyOn(redisClient, 'set')
|
.spyOn(redisClient, 'set')
|
||||||
|
Loading…
Reference in New Issue
Block a user