cancel-long-running-jobs.js 553 B

123456789101112131415161718192021222324
  1. 'use strict';
  2. var schedule = require('../lib/schedule');
  3. module.exports = {
  4. 'Cancel Long Running Job': {
  5. 'should work even when recurring jobs are to be run on the past': function (test) {
  6. var ok = true;
  7. var job = schedule.scheduleJob('*/1 * * * * *', function () {
  8. test.ok(ok);
  9. var time = Date.now();
  10. while (ok && (Date.now() - time < 2000)) {
  11. }
  12. });
  13. test.ok(job);
  14. setTimeout(function () {
  15. job.cancel();
  16. test.done();
  17. ok = false;
  18. }, 2100);
  19. }
  20. }
  21. };