forked from kelektiv/node-cron
-
Notifications
You must be signed in to change notification settings - Fork 0
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
PR to view bug replay #1
Open
psixdev
wants to merge
1
commit into
master
Choose a base branch
from
feature/use-sinon-to-repeat-bug
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
const { CronJob } = require('./lib/cron'); | ||
|
||
const job = new CronJob( | ||
'*/5 * * * * *', | ||
() => { | ||
console.log('current time is', new Date().toISOString()); | ||
}, | ||
() => { | ||
console.log('\x1b[41m%s\x1b[0m', 'job was stopped'); | ||
process.exit(1); | ||
}, | ||
true, | ||
'Europe/Moscow' | ||
); | ||
|
||
job.start(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,19 @@ | ||
const sinon = require('sinon'); | ||
|
||
const clock = sinon.useFakeTimers(Date.now()); | ||
|
||
function scheduleTick() { | ||
process.nextTick(() => { | ||
clock.tick(1); | ||
// clock.tick(0.001); | ||
scheduleTick(); | ||
}); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. setInterval not working when fake timers exists |
||
|
||
scheduleTick(); | ||
|
||
let SEND_AT_CALLS = 0; | ||
|
||
const CONSTRAINTS = [ | ||
[0, 59], | ||
[0, 59], | ||
|
@@ -147,6 +163,20 @@ function CronTime(luxon) { | |
*/ | ||
sendAt: function (i) { | ||
var date = this.realDate ? this.source : luxon.DateTime.local(); | ||
|
||
if (SEND_AT_CALLS === 5) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The step is chosen absolutely randomly :) |
||
console.log('\x1b[40m\x1b[31m%s\x1b[0m', 'add 7s to current time'); | ||
clock.tick(7000); | ||
} | ||
|
||
if (SEND_AT_CALLS === 7) { | ||
console.log('\x1b[42m%s\x1b[0m', 'failed to repeat the bug'); | ||
process.exit(0); | ||
} | ||
|
||
|
||
SEND_AT_CALLS++; | ||
|
||
if (this.zone) { | ||
date = date.setZone(this.zone); | ||
} | ||
|
@@ -199,7 +229,9 @@ function CronTime(luxon) { | |
* Get the number of milliseconds in the future at which to fire our callbacks. | ||
*/ | ||
getTimeout: function () { | ||
return Math.max(-1, this.sendAt() - luxon.DateTime.local()); | ||
const timeout = Math.max(-1, this.sendAt() - luxon.DateTime.local()); | ||
console.log('timeout is', timeout); | ||
return timeout; | ||
}, | ||
|
||
/** | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Used sinon to simulate the time change on the machine at the right moment