Skip to content

Commit

Permalink
Recover missing test case + remove unnecessary renaming and comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
b0dea committed Nov 19, 2024
1 parent 8d66861 commit a1fb95b
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions test/unit/pulse.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,15 +206,19 @@ describe('Test Pulse', () => {
});

describe('Test resumeOnRestart', () => {
test('should enable resumeOnRestart by default', () => {
test('sets the default resumeOnRestart', () => {
expect(globalPulseInstance._resumeOnRestart).toBeTruthy();
});

test('should disable resumeOnRestart when set to false', () => {
test('sets the custom resumeOnRestart', () => {
globalPulseInstance.resumeOnRestart(false);
expect(globalPulseInstance._resumeOnRestart).toBeFalsy();
});

test('returns itself', () => {
expect(globalPulseInstance.resumeOnRestart(false)).toEqual(globalPulseInstance);
});

test('should not reschedule successfully finished non-recurring jobs', async () => {
const job = globalPulseInstance.create('sendEmail', { to: '[email protected]' });
job.attrs.lastFinishedAt = new Date();
Expand Down Expand Up @@ -305,14 +309,14 @@ describe('Test Pulse', () => {
const job = globalPulseInstance.create('processData', { data: 'sample' });
job.attrs.repeatInterval = '10 minutes';
job.attrs.lockedAt = new Date();
job.attrs.nextRunAt = new Date(Date.now() + 10000); // Next run in 10 seconds
job.attrs.nextRunAt = new Date(Date.now() + 10000);
await job.save();

await globalPulseInstance.resumeOnRestart();

const updatedJob = (await globalPulseInstance.jobs({ name: 'processData' }))[0];
expect(updatedJob.attrs.lockedAt).not.toBeNull(); // Job remains locked
expect(updatedJob.attrs.nextRunAt).not.toBeNull(); // Scheduling intact
expect(updatedJob.attrs.lockedAt).not.toBeNull();
expect(updatedJob.attrs.nextRunAt).not.toBeNull();
});

test('should handle interrupted recurring jobs after server recovery', async () => {
Expand All @@ -331,14 +335,14 @@ describe('Test Pulse', () => {

test('should not modify non-recurring jobs with lastFinishedAt in the past', async () => {
const job = globalPulseInstance.create('sendEmail', { to: '[email protected]' });
job.attrs.lastFinishedAt = new Date(Date.now() - 10000); // Finished 10 seconds ago
job.attrs.lastFinishedAt = new Date(Date.now() - 10000);
job.attrs.nextRunAt = null;
await job.save();

await globalPulseInstance.resumeOnRestart();

const updatedJob = (await globalPulseInstance.jobs({ name: 'sendEmail' }))[0];
expect(updatedJob.attrs.nextRunAt).toBeNull(); // Job remains finished
expect(updatedJob.attrs.nextRunAt).toBeNull();
});
});
});
Expand Down

0 comments on commit a1fb95b

Please sign in to comment.