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: tests #3185

Closed
wants to merge 1 commit into from
Closed
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
29 changes: 15 additions & 14 deletions ts/test/session/unit/utils/job_runner/JobRunner_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ function getFakeSleepForJobPersisted(timestamp: number): FakeSleepJobData {
return getFakeSleepForJob(timestamp).serializeJob();
}

const multiJobSleepDuration = 5000;

function getFakeSleepForMultiJob({
timestamp,
identifier,
Expand All @@ -41,7 +43,7 @@ function getFakeSleepForMultiJob({
nextAttemptTimestamp: timestamp || 3000,
currentRetry: 0,
returnResult: isUndefined(returnResult) ? true : returnResult,
sleepDuration: 5000,
sleepDuration: multiJobSleepDuration,
});
return job;
}
Expand Down Expand Up @@ -388,35 +390,36 @@ describe('JobRunner', () => {

it('does await if there are jobs and one is started', async () => {
await runnerMulti.loadJobsFromDb();
const job = getFakeSleepForMultiJob({ timestamp: 100, returnResult: false }); // this job keeps failing
const job = getFakeSleepForMultiJob({ timestamp: 100, returnResult: false }); // this job keeps failing, on purpose
runnerMulti.startProcessing();
clock.tick(110);
// job should be started right away
const result = await runnerMulti.addJob(job);
expect(runnerMulti.getJobList()).to.deep.eq([job.serializeJob()]);

expect(result).to.eq('job_started');
clock.tick(5010);
// the job takes 5 fake seconds, tick a bit less than that and then wait for it to finish
clock.tick(multiJobSleepDuration - 100);
await runnerMulti.waitCurrentJob();
const jobUpdated = {
...job.serializeJob(),
nextAttemptTimestamp: clock.now + 10000,
nextAttemptTimestamp: clock.now + job.persistedData.delayBetweenRetries,
currentRetry: 1,
};
// just give time for the runnerMulti to pick up a new job
await sleepFor(100);
// just give time for the runnerMulti to sort out the job finishing
await sleepFor(10);

// the job failed, so the job should still be there
// the job failed, so the job should still be there with a currentRetry of 1
expect(runnerMulti.getJobList()).to.deep.eq([jobUpdated]);

// that job should be retried now
clock.tick(11000);
await runner.waitCurrentJob();
// job should have been rescheduled after 10s, so if we tick 10000 + 4900ms, we should have that job about to be done again
clock.tick(job.persistedData.delayBetweenRetries + multiJobSleepDuration - 100);
await runnerMulti.waitCurrentJob();
await sleepFor(10);

const jobUpdated2 = {
...job.serializeJob(),
nextAttemptTimestamp: clock.now + job.persistedData.delayBetweenRetries,
nextAttemptTimestamp: clock.now + job.persistedData.delayBetweenRetries - 20, // the 20 is for the sleepFor we had earlier
currentRetry: 2,
};

Expand All @@ -425,11 +428,9 @@ describe('JobRunner', () => {
expect(runnerMulti.getJobList()).to.deep.eq([jobUpdated2]);

// that job should be retried one more time and then removed from the list of jobs to be run
clock.tick(11000);
clock.tick(job.persistedData.delayBetweenRetries + multiJobSleepDuration - 100);
await runnerMulti.waitCurrentJob();
await sleepFor(10);

await runnerMulti.waitCurrentJob();
expect(runnerMulti.getJobList()).to.deep.eq([]);
});
});
Expand Down
Loading