Skip to content

Commit

Permalink
test: refactor several parallel/test-timer tests
Browse files Browse the repository at this point in the history
Change var to const/let. Simplify test-timers-uncaught-exception.

Backport-PR-URL: #12401
PR-URL: #10524
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
  • Loading branch information
BethGriggs authored and MylesBorins committed Apr 24, 2017
1 parent cd78a2b commit aae3765
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 36 deletions.
6 changes: 2 additions & 4 deletions test/parallel/test-timers-immediate-queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@ const assert = require('assert');
// but immediates queued while processing the current queue should happen
// on the next turn of the event loop.

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

let ticked = false;

Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-timers-non-integer-delay.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
'use strict';
require('../common');

/*
* This test makes sure that non-integer timer delays do not make the process
* hang. See https://github.com/joyent/node/issues/8065 and
Expand All @@ -15,8 +17,6 @@
* it 100%.
*/

require('../common');

const TIMEOUT_DELAY = 1.1;
const NB_TIMEOUTS_FIRED = 50;

Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-timers-ordering.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use strict';
require('../common');
const assert = require('assert');
const Timer = process.binding('timer_wrap').Timer;

const Timer = process.binding('timer_wrap').Timer;
const N = 30;

let last_i = 0;
Expand Down
37 changes: 8 additions & 29 deletions test/parallel/test-timers-uncaught-exception.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,19 @@
'use strict';
require('../common');
const common = require('../common');
const assert = require('assert');

let exceptions = 0;
let timer1 = 0;
let timer2 = 0;
const errorMsg = 'BAM!';

// the first timer throws...
console.error('set first timer');
setTimeout(function() {
console.error('first timer');
timer1++;
throw new Error('BAM!');
}, 100);
setTimeout(common.mustCall(function() {
throw new Error(errorMsg);
}), 1);

// ...but the second one should still run
console.error('set second timer');
setTimeout(function() {
console.error('second timer');
assert.strictEqual(timer1, 1);
timer2++;
}, 100);
setTimeout(common.mustCall(function() {}), 1);

function uncaughtException(err) {
console.error('uncaught handler');
assert.strictEqual(err.message, 'BAM!');
exceptions++;
assert.strictEqual(err.message, errorMsg);
}
process.on('uncaughtException', uncaughtException);

let exited = false;
process.on('exit', function() {
assert(!exited);
exited = true;
process.removeListener('uncaughtException', uncaughtException);
assert.strictEqual(exceptions, 1);
assert.strictEqual(timer1, 1);
assert.strictEqual(timer2, 1);
});
process.on('uncaughtException', common.mustCall(uncaughtException));

0 comments on commit aae3765

Please sign in to comment.