2009-10-31 19:02:30 +01:00
|
|
|
process.mixin(require("./common"));
|
2009-06-08 19:10:23 +02:00
|
|
|
|
2009-09-23 16:39:43 +02:00
|
|
|
var WINDOW = 200; // why is does this need to be so big?
|
2009-06-08 19:10:23 +02:00
|
|
|
|
|
|
|
var interval_count = 0;
|
|
|
|
var setTimeout_called = false;
|
|
|
|
|
2009-08-26 18:22:00 +02:00
|
|
|
assertInstanceof(setTimeout, Function);
|
|
|
|
var starttime = new Date;
|
|
|
|
|
|
|
|
setTimeout(function () {
|
|
|
|
var endtime = new Date;
|
2009-09-23 16:39:43 +02:00
|
|
|
|
2009-08-26 18:22:00 +02:00
|
|
|
var diff = endtime - starttime;
|
|
|
|
if (diff < 0) diff = -diff;
|
2009-09-23 16:39:43 +02:00
|
|
|
puts("diff: " + diff);
|
|
|
|
|
2009-08-26 18:22:00 +02:00
|
|
|
assertTrue(1000 - WINDOW < diff && diff < 1000 + WINDOW);
|
|
|
|
setTimeout_called = true;
|
|
|
|
}, 1000);
|
|
|
|
|
|
|
|
// this timer shouldn't execute
|
|
|
|
var id = setTimeout(function () { assertTrue(false); }, 500);
|
|
|
|
clearTimeout(id);
|
|
|
|
|
|
|
|
setInterval(function () {
|
|
|
|
interval_count += 1;
|
|
|
|
var endtime = new Date;
|
2009-09-23 16:39:43 +02:00
|
|
|
|
2009-08-26 18:22:00 +02:00
|
|
|
var diff = endtime - starttime;
|
|
|
|
if (diff < 0) diff = -diff;
|
2009-09-23 16:39:43 +02:00
|
|
|
puts("diff: " + diff);
|
2009-08-26 18:22:00 +02:00
|
|
|
|
|
|
|
var t = interval_count * 1000;
|
|
|
|
|
|
|
|
assertTrue(t - WINDOW < diff && diff < t + WINDOW);
|
2009-08-26 22:03:19 +02:00
|
|
|
|
2009-08-26 18:22:00 +02:00
|
|
|
assertTrue(interval_count <= 3);
|
|
|
|
if (interval_count == 3)
|
|
|
|
clearInterval(this);
|
|
|
|
}, 1000);
|
2009-06-08 19:10:23 +02:00
|
|
|
|
2009-08-26 18:51:04 +02:00
|
|
|
process.addListener("exit", function () {
|
2009-06-08 19:10:23 +02:00
|
|
|
assertTrue(setTimeout_called);
|
|
|
|
assertEquals(3, interval_count);
|
2009-08-26 18:51:04 +02:00
|
|
|
});
|