Skip to content

Commit

Permalink
Revert "src: don't allow scheduling tests in the past"
Browse files Browse the repository at this point in the history
This reverts commit c1afc663b1b75a32a62b4d61c45990ffa335ed68.
  • Loading branch information
jonhester committed May 31, 2015
1 parent 163e9ec commit 722178f
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 84 deletions.
8 changes: 3 additions & 5 deletions lib/schedule.js
Expand Up @@ -159,11 +159,9 @@ Job.prototype.schedule = function(spec) {
}

if (spec instanceof Date) {
if (spec.getTime() >= Date.now()) {
inv = new Invocation(self, spec);
scheduleInvocation(inv);
success = self.trackInvocation(inv);
}
inv = new Invocation(self, spec);
scheduleInvocation(inv);
success = self.trackInvocation(inv);
} else if (type === 'object') {
if (!(spec instanceof RecurrenceRule)) {
var r = new RecurrenceRule();
Expand Down
71 changes: 30 additions & 41 deletions test/convenience-method-test.js
Expand Up @@ -45,21 +45,17 @@ module.exports = {
}, 1250);

clock.tick(1250);
},
"Won't run job if scheduled in the past": function(test) {
test.expect(1);
var job = schedule.scheduleJob(new Date(Date.now() - 3000), function() {
}
/*,
"Won't run job if scheduled in the past": function(test) {
schedule.scheduleJob(new Date(Date.now() - 3000), function() {
test.ok(false);
});

test.equal(job, null);
});
setTimeout(function() {
setTimeout(function() {
test.done();
}, 1000);

clock.tick(1000);
}
}, 1000);
}*/
},
".scheduleJob(RecurrenceRule, fn)": {
"Runs job at interval based on recur rule, repeating indefinitely": function(test) {
Expand Down Expand Up @@ -100,24 +96,21 @@ module.exports = {
}, 3250);

clock.tick(3250);
},
"Doesn't invoke job if recur rule schedules it in the past": function(test) {
test.expect(1);
var rule = new schedule.RecurrenceRule();
rule.year = 1960;
}
/*,
"Doesn't invoke job if recur rule schedules it in the past": function(test) {
var rule = new schedule.RecurrenceRule();
rule.year = 2000;
var job = schedule.scheduleJob(rule, function() {
var job = schedule.scheduleJob(rule, function() {
test.ok(false);
});

test.equal(job, null);
});
setTimeout(function() {
setTimeout(function() {
job.cancel();
test.done();
}, 1000);

clock.tick(1000);
}
}, 1000);
}*/
},
".scheduleJob({...}, fn)": {
"Runs job at interval based on object, repeating indefinitely": function(test) {
Expand Down Expand Up @@ -159,24 +152,20 @@ module.exports = {
}, 2250);

clock.tick(2250);
},
"Doesn't invoke job if object schedules it in the past": function(test) {
test.expect(1);

var job = schedule.scheduleJob({
year: 1960
}, function() {
}
/*,
"Doesn't invoke job if object schedules it in the past": function(test) {
var job = new schedule.scheduleJob({
year: 2000
}, function() {
test.ok(false);
});

test.equal(job, null);
});
setTimeout(function() {
setTimeout(function() {
job.cancel();
test.done();
}, 1000);

clock.tick(1000);
}
}, 1000);
}*/
},
".cancelJob(Job)": {
"Prevents all future invocations of Job passed in": function(test) {
Expand Down
69 changes: 31 additions & 38 deletions test/job-test.js
Expand Up @@ -70,50 +70,45 @@ module.exports = {
});

job.runOnDate(new Date(Date.now() + 3000));

setTimeout(function() {
test.done();
}, 3250);

clock.tick(3250);
},
/* No jobs will run after this test for some reason - hide for now
"Won't run job if scheduled in the past": function(test) {
test.expect(0);
var job = new schedule.Job(function() {
test.ok(false);
test.ok(true);
});
job.schedule(new Date(Date.now() - 3000));
setTimeout(function() {
test.done();
test.done();
}, 1000);

clock.tick(1000);
},
"Jobs still run after scheduling a Job in the past": function(test) {
test.expect(1);
var pastJob = new schedule.Job(function() {
// Should not run, blow up if it does
test.ok(false);
test.ok(false);
});

pastJob.schedule(new Date(Date.now() - 3000));
var job = new schedule.Job(function() {
test.ok(true);
test.ok(true);
});

job.schedule(new Date(Date.now() + 3000));
setTimeout(function() {
test.done();
test.done();
}, 3250);

clock.tick(3250);
},
},*/
"Job emits 'scheduled' event with 'run at' Date": function(test) {
test.expect(1);

Expand Down Expand Up @@ -172,26 +167,25 @@ module.exports = {
}, 3250);

clock.tick(3250);
},
"Doesn't invoke job if recur rule schedules it in the past": function(test) {
test.expect(0);
}
/*,
"Doesn't invoke job if recur rule schedules it in the past": function(test) {
test.expect(0);
var job = new schedule.Job(function() {
var job = new schedule.Job(function() {
test.ok(false);
});
});
var rule = new schedule.RecurrenceRule();
rule.year = 2000;
var rule = new schedule.RecurrenceRule();
rule.year = 2000;
job.schedule(rule);
job.schedule(rule);
setTimeout(function() {
setTimeout(function() {
job.cancel();
test.done();
}, 1000);

clock.tick(1000);
}
}, 1000);
}*/
},
"#schedule({...})": {
"Runs job at interval based on object, repeating indefinitely": function(test) {
Expand Down Expand Up @@ -233,25 +227,24 @@ module.exports = {
}, 3250);

clock.tick(3250);
},
"Doesn't invoke job if object schedules it in the past": function(test) {
test.expect(0);
}
/*,
"Doesn't invoke job if object schedules it in the past": function(test) {
test.expect(0);
var job = new schedule.Job(function() {
var job = new schedule.Job(function() {
test.ok(false);
});
});
job.schedule({
job.schedule({
year: 2000
});
});
setTimeout(function() {
setTimeout(function() {
job.cancel();
test.done();
}, 1000);

clock.tick(1000);
}
}, 1000);
}*/
},
"#cancel": {
"Prevents all future invocations": function(test) {
Expand Down

0 comments on commit 722178f

Please sign in to comment.