Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(get-workers): use blockingConnection to set clientName #1255

Merged
merged 1 commit into from
May 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/classes/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ export class Worker<
if (!this.running) {
try {
this.running = true;
const client = await this.client;
const client = await this.blockingConnection.client;

if (this.closing) {
return;
Expand Down
57 changes: 57 additions & 0 deletions tests/test_getters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,33 @@ describe('Jobs getters', function () {
await queueScheduler.close();
await queueScheduler2.close();
});

describe('when sharing connection', () => {
it('gets all queueSchedulers for this queue', async function () {
const ioredisConnection = new IORedis({ maxRetriesPerRequest: null });
const queueScheduler = new QueueScheduler(queueName, {
connection: ioredisConnection,
});
await queueScheduler.waitUntilReady();
await delay(10);

const queueSchedulers = await queue.getQueueSchedulers();
expect(queueSchedulers).to.have.length(1);

const queueScheduler2 = new QueueScheduler(queueName, {
connection: ioredisConnection,
});
await queueScheduler2.waitUntilReady();
await delay(10);

const nextQueueSchedulers = await queue.getQueueSchedulers();
expect(nextQueueSchedulers).to.have.length(2);

await queueScheduler.close();
await queueScheduler2.close();
await ioredisConnection.quit();
});
});
});

describe('.getWorkers', () => {
Expand Down Expand Up @@ -114,6 +141,36 @@ describe('Jobs getters', function () {
await worker2.close();
await removeAllQueueData(new IORedis(), queueName2);
});

describe('when sharing connection', () => {
it('gets all workers for this queue only', async function () {
const ioredisConnection = new IORedis({ maxRetriesPerRequest: null });
const worker = new Worker(queueName, async () => {}, {
connection: ioredisConnection,
});
const queueScheduler = new QueueScheduler(queueName, { connection });
await worker.waitUntilReady();
await queueScheduler.waitUntilReady();
await delay(10);

const workers = await queue.getWorkers();
expect(workers).to.have.length(1);

const worker2 = new Worker(queueName, async () => {}, {
connection: ioredisConnection,
});
await worker2.waitUntilReady();
await delay(10);

const nextWorkers = await queue.getWorkers();
expect(nextWorkers).to.have.length(2);

await worker.close();
await worker2.close();
await queueScheduler.close();
await ioredisConnection.quit();
});
});
});

it('should get waiting jobs', async function () {
Expand Down