summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorDaniele Belardi <dwon.dnl@gmail.com>2020-12-16 08:39:16 +0100
committerNode.js GitHub Bot <github-bot@iojs.org>2020-12-17 10:31:10 +0000
commit8154e47e2b407a906f2c1270e5fc76fe466cc886 (patch)
treec617d7566cc01d698e06600b7ec5a26ac0dd1dbf /test
parenta6bf74eac00516fd0767b585c8f304857dddd2aa (diff)
downloadios-node-v8-8154e47e2b407a906f2c1270e5fc76fe466cc886.tar.gz
ios-node-v8-8154e47e2b407a906f2c1270e5fc76fe466cc886.tar.bz2
ios-node-v8-8154e47e2b407a906f2c1270e5fc76fe466cc886.zip
http: add test for incomingmessage destroy
Test uncaught exceptions when destroying IncomingMessage. PR-URL: https://github.com/nodejs/node/pull/33035 Refs: https://github.com/nodejs/node/issues/30625 Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
Diffstat (limited to 'test')
-rw-r--r--test/parallel/test-http-client-incomingmessage-destroy.js25
-rw-r--r--test/parallel/test-http-server-incomingmessage-destroy.js25
2 files changed, 50 insertions, 0 deletions
diff --git a/test/parallel/test-http-client-incomingmessage-destroy.js b/test/parallel/test-http-client-incomingmessage-destroy.js
new file mode 100644
index 0000000000..a0823d3778
--- /dev/null
+++ b/test/parallel/test-http-client-incomingmessage-destroy.js
@@ -0,0 +1,25 @@
+'use strict';
+
+const common = require('../common');
+const { createServer, get } = require('http');
+const assert = require('assert');
+
+const server = createServer(common.mustCall((req, res) => {
+ res.writeHead(200);
+ res.write('Part of res.');
+}));
+
+function onUncaught(error) {
+ assert.strictEqual(error.message, 'Destroy test');
+ server.close();
+}
+
+process.on('uncaughtException', common.mustCall(onUncaught));
+
+server.listen(0, () => {
+ get({
+ port: server.address().port
+ }, common.mustCall((res) => {
+ res.destroy(new Error('Destroy test'));
+ }));
+});
diff --git a/test/parallel/test-http-server-incomingmessage-destroy.js b/test/parallel/test-http-server-incomingmessage-destroy.js
new file mode 100644
index 0000000000..cfe7e4feec
--- /dev/null
+++ b/test/parallel/test-http-server-incomingmessage-destroy.js
@@ -0,0 +1,25 @@
+'use strict';
+
+const common = require('../common');
+const { createServer, get } = require('http');
+const assert = require('assert');
+
+const server = createServer(common.mustCall((req, res) => {
+ req.destroy(new Error('Destroy test'));
+}));
+
+function onUncaught(error) {}
+
+process.on('uncaughtException', common.mustNotCall(onUncaught));
+
+server.listen(0, common.mustCall(() => {
+ get({
+ port: server.address().port
+ }, (res) => {
+ res.resume();
+ }).on('error', (error) => {
+ assert.strictEqual(error.message, 'socket hang up');
+ assert.strictEqual(error.code, 'ECONNRESET');
+ server.close();
+ });
+}));