import { Redis } from 'ioredis' ; import { flushAll , quit , createClientAndLoadLuaScripts , } from '../../utils/redis' ; import { createUuid } from '../../utils/general' ; import { redisConfig } from '../config' ; import { takeTaskAndMarkAsProcessing } from '../../actions/take-task-and-mark-as-processing' ; import { Task } from '../../domain/tasks/task' ; import { enqueueTasks } from '../../actions/enqueue-tasks' ; import { markTaskSuccess } from '../../actions/mark-task-success' ; import { markTaskFailed } from '../../actions/mark-task-failed' ; import { getTaskCounts } from '../../actions/get-task-counts' ; import { scheduleTask } from '../../actions/schedule-task' ; describe ( 'getTaskCounts' , ( ) => { const queue = createUuid ( ) ; let client ; beforeAll ( ( ) => { client = createClientAndLoadLuaScripts ( redisConfig ) ; } ) ; beforeEach ( async ( ) => { await flushAll ( { client } ) ; } ) ; afterAll ( async ( ) => { await quit ( { client } ) ; } ) ; it ( 'getTaskCounts gets counts' , async ( ) => { const task1 = { id : '1' , data : 'c' , enqueueAfter : new Date ( ) } ; const task2 = { id : '2' , data : 'c' } ; const task3 = { id : '3' , data : 'c' } ; const task4 = { id : '4' , data : 'c' } ; const task5 = { id : '5' , data : 'c' } ; const task6 = { id : '6' , data : 'c' } ; await scheduleTask ( { task : task1 , queue , client } ) ; await enqueueTasks ( { queue , tasks : [ task2 , task3 , task4 , task5 , task6 ] , client , } ) ; await takeTaskAndMarkAsProcessing ( { queue , client } ) ; const successfulTask = ( await takeTaskAndMarkAsProcessing ( { queue , client , } ) ) as Task ; const failedTask = ( await takeTaskAndMarkAsProcessing ( { queue , client , } ) ) as Task ; await markTaskSuccess ( { task : successfulTask , queue , client , result : 'some-result' , asOf : new Date ( ) , } ) ; await markTaskFailed ( { task : failedTask , queue , client , error : 'some-error' , } ) ; const { scheduledCount , queuedCount , processingCount , successCount , failedCount , } = await getTaskCounts ( { queue , client } ) ; expect ( scheduledCount ) . toBe ( 1 ) ; expect ( queuedCount ) . toBe ( 2 ) ; expect ( processingCount ) . toBe ( 1 ) ; expect ( successCount ) . toBe ( 1 ) ; expect ( failedCount ) . toBe ( 1 ) ; } ) ; } ) ;