Skip to content

Commit

Permalink
ci: add support for testing on dragonflydb (#2210)
Browse files Browse the repository at this point in the history
  • Loading branch information
manast authored Nov 3, 2023
1 parent edd4b6b commit d4cb929
Show file tree
Hide file tree
Showing 25 changed files with 1,910 additions and 1,243 deletions.
31 changes: 30 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:
exit 1
fi
compatibility:
node-redis:
runs-on: ubuntu-latest

name: testing node@${{ matrix.node-version }}, redis@${{ matrix.redis-version }}
Expand Down Expand Up @@ -87,6 +87,35 @@ jobs:
- run: yarn build
- run: yarn test

node-dragonflydb:
runs-on: ubuntu-latest

env:
node-version: lts/*

name: testing node@lts/*, dragonflydb@latest

services:
dragonflydb:
image: docker.dragonflydb.io/dragonflydb/dragonfly
env:
DFLY_cluster_mode: emulated
DFLY_lock_on_hashtags: true
ports:
- 6379:6379

steps:
- name: Checkout repository
uses: actions/checkout@v3 # v3
- name: Use Node.js ${{ env.node-version }}
uses: actions/setup-node@v3 # v3
with:
node-version: lts/*
cache: 'yarn'
- run: yarn install --ignore-engines --frozen-lockfile --non-interactive
- run: yarn build
- run: BULLMQ_TEST_PREFIX={b} yarn test

python:
runs-on: ubuntu-latest

Expand Down
1 change: 1 addition & 0 deletions .mocharc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ module.exports = {
file: ['./mocha.setup.ts'],
spec: ['./tests/test_*.ts'],
timeout: 4000,
'trace-warnings': true,
};
3 changes: 2 additions & 1 deletion src/classes/queue-getters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,8 @@ export class QueueGetters<
}

/**
* Returns the jobs that are in the "waiting" status.
* Returns the jobs that are in the "waiting-children" status.
* I.E. parent jobs that have at least one child that has not completed yet.
* @param start - zero based index from where to start returning jobs.
* @param end - zero based index where to stop returning jobs.
*/
Expand Down
6 changes: 5 additions & 1 deletion src/classes/redis-connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,11 +222,15 @@ export class RedisConnection extends EventEmitter {
return this._client;
}

async disconnect(): Promise<void> {
async disconnect(wait = true): Promise<void> {
const client = await this.client;
if (client.status !== 'end') {
let _resolve, _reject;

if (!wait) {
return client.disconnect();
}

const disconnecting = new Promise<void>((resolve, reject) => {
client.once('end', resolve);
client.once('error', reject);
Expand Down
3 changes: 2 additions & 1 deletion src/classes/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,8 @@ export class Worker<
// Force reconnection of blocking connection to abort blocking redis call immediately.
//
if (this.waiting) {
await this.blockingConnection.disconnect();
// If we are not going to reconnect, we will not wait for the disconnection.
await this.blockingConnection.disconnect(reconnect);
} else {
reconnect = false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export function isRedisCluster(obj: unknown): obj is Cluster {
export async function removeAllQueueData(
client: RedisClient,
queueName: string,
prefix = 'bull',
prefix = process.env.BULLMQ_TEST_PREFIX || 'bull',
): Promise<void | boolean> {
if (client instanceof Cluster) {
// todo compat with cluster ?
Expand Down
21 changes: 13 additions & 8 deletions tests/test_bulk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@ import { v4 } from 'uuid';
import { Queue, Worker, Job } from '../src/classes';
import { removeAllQueueData } from '../src/utils';

const prefix = process.env.BULLMQ_TEST_PREFIX || 'bull';

describe('bulk jobs', () => {
let queue: Queue;
let queueName: string;
const connection = { host: 'localhost' };

beforeEach(async function () {
queueName = `test-${v4()}`;
queue = new Queue(queueName, { connection });
queue = new Queue(queueName, { connection, prefix });
});

afterEach(async function () {
Expand All @@ -35,7 +37,7 @@ describe('bulk jobs', () => {
}
}),
);
const worker = new Worker(queueName, processor, { connection });
const worker = new Worker(queueName, processor, { connection, prefix });
await worker.waitUntilReady();

const jobs = await queue.addBulk([
Expand All @@ -56,10 +58,13 @@ describe('bulk jobs', () => {
it('should allow to pass parent option', async () => {
const name = 'test';
const parentQueueName = `parent-queue-${v4()}`;
const parentQueue = new Queue(parentQueueName, { connection });
const parentQueue = new Queue(parentQueueName, { connection, prefix });

const parentWorker = new Worker(parentQueueName, null, { connection });
const childrenWorker = new Worker(queueName, null, { connection });
const parentWorker = new Worker(parentQueueName, null, {
connection,
prefix,
});
const childrenWorker = new Worker(queueName, null, { connection, prefix });
await parentWorker.waitUntilReady();
await childrenWorker.waitUntilReady();

Expand All @@ -71,7 +76,7 @@ describe('bulk jobs', () => {
opts: {
parent: {
id: parent.id,
queue: `bull:${parentQueueName}`,
queue: `${prefix}:${parentQueueName}`,
},
},
},
Expand All @@ -81,7 +86,7 @@ describe('bulk jobs', () => {
opts: {
parent: {
id: parent.id,
queue: `bull:${parentQueueName}`,
queue: `${prefix}:${parentQueueName}`,
},
},
},
Expand Down Expand Up @@ -120,7 +125,7 @@ describe('bulk jobs', () => {
}
}),
);
const worker = new Worker(queueName, processor, { connection });
const worker = new Worker(queueName, processor, { connection, prefix });
await worker.waitUntilReady();

const jobs = await queue.addBulk([
Expand Down
Loading

0 comments on commit d4cb929

Please sign in to comment.