0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-30 23:43:09 +01:00
nodejs/test/parallel/test-timers-ordering.js
Roman Reiss f29762f4dd test: enable linting for tests
Enable linting for the test directory. A number of changes was made so
all tests conform the current rules used by lib and src directories. The
only exception for tests is that unreachable (dead) code is allowed.

test-fs-non-number-arguments-throw had to be excluded from the changes
because of a weird issue on Windows CI.

PR-URL: https://github.com/nodejs/io.js/pull/1721
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2015-05-19 21:21:27 +02:00

33 lines
707 B
JavaScript

'use strict';
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 = Timer.now();
var f = function(i) {
if (i <= N) {
// check order
assert.equal(i, last_i + 1, 'order is broken: ' + i + ' != ' +
last_i + ' + 1');
last_i = i;
// check that this iteration is fired at least 1ms later than the previous
var now = Timer.now();
console.log(i, now);
assert(now >= last_ts + 1,
'current ts ' + now + ' < prev ts ' + last_ts + ' + 1');
last_ts = now;
// schedule next iteration
setTimeout(f, 1, i + 1);
}
};
f(1);