test: refactor several parallel/test-timer tests
Change var to const/let. Simplify test-timers-uncaught-exception. PR-URL: https://github.com/nodejs/node/pull/10524 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
This commit is contained in:
parent
7a46b992d2
commit
7c77932fa2
@ -7,7 +7,7 @@ function range(n) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function timeout(nargs) {
|
function timeout(nargs) {
|
||||||
var args = range(nargs);
|
const args = range(nargs);
|
||||||
setTimeout.apply(null, [callback, 1].concat(args));
|
setTimeout.apply(null, [callback, 1].concat(args));
|
||||||
|
|
||||||
function callback() {
|
function callback() {
|
||||||
@ -17,8 +17,8 @@ function timeout(nargs) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function interval(nargs) {
|
function interval(nargs) {
|
||||||
var args = range(nargs);
|
const args = range(nargs);
|
||||||
var timer = setTimeout.apply(null, [callback, 1].concat(args));
|
const timer = setTimeout.apply(null, [callback, 1].concat(args));
|
||||||
|
|
||||||
function callback() {
|
function callback() {
|
||||||
clearInterval(timer);
|
clearInterval(timer);
|
||||||
|
@ -6,15 +6,13 @@ const assert = require('assert');
|
|||||||
// but immediates queued while processing the current queue should happen
|
// but immediates queued while processing the current queue should happen
|
||||||
// on the next turn of the event loop.
|
// on the next turn of the event loop.
|
||||||
|
|
||||||
// in v0.10 hit should be 1, because we only process one cb per turn
|
// hit should be the exact same size of QUEUE, if we're letting things
|
||||||
// in v0.11 and beyond it should be the exact same size of QUEUE
|
// recursively add to the immediate QUEUE hit will be > QUEUE
|
||||||
// if we're letting things recursively add to the immediate QUEUE hit will be
|
|
||||||
// > QUEUE
|
|
||||||
|
|
||||||
var ticked = false;
|
let ticked = false;
|
||||||
|
|
||||||
var hit = 0;
|
let hit = 0;
|
||||||
var QUEUE = 1000;
|
const QUEUE = 1000;
|
||||||
|
|
||||||
function run() {
|
function run() {
|
||||||
if (hit === 0)
|
if (hit === 0)
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
require('../common');
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This test makes sure that non-integer timer delays do not make the process
|
* This test makes sure that non-integer timer delays do not make the process
|
||||||
* hang. See https://github.com/joyent/node/issues/8065 and
|
* hang. See https://github.com/joyent/node/issues/8065 and
|
||||||
@ -15,13 +17,11 @@
|
|||||||
* it 100%.
|
* it 100%.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
require('../common');
|
const TIMEOUT_DELAY = 1.1;
|
||||||
|
const NB_TIMEOUTS_FIRED = 50;
|
||||||
|
|
||||||
var TIMEOUT_DELAY = 1.1;
|
let nbTimeoutFired = 0;
|
||||||
var NB_TIMEOUTS_FIRED = 50;
|
const interval = setInterval(function() {
|
||||||
|
|
||||||
var nbTimeoutFired = 0;
|
|
||||||
var interval = setInterval(function() {
|
|
||||||
++nbTimeoutFired;
|
++nbTimeoutFired;
|
||||||
if (nbTimeoutFired === NB_TIMEOUTS_FIRED) {
|
if (nbTimeoutFired === NB_TIMEOUTS_FIRED) {
|
||||||
clearInterval(interval);
|
clearInterval(interval);
|
||||||
|
@ -1,22 +1,22 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
require('../common');
|
require('../common');
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
var Timer = process.binding('timer_wrap').Timer;
|
|
||||||
|
|
||||||
var N = 30;
|
const Timer = process.binding('timer_wrap').Timer;
|
||||||
|
const N = 30;
|
||||||
|
|
||||||
var last_i = 0;
|
let last_i = 0;
|
||||||
var last_ts = 0;
|
let last_ts = 0;
|
||||||
|
|
||||||
var f = function(i) {
|
const f = function(i) {
|
||||||
if (i <= N) {
|
if (i <= N) {
|
||||||
// check order
|
// check order
|
||||||
assert.equal(i, last_i + 1, 'order is broken: ' + i + ' != ' +
|
assert.strictEqual(i, last_i + 1, 'order is broken: ' + i + ' != ' +
|
||||||
last_i + ' + 1');
|
last_i + ' + 1');
|
||||||
last_i = i;
|
last_i = i;
|
||||||
|
|
||||||
// check that this iteration is fired at least 1ms later than the previous
|
// check that this iteration is fired at least 1ms later than the previous
|
||||||
var now = Timer.now();
|
const now = Timer.now();
|
||||||
console.log(i, now);
|
console.log(i, now);
|
||||||
assert(now >= last_ts + 1,
|
assert(now >= last_ts + 1,
|
||||||
'current ts ' + now + ' < prev ts ' + last_ts + ' + 1');
|
'current ts ' + now + ' < prev ts ' + last_ts + ' + 1');
|
||||||
|
@ -1,40 +1,18 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
require('../common');
|
const common = require('../common');
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
|
const errorMsg = 'BAM!';
|
||||||
var exceptions = 0;
|
|
||||||
var timer1 = 0;
|
|
||||||
var timer2 = 0;
|
|
||||||
|
|
||||||
// the first timer throws...
|
// the first timer throws...
|
||||||
console.error('set first timer');
|
setTimeout(common.mustCall(function() {
|
||||||
setTimeout(function() {
|
throw new Error(errorMsg);
|
||||||
console.error('first timer');
|
}), 1);
|
||||||
timer1++;
|
|
||||||
throw new Error('BAM!');
|
|
||||||
}, 100);
|
|
||||||
|
|
||||||
// ...but the second one should still run
|
// ...but the second one should still run
|
||||||
console.error('set second timer');
|
setTimeout(common.mustCall(function() {}), 1);
|
||||||
setTimeout(function() {
|
|
||||||
console.error('second timer');
|
|
||||||
assert.equal(timer1, 1);
|
|
||||||
timer2++;
|
|
||||||
}, 100);
|
|
||||||
|
|
||||||
function uncaughtException(err) {
|
function uncaughtException(err) {
|
||||||
console.error('uncaught handler');
|
assert.strictEqual(err.message, errorMsg);
|
||||||
assert.equal(err.message, 'BAM!');
|
|
||||||
exceptions++;
|
|
||||||
}
|
}
|
||||||
process.on('uncaughtException', uncaughtException);
|
|
||||||
|
|
||||||
var exited = false;
|
process.on('uncaughtException', common.mustCall(uncaughtException));
|
||||||
process.on('exit', function() {
|
|
||||||
assert(!exited);
|
|
||||||
exited = true;
|
|
||||||
process.removeListener('uncaughtException', uncaughtException);
|
|
||||||
assert.equal(exceptions, 1);
|
|
||||||
assert.equal(timer1, 1);
|
|
||||||
assert.equal(timer2, 1);
|
|
||||||
});
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user