Browse Source

test: refactor test-beforeexit-event

- replaced var with const/let.
- removed all console.log() statements.
- removed deaths and revivals vars.
- wrapped beforexit listener callbacks with
  common.mustCall().
- removed exit event listener.

PR-URL: https://github.com/nodejs/node/pull/10121
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: Brian White <mscdex@mscdex.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
v6
Rob Adelmann 8 years ago
committed by Anna Henningsen
parent
commit
89603835b3
No known key found for this signature in database GPG Key ID: D8B9F5AEAE84E4CF
  1. 40
      test/parallel/test-beforeexit-event.js

40
test/parallel/test-beforeexit-event.js

@ -1,42 +1,26 @@
'use strict'; 'use strict';
require('../common'); const common = require('../common');
var assert = require('assert'); const net = require('net');
var net = require('net');
var revivals = 0;
var deaths = 0;
process.on('beforeExit', function() { deaths++; }); process.once('beforeExit', common.mustCall(tryImmediate));
process.once('beforeExit', tryImmediate);
function tryImmediate() { function tryImmediate() {
console.log('set immediate'); setImmediate(common.mustCall(() => {
setImmediate(function() { process.once('beforeExit', common.mustCall(tryTimer));
revivals++; }));
process.once('beforeExit', tryTimer);
});
} }
function tryTimer() { function tryTimer() {
console.log('set a timeout'); setTimeout(common.mustCall(() => {
setTimeout(function() { process.once('beforeExit', common.mustCall(tryListen));
console.log('timeout cb, do another once beforeExit'); }), 1);
revivals++;
process.once('beforeExit', tryListen);
}, 1);
} }
function tryListen() { function tryListen() {
console.log('create a server');
net.createServer() net.createServer()
.listen(0) .listen(0)
.on('listening', function() { .on('listening', common.mustCall(function() {
revivals++;
this.close(); this.close();
}); process.on('beforeExit', common.mustCall(() => {}));
}));
} }
process.on('exit', function() {
assert.strictEqual(4, deaths);
assert.strictEqual(3, revivals);
});

Loading…
Cancel
Save