Make use of helpers

This commit is contained in:
Adria Navarro 2024-11-07 10:38:34 +01:00
parent a7bb89a710
commit 866bef8145
3 changed files with 13 additions and 4 deletions

View File

@ -21,6 +21,8 @@ async function waitForQueueCompletion() {
await utils.queue.processMessages(DocWritethroughProcessor.queue)
}
beforeAll(() => utils.queue.useRealQueues())
describe("docWritethrough", () => {
beforeAll(() => {
init()

View File

@ -15,7 +15,7 @@ const QUEUE_LOCK_MS = Duration.fromMinutes(5).toMs()
const QUEUE_LOCK_RENEW_INTERNAL_MS = Duration.fromSeconds(30).toMs()
// cleanup the queue every 60 seconds
const CLEANUP_PERIOD_MS = Duration.fromSeconds(60).toMs()
let QUEUES: BullQueue.Queue[] | InMemoryQueue[] = []
let QUEUES: BullQueue.Queue[] = []
let cleanupInterval: NodeJS.Timeout
async function cleanup() {
@ -45,11 +45,18 @@ export function createQueue<T>(
if (opts.jobOptions) {
queueConfig.defaultJobOptions = opts.jobOptions
}
let queue: any
let queue: BullQueue.Queue<T>
if (!env.isTest()) {
queue = new BullQueue(jobQueue, queueConfig)
} else if (
process.env.BULL_TEST_REDIS_PORT &&
!isNaN(+process.env.BULL_TEST_REDIS_PORT)
) {
queue = new BullQueue(jobQueue, {
redis: { host: "localhost", port: +process.env.BULL_TEST_REDIS_PORT },
})
} else {
queue = new InMemoryQueue(jobQueue, queueConfig)
queue = new InMemoryQueue(jobQueue, queueConfig) as any
}
addListeners(queue, jobQueue, opts?.removeStalledCb)
QUEUES.push(queue)

View File

@ -19,7 +19,7 @@ export async function useRealQueues() {
.start()
const port = redis.getMappedPort(6379)
process.env.BULL_TEST_REDIS = `http://127.0.0.1:${port}`
process.env.BULL_TEST_REDIS_PORT = port.toString()
}
export async function processMessages(queue: Queue) {