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