Browse Source

test: timers-ordering should be more precise

Internally we use hrtime to schedule when a timer will fire, to avoid
the perils of clock drift or other external operation making time go
backward. The timers ordering test should use the same timing mechanism
v0.11.12-release
Timothy J Fontaine 11 years ago
parent
commit
a18c9b7dde
  1. 6
      test/simple/test-timers-ordering.js

6
test/simple/test-timers-ordering.js

@ -21,13 +21,15 @@
var common = require('../common');
var assert = require('assert');
var Timer = process.binding('timer_wrap').Timer;
var i;
var N = 30;
var last_i = 0;
var last_ts = 0;
var start = Date.now();
var start = Timer.now();
var f = function(i) {
if (i <= N) {
@ -36,7 +38,7 @@ var f = function(i) {
last_i = i;
// check that this iteration is fired at least 1ms later than the previous
var now = Date.now();
var now = Timer.now();
console.log(i, now);
assert(now >= last_ts + 1, 'current ts ' + now + ' < prev ts ' + last_ts + ' + 1');
last_ts = now;

Loading…
Cancel
Save