Skip to content

Commit 0a2fb0d

Browse files
BethGriggsitaloacasas
authored andcommitted
test: refactor several parallel/test-timer tests
Change var to const/let. Simplify test-timers-uncaught-exception. PR-URL: #10524 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Gibson Fahnestock <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]>
1 parent dba8d20 commit 0a2fb0d

5 files changed

+29
-53
lines changed

test/parallel/test-timers-args.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ function range(n) {
77
}
88

99
function timeout(nargs) {
10-
var args = range(nargs);
10+
const args = range(nargs);
1111
setTimeout.apply(null, [callback, 1].concat(args));
1212

1313
function callback() {
@@ -17,8 +17,8 @@ function timeout(nargs) {
1717
}
1818

1919
function interval(nargs) {
20-
var args = range(nargs);
21-
var timer = setTimeout.apply(null, [callback, 1].concat(args));
20+
const args = range(nargs);
21+
const timer = setTimeout.apply(null, [callback, 1].concat(args));
2222

2323
function callback() {
2424
clearInterval(timer);

test/parallel/test-timers-immediate-queue.js

+5-7
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,13 @@ const assert = require('assert');
66
// but immediates queued while processing the current queue should happen
77
// on the next turn of the event loop.
88

9-
// in v0.10 hit should be 1, because we only process one cb per turn
10-
// in v0.11 and beyond it should be the exact same size of QUEUE
11-
// if we're letting things recursively add to the immediate QUEUE hit will be
12-
// > QUEUE
9+
// hit should be the exact same size of QUEUE, if we're letting things
10+
// recursively add to the immediate QUEUE hit will be > QUEUE
1311

14-
var ticked = false;
12+
let ticked = false;
1513

16-
var hit = 0;
17-
var QUEUE = 1000;
14+
let hit = 0;
15+
const QUEUE = 1000;
1816

1917
function run() {
2018
if (hit === 0)

test/parallel/test-timers-non-integer-delay.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
'use strict';
2+
require('../common');
3+
24
/*
35
* This test makes sure that non-integer timer delays do not make the process
46
* hang. See https://github.com/joyent/node/issues/8065 and
@@ -15,13 +17,11 @@
1517
* it 100%.
1618
*/
1719

18-
require('../common');
19-
20-
var TIMEOUT_DELAY = 1.1;
21-
var NB_TIMEOUTS_FIRED = 50;
20+
const TIMEOUT_DELAY = 1.1;
21+
const NB_TIMEOUTS_FIRED = 50;
2222

23-
var nbTimeoutFired = 0;
24-
var interval = setInterval(function() {
23+
let nbTimeoutFired = 0;
24+
const interval = setInterval(function() {
2525
++nbTimeoutFired;
2626
if (nbTimeoutFired === NB_TIMEOUTS_FIRED) {
2727
clearInterval(interval);

test/parallel/test-timers-ordering.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
'use strict';
22
require('../common');
33
const assert = require('assert');
4-
var Timer = process.binding('timer_wrap').Timer;
54

6-
var N = 30;
5+
const Timer = process.binding('timer_wrap').Timer;
6+
const N = 30;
77

8-
var last_i = 0;
9-
var last_ts = 0;
8+
let last_i = 0;
9+
let last_ts = 0;
1010

11-
var f = function(i) {
11+
const f = function(i) {
1212
if (i <= N) {
1313
// check order
14-
assert.equal(i, last_i + 1, 'order is broken: ' + i + ' != ' +
14+
assert.strictEqual(i, last_i + 1, 'order is broken: ' + i + ' != ' +
1515
last_i + ' + 1');
1616
last_i = i;
1717

1818
// check that this iteration is fired at least 1ms later than the previous
19-
var now = Timer.now();
19+
const now = Timer.now();
2020
console.log(i, now);
2121
assert(now >= last_ts + 1,
2222
'current ts ' + now + ' < prev ts ' + last_ts + ' + 1');
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,18 @@
11
'use strict';
2-
require('../common');
2+
const common = require('../common');
33
const assert = require('assert');
4-
5-
var exceptions = 0;
6-
var timer1 = 0;
7-
var timer2 = 0;
4+
const errorMsg = 'BAM!';
85

96
// the first timer throws...
10-
console.error('set first timer');
11-
setTimeout(function() {
12-
console.error('first timer');
13-
timer1++;
14-
throw new Error('BAM!');
15-
}, 100);
7+
setTimeout(common.mustCall(function() {
8+
throw new Error(errorMsg);
9+
}), 1);
1610

1711
// ...but the second one should still run
18-
console.error('set second timer');
19-
setTimeout(function() {
20-
console.error('second timer');
21-
assert.equal(timer1, 1);
22-
timer2++;
23-
}, 100);
12+
setTimeout(common.mustCall(function() {}), 1);
2413

2514
function uncaughtException(err) {
26-
console.error('uncaught handler');
27-
assert.equal(err.message, 'BAM!');
28-
exceptions++;
15+
assert.strictEqual(err.message, errorMsg);
2916
}
30-
process.on('uncaughtException', uncaughtException);
3117

32-
var exited = false;
33-
process.on('exit', function() {
34-
assert(!exited);
35-
exited = true;
36-
process.removeListener('uncaughtException', uncaughtException);
37-
assert.equal(exceptions, 1);
38-
assert.equal(timer1, 1);
39-
assert.equal(timer2, 1);
40-
});
18+
process.on('uncaughtException', common.mustCall(uncaughtException));

0 commit comments

Comments
 (0)