Skip to content

Commit

Permalink
chore: 4rd attempt to fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
roggervalf committed Dec 4, 2024
1 parent 7687688 commit aee5ded
Showing 1 changed file with 40 additions and 47 deletions.
87 changes: 40 additions & 47 deletions tests/test_job_scheduler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,11 @@ describe('Job Scheduler', function () {
const every = 100;
const date = new Date('2017-02-07 9:24:00');
this.clock.setSystemTime(date);
const worker = new Worker(
queueName,
async () => {
this.clock.tick(every);
},
{ autorun: false, connection, prefix },
);
const worker = new Worker(queueName, async () => {}, {
autorun: false,
connection,
prefix,
});
const delayStub = sinon.stub(worker, 'delay').callsFake(async () => {});
await worker.waitUntilReady();

Expand All @@ -143,6 +141,7 @@ describe('Job Scheduler', function () {
if (processed === 10) {
resolve();
}
this.clock.tick(every);
});
});

Expand Down Expand Up @@ -333,13 +332,11 @@ describe('Job Scheduler', function () {

const nextTick = 2 * ONE_SECOND + 100;

const worker = new Worker(
queueName,
async () => {
this.clock.tick(nextTick);
},
{ autorun: false, connection, prefix },
);
const worker = new Worker(queueName, async () => {}, {
autorun: false,
connection,
prefix,
});
const delayStub = sinon.stub(worker, 'delay').callsFake(async () => {});

const date = new Date('2017-02-07 9:24:00');
Expand Down Expand Up @@ -383,6 +380,7 @@ describe('Job Scheduler', function () {
if (counter == 5) {
resolve();
}
this.clock.tick(nextTick);
});
});

Expand All @@ -401,13 +399,11 @@ describe('Job Scheduler', function () {
const nextTick = 2 * ONE_SECOND + 500;
const delay = 5 * ONE_SECOND + 500;

const worker = new Worker(
queueName,
async () => {
this.clock.tick(nextTick);
},
{ autorun: false, connection, prefix },
);
const worker = new Worker(queueName, async () => {}, {
autorun: false,
connection,
prefix,
});
const delayStub = sinon.stub(worker, 'delay').callsFake(async () => {});

await queue.upsertJobScheduler(
Expand Down Expand Up @@ -435,6 +431,7 @@ describe('Job Scheduler', function () {
if (counter == 5) {
resolve();
}
this.clock.tick(nextTick);
});
});

Expand All @@ -454,13 +451,11 @@ describe('Job Scheduler', function () {
const nextTick = 2 * ONE_SECOND + 500;
const delay = 5 * ONE_SECOND + 500;

const worker = new Worker(
queueName,
async () => {
this.clock.tick(nextTick);
},
{ autorun: false, connection, prefix },
);
const worker = new Worker(queueName, async () => {}, {
autorun: false,
connection,
prefix,
});
const delayStub = sinon.stub(worker, 'delay').callsFake(async () => {});

await queue.upsertJobScheduler(
Expand Down Expand Up @@ -488,6 +483,7 @@ describe('Job Scheduler', function () {
if (counter == 5) {
resolve();
}
this.clock.tick(nextTick);
});
});

Expand Down Expand Up @@ -515,16 +511,14 @@ describe('Job Scheduler', function () {
const nextTick = 2 * ONE_SECOND + 500;
const delay = 5 * ONE_SECOND + 500;

const worker = new Worker(
queueName,
async () => {
this.clock.tick(nextTick);
},
{ autorun: false, connection, prefix },
);
const worker = new Worker(queueName2, async () => {}, {
autorun: false,
connection,
prefix,
});
const delayStub = sinon.stub(worker, 'delay').callsFake(async () => {});

await queue.upsertJobScheduler(
await queue2.upsertJobScheduler(
'test',
{
pattern: '*/2 * * * * *',
Expand All @@ -551,6 +545,7 @@ describe('Job Scheduler', function () {
expect(counts.completed).to.be.equal(0);
resolve();
}
this.clock.tick(nextTick);
});
});

Expand Down Expand Up @@ -776,13 +771,10 @@ describe('Job Scheduler', function () {
this.clock.setSystemTime(date);
const nextTick = 2 * ONE_SECOND;

const worker = new Worker(
queueName,
async () => {
this.clock.tick(nextTick);
},
{ connection, prefix },
);
const worker = new Worker(queueName, async () => {}, {
connection,
prefix,
});

let prev: Job;
let counter = 0;
Expand All @@ -802,6 +794,7 @@ describe('Job Scheduler', function () {
if (counter === 5) {
resolve();
}
this.clock.tick(nextTick);
} catch (err) {
reject(err);
}
Expand Down Expand Up @@ -831,8 +824,6 @@ describe('Job Scheduler', function () {
worker = new Worker(
queueName,
async (job: Job) => {
this.clock.tick(nextTick);

try {
expect(job.opts.delay).to.be.eq(0);
resolve();
Expand All @@ -859,14 +850,14 @@ describe('Job Scheduler', function () {

await worker!.close();

this.clock.tick(nextTick);

await queue.removeJobScheduler('repeat');

const processing2 = new Promise<void>((resolve, reject) => {
worker = new Worker(
queueName,
async (job: Job) => {
this.clock.tick(nextTick);

try {
expect(job.opts.delay).to.be.eq(0);
resolve();
Expand All @@ -889,6 +880,8 @@ describe('Job Scheduler', function () {

await processing2;

this.clock.tick(nextTick);

await worker!.close();
});

Expand Down

0 comments on commit aee5ded

Please sign in to comment.