mirror of https://github.com/lukechilds/node.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
78 lines
1.7 KiB
78 lines
1.7 KiB
15 years ago
|
process.mixin(require("../common"));
|
||
16 years ago
|
|
||
15 years ago
|
var WINDOW = 200; // why is does this need to be so big?
|
||
16 years ago
|
|
||
|
var interval_count = 0;
|
||
|
var setTimeout_called = false;
|
||
|
|
||
15 years ago
|
assert.equal(true, setTimeout instanceof Function);
|
||
16 years ago
|
var starttime = new Date;
|
||
|
setTimeout(function () {
|
||
|
var endtime = new Date;
|
||
15 years ago
|
|
||
16 years ago
|
var diff = endtime - starttime;
|
||
15 years ago
|
assert.ok(diff > 0);
|
||
15 years ago
|
puts("diff: " + diff);
|
||
|
|
||
15 years ago
|
assert.equal(true, 1000 - WINDOW < diff && diff < 1000 + WINDOW);
|
||
16 years ago
|
setTimeout_called = true;
|
||
|
}, 1000);
|
||
|
|
||
|
// this timer shouldn't execute
|
||
15 years ago
|
var id = setTimeout(function () { assert.equal(true, false); }, 500);
|
||
16 years ago
|
clearTimeout(id);
|
||
|
|
||
|
setInterval(function () {
|
||
|
interval_count += 1;
|
||
|
var endtime = new Date;
|
||
15 years ago
|
|
||
16 years ago
|
var diff = endtime - starttime;
|
||
15 years ago
|
assert.ok(diff > 0);
|
||
15 years ago
|
puts("diff: " + diff);
|
||
16 years ago
|
|
||
|
var t = interval_count * 1000;
|
||
|
|
||
15 years ago
|
assert.equal(true, t - WINDOW < diff && diff < t + WINDOW);
|
||
16 years ago
|
|
||
15 years ago
|
assert.equal(true, interval_count <= 3);
|
||
16 years ago
|
if (interval_count == 3)
|
||
|
clearInterval(this);
|
||
|
}, 1000);
|
||
16 years ago
|
|
||
15 years ago
|
|
||
|
// Single param:
|
||
|
setTimeout(function(param){
|
||
|
assert.equal("test param", param);
|
||
|
}, 1000, "test param");
|
||
|
|
||
|
var interval_count2 = 0;
|
||
|
setInterval(function(param){
|
||
|
++interval_count2;
|
||
|
assert.equal("test param", param);
|
||
15 years ago
|
|
||
15 years ago
|
if(interval_count2 == 3)
|
||
|
clearInterval(this);
|
||
|
}, 1000, "test param");
|
||
|
|
||
|
|
||
|
// Multiple param
|
||
|
setTimeout(function(param1, param2){
|
||
|
assert.equal("param1", param1);
|
||
|
assert.equal("param2", param2);
|
||
|
}, 1000, "param1", "param2");
|
||
|
|
||
|
var interval_count3 = 0;
|
||
|
setInterval(function(param1, param2){
|
||
|
++interval_count3;
|
||
|
assert.equal("param1", param1);
|
||
|
assert.equal("param2", param2);
|
||
15 years ago
|
|
||
15 years ago
|
if(interval_count3 == 3)
|
||
|
clearInterval(this);
|
||
|
}, 1000, "param1", "param2");
|
||
|
|
||
16 years ago
|
process.addListener("exit", function () {
|
||
15 years ago
|
assert.equal(true, setTimeout_called);
|
||
|
assert.equal(3, interval_count);
|
||
16 years ago
|
});
|