test: fix test-domain-exit-dispose-again
test-domain-exit-dispose-again had been written for node v0.10.x, and was using the fact that callbacks scheduled with `process.nextTick` wouldn't run if the domain attached to it was disposed. This is not longer the case, and as a result the test would not catch any regression: it would always pass. This change rewrites that test to check that the current domain is cleared properly when processing the rest of the timers list if a timer's callback throws an error. This makes the test fail without the original fix, and pass with the original fix, as expected. PR: #3990 PR-URL: https://github.com/nodejs/node/pull/3990 Reviewed-By: Trevor Norris <trev.norris@gmail.com>
This commit is contained in:
parent
8b75030249
commit
1c85849973
@ -1,56 +1,39 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
var common = require('../common');
|
const common = require('../common');
|
||||||
var assert = require('assert');
|
const assert = require('assert');
|
||||||
var domain = require('domain');
|
const domain = require('domain');
|
||||||
var disposalFailed = false;
|
|
||||||
|
|
||||||
// no matter what happens, we should increment a 10 times.
|
// Use the same timeout value so that both timers' callbacks are called during
|
||||||
var a = 0;
|
// the same invocation of the underlying native timer's callback (listOnTimeout
|
||||||
log();
|
// in lib/timers.js).
|
||||||
function log() {
|
|
||||||
console.log(a++, process.domain);
|
|
||||||
if (a < 10) setTimeout(log, 20);
|
|
||||||
}
|
|
||||||
|
|
||||||
var secondTimerRan = false;
|
|
||||||
|
|
||||||
// in 50ms we'll throw an error.
|
|
||||||
setTimeout(err, 50);
|
setTimeout(err, 50);
|
||||||
setTimeout(secondTimer, 50);
|
setTimeout(common.mustCall(secondTimer), 50);
|
||||||
|
|
||||||
function err() {
|
function err() {
|
||||||
var d = domain.create();
|
const d = domain.create();
|
||||||
d.on('error', handle);
|
d.on('error', handleDomainError);
|
||||||
d.run(err2);
|
d.run(err2);
|
||||||
|
|
||||||
function err2() {
|
function err2() {
|
||||||
// this timeout should never be called, since the domain gets
|
|
||||||
// disposed when the error happens.
|
|
||||||
setTimeout(function() {
|
|
||||||
console.error('This should not happen.');
|
|
||||||
disposalFailed = true;
|
|
||||||
process.exit(1);
|
|
||||||
});
|
|
||||||
|
|
||||||
// this function doesn't exist, and throws an error as a result.
|
// this function doesn't exist, and throws an error as a result.
|
||||||
err3();
|
err3();
|
||||||
}
|
}
|
||||||
|
|
||||||
function handle(e) {
|
function handleDomainError(e) {
|
||||||
// this should clean up everything properly.
|
// In the domain's error handler, the current active domain should be the
|
||||||
d.dispose();
|
// domain within which the error was thrown.
|
||||||
console.error(e);
|
assert.equal(process.domain, d);
|
||||||
console.error('in handler', process.domain, process.domain === d);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function secondTimer() {
|
function secondTimer() {
|
||||||
console.log('In second timer');
|
// secondTimer was scheduled before any domain had been created, so its
|
||||||
secondTimerRan = true;
|
// callback should not have any active domain set when it runs.
|
||||||
|
// Do not use assert here, as it throws errors and if a domain with an error
|
||||||
|
// handler is active, then asserting wouldn't make the test fail.
|
||||||
|
if (process.domain !== null) {
|
||||||
|
console.log('process.domain should be null, but instead is:',
|
||||||
|
process.domain);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
process.on('exit', function() {
|
|
||||||
assert.equal(a, 10);
|
|
||||||
assert.equal(disposalFailed, false);
|
|
||||||
assert(secondTimerRan);
|
|
||||||
console.log('ok');
|
|
||||||
});
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user