Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
test: add tests for ensuring proper timer delays
Includes a passing test that should keep passing and an issue test to
be fixed.

Refs: #5426
Refs: #7346
Refs: #7386
  • Loading branch information
Fishrock123 committed Jun 24, 2016
commit e0ef4eabc00892a14e25f79a0f9c5bbcd7b52598
32 changes: 32 additions & 0 deletions test/known_issues/test-timers-sync-work-delay-problem.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
'use strict';

// See https://github.com/nodejs/node/issues/5426

const common = require('../common');
const TimerWrap = process.binding('timer_wrap').Timer;

function sleep(duration) {
var start = Date.now();
while ((Date.now() - start) < duration) {
for (var i = 0; i < 1e5;) i++;
}
}

var last = TimerWrap.now();
var count = 0;

const interval = setInterval(common.mustCall(repeat, 4), 500);

function repeat() {
if (++count === 4) {
clearInterval(interval);
}
const now = TimerWrap.now();

if (now < last + 500 - 200 || now > last + 500 + 200) {
common.fail(`\`repeat\` delay: ${count} (now: ${now}, last: ${last})\n` +
'is not within the margin of error.');
}
last = now;
sleep(500);
}
18 changes: 18 additions & 0 deletions test/parallel/test-timers-later-scheduled-delay.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
'use strict';

// See https://github.com/nodejs/node/issues/5426#issuecomment-228294811

const common = require('../common');
const TimerWrap = process.binding('timer_wrap').Timer;

setTimeout(common.mustCall(function first() {}), 1000);

setTimeout(function scheduleLast() {
setTimeout(common.mustCall(function last() {
const now = TimerWrap.now();

if (now < 1500 - 200 || now > 1500 + 200) {
common.fail('Delay for `last` is not within the margin of error.');
}
}), 1000);
}, 500);