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
This commit is contained in:
parent
e108ff4da7
commit
a18c9b7dde
@ -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…
x
Reference in New Issue
Block a user