summaryrefslogtreecommitdiff
path: root/test/parallel/test-http-client-finished.js
diff options
context:
space:
mode:
authorRobert Nagy <ronagy@icloud.com>2019-07-18 13:15:42 +0200
committerMatteo Collina <hello@matteocollina.com>2019-09-03 10:28:48 +0200
commitb03845b9376aec590b89f753a4b7c1b47729c5f8 (patch)
treebc16cf37f489fc97d715642941d4dd25b2e60d42 /test/parallel/test-http-client-finished.js
parentd62d2b456031539617a9e615c3e62c199a7e7dfe (diff)
downloadandroid-node-v8-b03845b9376aec590b89f753a4b7c1b47729c5f8.tar.gz
android-node-v8-b03845b9376aec590b89f753a4b7c1b47729c5f8.tar.bz2
android-node-v8-b03845b9376aec590b89f753a4b7c1b47729c5f8.zip
stream: make finished call the callback if the stream is closed
Make stream.finished callback invoked if stream is already closed/destroyed. PR-URL: https://github.com/nodejs/node/pull/28748 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Diffstat (limited to 'test/parallel/test-http-client-finished.js')
-rw-r--r--test/parallel/test-http-client-finished.js106
1 files changed, 106 insertions, 0 deletions
diff --git a/test/parallel/test-http-client-finished.js b/test/parallel/test-http-client-finished.js
index 2d7e5b95b3..337f7b596d 100644
--- a/test/parallel/test-http-client-finished.js
+++ b/test/parallel/test-http-client-finished.js
@@ -25,3 +25,109 @@ const { finished } = require('stream');
.end();
}));
}
+
+{
+ // Test abort before finished.
+
+ const server = http.createServer(function(req, res) {
+ });
+
+ server.listen(0, common.mustCall(function() {
+ const req = http.request({
+ port: this.address().port
+ }, common.mustNotCall());
+ req.abort();
+ finished(req, common.mustCall(() => {
+ server.close();
+ }));
+ }));
+}
+
+{
+ // Test abort after request.
+
+ const server = http.createServer(function(req, res) {
+ });
+
+ server.listen(0, common.mustCall(function() {
+ const req = http.request({
+ port: this.address().port
+ }).end();
+ finished(req, (err) => {
+ common.expectsError({
+ type: Error,
+ code: 'ERR_STREAM_PREMATURE_CLOSE'
+ })(err);
+ finished(req, common.mustCall(() => {
+ server.close();
+ }));
+ });
+ req.abort();
+ }));
+}
+
+{
+ // Test abort before end.
+
+ const server = http.createServer(function(req, res) {
+ res.write('test');
+ });
+
+ server.listen(0, common.mustCall(function() {
+ const req = http.request({
+ port: this.address().port
+ }).on('response', common.mustCall((res) => {
+ req.abort();
+ finished(res, common.mustCall(() => {
+ finished(res, common.mustCall(() => {
+ server.close();
+ }));
+ }));
+ })).end();
+ }));
+}
+
+{
+ // Test destroy before end.
+
+ const server = http.createServer(function(req, res) {
+ res.write('test');
+ });
+
+ server.listen(0, common.mustCall(function() {
+ http.request({
+ port: this.address().port
+ }).on('response', common.mustCall((res) => {
+ // TODO(ronag): Bug? Won't emit 'close' unless read.
+ res.on('data', () => {});
+ res.destroy();
+ finished(res, common.mustCall(() => {
+ finished(res, common.mustCall(() => {
+ server.close();
+ }));
+ }));
+ })).end();
+ }));
+}
+
+{
+ // Test finish after end.
+
+ const server = http.createServer(function(req, res) {
+ res.end('asd');
+ });
+
+ server.listen(0, common.mustCall(function() {
+ http.request({
+ port: this.address().port
+ }).on('response', common.mustCall((res) => {
+ // TODO(ronag): Bug? Won't emit 'close' unless read.
+ res.on('data', () => {});
+ finished(res, common.mustCall(() => {
+ finished(res, common.mustCall(() => {
+ server.close();
+ }));
+ }));
+ })).end();
+ }));
+}