MCPcopy
hub / github.com/OptimalBits/bull / testRemoveOnFinish

Function testRemoveOnFinish

test/test_queue.js:497–562  ·  view source on GitHub ↗
(opts, expectedCount, fail)

Source from the content-addressed store, hash-verified

495
496 describe('auto job removal', () => {
497 async function testRemoveOnFinish(opts, expectedCount, fail) {
498 const clock = sinon.useFakeTimers();
499 clock.reset();
500
501 queue.process(async job => {
502 await job.log('test log');
503 if (fail) {
504 throw new Error('job failed');
505 }
506 });
507
508 const datas = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14];
509
510 const processing = new Promise(resolve => {
511 queue.on(fail ? 'failed' : 'completed', async job => {
512 clock.tick(1000);
513
514 if (job.data == 14) {
515 const counts = await queue.getJobCounts(
516 fail ? 'failed' : 'completed'
517 );
518
519 if (fail) {
520 expect(counts.failed).to.be.equal(expectedCount);
521 } else {
522 expect(counts.completed).to.be.equal(expectedCount);
523 }
524
525 await Promise.all(
526 jobIds.map(async (jobId, index) => {
527 const job = await queue.getJob(jobId);
528 const logs = await queue.getJobLogs(jobId);
529
530 try {
531 if (index >= datas.length - expectedCount) {
532 expect(job).to.not.be.equal(null);
533 expect(logs.logs).to.not.be.empty;
534 } else {
535 expect(job).to.be.equal(null);
536 expect(logs.logs).to.be.empty;
537 }
538 } catch (err) {
539 console.error(err);
540 }
541 })
542 );
543
544 resolve();
545 }
546 });
547 });
548
549 const jobOpts = {};
550 if (fail) {
551 jobOpts.removeOnFail = opts;
552 } else {
553 jobOpts.removeOnComplete = opts;
554 }

Callers 1

test_queue.jsFile · 0.85

Calls 7

processMethod · 0.80
logMethod · 0.80
onMethod · 0.80
getJobCountsMethod · 0.80
getJobMethod · 0.80
getJobLogsMethod · 0.80
addMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…