File size: 1,234 Bytes
2276d59
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65fc551
2276d59
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65fc551
 
 
 
 
 
 
 
2276d59
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';

// bypass mocks
vi.unmock('ioredis');

import { Queue, Worker } from 'bullmq';
import Redis from 'ioredis';

describe('BullMQ Infrastructure Engine Integration', () => {
  let connection: Redis;
  let testQueue: Queue;
  let testWorker: Worker;

  beforeEach(() => {
    // configure Redis
    connection = new Redis(process.env.REDIS_URL || 'redis://127.0.0.1:6379', {
      maxRetriesPerRequest: null,
    });
    testQueue = new Queue('test_downloads', { connection });
  });

  afterEach(async () => {
    if (testWorker) await testWorker.close();
    if (testQueue) await testQueue.close();
    if (connection) {
      await connection.flushdb();
      await connection.quit();
    }
  });

  it('Should successfully dispatch, pick up, and drain tasks via the localized pipeline', async () => {
    const jobPromise = new Promise<void>((resolve) => {
      testWorker = new Worker(
        'test_downloads',
        (job) => {
          expect(job.data.weight).toBe(1);
          resolve();
        },
        { connection }
      );
    });

    await testQueue.add('lock', { weight: 1 });
    await expect(jobPromise).resolves.not.toThrow();
  });
});