Skip to content

Commit 6896e4c

Browse files
committed
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 e760a1b commit 6896e4c

File tree

4 files changed

+13
-36
lines changed

4 files changed

+13
-36
lines changed

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@ 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

1412
let ticked = false;
1513

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

Lines changed: 2 additions & 2 deletions
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,8 +17,6 @@
1517
* it 100%.
1618
*/
1719

18-
require('../common');
19-
2020
const TIMEOUT_DELAY = 1.1;
2121
const NB_TIMEOUTS_FIRED = 50;
2222

test/parallel/test-timers-ordering.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
'use strict';
22
require('../common');
33
const assert = require('assert');
4-
const Timer = process.binding('timer_wrap').Timer;
54

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

88
let last_i = 0;
Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,19 @@
11
'use strict';
2-
require('../common');
2+
const common = require('../common');
33
const assert = require('assert');
44

5-
let exceptions = 0;
6-
let timer1 = 0;
7-
let timer2 = 0;
5+
const errorMsg = 'BAM!';
86

97
// 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);
8+
setTimeout(common.mustCall(function() {
9+
throw new Error(errorMsg);
10+
}), 1);
1611

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

2515
function uncaughtException(err) {
26-
console.error('uncaught handler');
27-
assert.strictEqual(err.message, 'BAM!');
28-
exceptions++;
16+
assert.strictEqual(err.message, errorMsg);
2917
}
30-
process.on('uncaughtException', uncaughtException);
3118

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

0 commit comments

Comments
 (0)