Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 11826 #11920

Closed
wants to merge 9 commits into from
6 changes: 6 additions & 0 deletions test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,12 @@ The realpath of the 'tmp' directory.

Name of the temp directory used by tests.

### childShouldNotThrowAndAbort()

This test makes sure that when using `--abort-on-uncaught-exception` and when
throwing an error from within a domain that has an error handler setup,
the process _does not_ abort.

### WPT

A port of parts of
Expand Down
22 changes: 22 additions & 0 deletions test/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,28 @@ exports.childShouldThrowAndAbort = function() {
});
};


// This function makes sure that when using --abort-on-uncaught-exception and
// when throwing an error from within a domain that has an error handler
// setup, the process _does not_ abort.

exports.childShouldNotThrowAndAbort = () => {
let testCmd = '';
if (!exports.isWindows) {
testCmd += 'ulimit -c 0 && ';
}

testCmd += `${process.argv[0]} --abort-on-uncaught-exception`;
testCmd += ` ${process.argv[1]} child`;

const child = child_process.exec(testCmd);
child.on('exit', (code, signal) => {
const errorMsg = `Test should have exited with exit code 0 but instead
exited with ${code} and signal ${signal}`;
assert.strictEqual(code, 0, errorMsg);
});
};

exports.ddCommand = function(filename, kilobytes) {
if (exports.isWindows) {
const p = path.resolve(exports.fixturesDir, 'create-file.js');
Expand Down
26 changes: 26 additions & 0 deletions test/parallel/test-domain-abort-on-uncaught-0.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
'use strict';

// This test makes sure that when using --abort-on-uncaught-exception and
// when throwing an error from within a domain that has an error handler
// setup, the process _does not_ abort.

const common = require('../common');
const domain = require('domain');

const nextTick = () => {
const d = domain.create();
d.once('error', common.mustCall(() => {}));

d.run(() => {
process.nextTick(() => {
throw new Error('exceptional!');
});
});
};


if (process.argv[2] === 'child') {
nextTick();
} else {
common.childShouldNotThrowAndAbort();
}
26 changes: 26 additions & 0 deletions test/parallel/test-domain-abort-on-uncaught-1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
'use strict';

// This test makes sure that when using --abort-on-uncaught-exception and
// when throwing an error from within a domain that has an error handler
// setup, the process _does not_ abort.

const common = require('../common');
const domain = require('domain');

const test = () => {
const d = domain.create();
d.once('error', common.mustCall(() => {}));

d.run(function() {
setTimeout(function() {
throw new Error('exceptional!');
}, 33);
});
};


if (process.argv[2] === 'child') {
test();
} else {
common.childShouldNotThrowAndAbort();
}
29 changes: 29 additions & 0 deletions test/parallel/test-domain-abort-on-uncaught-10.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
'use strict';

// This test makes sure that when using --abort-on-uncaught-exception and
// when throwing an error from within a domain that has an error handler
// setup, the process _does not_ abort.

const common = require('../common');
const domain = require('domain');

const test = () => {
const d = domain.create();
const d2 = domain.create();
d2.on('error', common.mustCall(() => {}));

d.run(function() {
d2.run(function() {
setImmediate(function() {
throw new Error('boom!');
});
});
});
};


if (process.argv[2] === 'child') {
test();
} else {
common.childShouldNotThrowAndAbort();
}
29 changes: 29 additions & 0 deletions test/parallel/test-domain-abort-on-uncaught-11.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
'use strict';

// This test makes sure that when using --abort-on-uncaught-exception and
// when throwing an error from within a domain that has an error handler
// setup, the process _does not_ abort.

const common = require('../common');
const domain = require('domain');

const test = () => {
const d = domain.create();
const d2 = domain.create();
d2.on('error', common.mustCall(() => {}));

d.run(function() {
d2.run(function() {
process.nextTick(function() {
throw new Error('boom!');
});
});
});
};


if (process.argv[2] === 'child') {
test();
} else {
common.childShouldNotThrowAndAbort();
}
31 changes: 31 additions & 0 deletions test/parallel/test-domain-abort-on-uncaught-12.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
'use strict';

// This test makes sure that when using --abort-on-uncaught-exception and
// when throwing an error from within a domain that has an error handler
// setup, the process _does not_ abort.

const common = require('../common');
const domain = require('domain');


const test = () => {
const d = domain.create();
const d2 = domain.create();
d2.on('error', common.mustCall(() => {}));

d.run(function() {
d2.run(function() {
const fs = require('fs');
fs.exists('/non/existing/file', function onExists(exists) {
throw new Error('boom!');
});
});
});
};


if (process.argv[2] === 'child') {
test();
} else {
common.childShouldNotThrowAndAbort();
}
25 changes: 25 additions & 0 deletions test/parallel/test-domain-abort-on-uncaught-2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
'use strict';

// This test makes sure that when using --abort-on-uncaught-exception and
// when throwing an error from within a domain that has an error handler
// setup, the process _does not_ abort.

const common = require('../common');
const domain = require('domain');

const test = () => {
const d = domain.create();
d.once('error', common.mustCall(() => {}));

d.run(function() {
setImmediate(function() {
throw new Error('boom!');
});
});
};

if (process.argv[2] === 'child') {
test();
} else {
common.childShouldNotThrowAndAbort();
}
28 changes: 28 additions & 0 deletions test/parallel/test-domain-abort-on-uncaught-3.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
'use strict';

// This test makes sure that when using --abort-on-uncaught-exception and
// when throwing an error from within a domain that has an error handler
// setup, the process _does not_ abort.

const common = require('../common');
const domain = require('domain');

const test = () => {
const d = domain.create();
d.once('error', common.mustCall(() => { }));

d.run(function() {
setTimeout(function() {
process.nextTick(function() {
throw new Error('exceptional!');
});
}, 33);
});
};


if (process.argv[2] === 'child') {
test();
} else {
common.childShouldNotThrowAndAbort();
}
24 changes: 24 additions & 0 deletions test/parallel/test-domain-abort-on-uncaught-4.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
'use strict';

// This test makes sure that when using --abort-on-uncaught-exception and
// when throwing an error from within a domain that has an error handler
// setup, the process _does not_ abort.

const common = require('../common');
const domain = require('domain');

const test = () => {
const d = domain.create();
d.once('error', common.mustCall(() => { }));

d.run(function() {
throw new Error('exceptional!');
});
};


if (process.argv[2] === 'child') {
test();
} else {
common.childShouldNotThrowAndAbort();
}
27 changes: 27 additions & 0 deletions test/parallel/test-domain-abort-on-uncaught-5.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
'use strict';

// This test makes sure that when using --abort-on-uncaught-exception and
// when throwing an error from within a domain that has an error handler
// setup, the process _does not_ abort.

const common = require('../common');
const domain = require('domain');

const test = () => {
const d = domain.create();
d.once('error', common.mustCall(() => { }));

d.run(function() {
const fs = require('fs');
fs.exists('/non/existing/file', function onExists(exists) {
throw new Error('boom!');
});
});
};


if (process.argv[2] === 'child') {
test();
} else {
common.childShouldNotThrowAndAbort();
}
35 changes: 35 additions & 0 deletions test/parallel/test-domain-abort-on-uncaught-6.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
'use strict';

// This test makes sure that when using --abort-on-uncaught-exception and
// when throwing an error from within a domain that has an error handler
// setup, the process _does not_ abort.

const common = require('../common');
const domain = require('domain');

const test = () => {
const net = require('net');
const d = domain.create();
d.on('error', common.mustCall(() => {}));

d.run(function() {
const server = net.createServer(function(conn) {
conn.pipe(conn);
});
server.listen(0, common.localhostIPv4, function() {
const conn = net.connect(this.address().port, common.localhostIPv4);
conn.once('data', function() {
throw new Error('ok');
});
conn.end('ok');
server.close();
});
});
};


if (process.argv[2] === 'child') {
test();
} else {
common.childShouldNotThrowAndAbort();
}
27 changes: 27 additions & 0 deletions test/parallel/test-domain-abort-on-uncaught-7.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
'use strict';

// This test makes sure that when using --abort-on-uncaught-exception and
// when throwing an error from within a domain that has an error handler
// setup, the process _does not_ abort.

const common = require('../common');
const domain = require('domain');

const test = () => {
const d = domain.create();
const d2 = domain.create();
d.on('error', common.mustCall(() => {}));

d.run(function() {
d2.run(function() {
throw new Error('boom!');
});
});
};


if (process.argv[2] === 'child') {
test();
} else {
common.childShouldNotThrowAndAbort();
}
28 changes: 28 additions & 0 deletions test/parallel/test-domain-abort-on-uncaught-8.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
'use strict';

// This test makes sure that when using --abort-on-uncaught-exception and
// when throwing an error from within a domain that has an error handler
// setup, the process _does not_ abort.

const common = require('../common');
const domain = require('domain');

const test = () => {
const d = domain.create();
const d2 = domain.create();

d2.on('error', common.mustCall(() => {}));

d.run(function() {
d2.run(function() {
throw new Error('boom!');
});
});
};


if (process.argv[2] === 'child') {
test();
} else {
common.childShouldNotThrowAndAbort();
}
Loading