summaryrefslogtreecommitdiff
path: root/gnu/packages/patches/node-test-http2-server-rst-stream.patch
blob: c2f85010b191b495e18f1842896fcbe0882e2179 (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
From a41cc020fd6e40b358103425edfa50e6a10fc973 Mon Sep 17 00:00:00 2001
From: Anatoli Papirovski <apapirovski@mac.com>
Date: Thu, 2 Nov 2017 12:46:31 -0400
Subject: [PATCH] test: fix flaky test-http2-server-rst-stream.js

PR-URL: https://github.com/nodejs/node/pull/16690
Fixes: https://github.com/nodejs/node/issues/16688
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
---
 test/parallel/test-http2-server-rst-stream.js | 93 ++++++++++-----------------
 1 file changed, 35 insertions(+), 58 deletions(-)

diff --git a/test/parallel/test-http2-server-rst-stream.js b/test/parallel/test-http2-server-rst-stream.js
index b92217dc99..dd38efb42f 100644
--- a/test/parallel/test-http2-server-rst-stream.js
+++ b/test/parallel/test-http2-server-rst-stream.js
@@ -5,11 +5,9 @@ if (!common.hasCrypto)
   common.skip('missing crypto');
 const assert = require('assert');
 const http2 = require('http2');
+const Countdown = require('../common/countdown');
 
 const {
-  HTTP2_HEADER_METHOD,
-  HTTP2_HEADER_PATH,
-  HTTP2_METHOD_POST,
   NGHTTP2_CANCEL,
   NGHTTP2_NO_ERROR,
   NGHTTP2_PROTOCOL_ERROR,
@@ -17,63 +15,42 @@ const {
   NGHTTP2_INTERNAL_ERROR
 } = http2.constants;
 
-const errCheck = common.expectsError({ code: 'ERR_HTTP2_STREAM_ERROR' }, 6);
+const tests = [
+  ['rstStream', NGHTTP2_NO_ERROR, false],
+  ['rstWithNoError', NGHTTP2_NO_ERROR, false],
+  ['rstWithProtocolError', NGHTTP2_PROTOCOL_ERROR, true],
+  ['rstWithCancel', NGHTTP2_CANCEL, false],
+  ['rstWithRefuse', NGHTTP2_REFUSED_STREAM, true],
+  ['rstWithInternalError', NGHTTP2_INTERNAL_ERROR, true]
+];
+
+const server = http2.createServer();
+server.on('stream', (stream, headers) => {
+  const method = headers['rstmethod'];
+  stream[method]();
+});
+
+server.listen(0, common.mustCall(() => {
+  const client = http2.connect(`http://localhost:${server.address().port}`);
+
+  const countdown = new Countdown(tests.length, common.mustCall(() => {
+    client.destroy();
+    server.close();
+  }));
 
-function checkRstCode(rstMethod, expectRstCode) {
-  const server = http2.createServer();
-  server.on('stream', (stream, headers, flags) => {
-    stream.respond({
-      'content-type': 'text/html',
-      ':status': 200
+  tests.forEach((test) => {
+    const req = client.request({
+      ':method': 'POST',
+      rstmethod: test[0]
     });
-    stream.write('test');
-    if (rstMethod === 'rstStream')
-      stream[rstMethod](expectRstCode);
-    else
-      stream[rstMethod]();
-
-    if (expectRstCode !== NGHTTP2_NO_ERROR &&
-        expectRstCode !== NGHTTP2_CANCEL) {
-      stream.on('error', common.mustCall(errCheck));
-    } else {
-      stream.on('error', common.mustNotCall());
-    }
-  });
-
-  server.listen(0, common.mustCall(() => {
-    const port = server.address().port;
-    const client = http2.connect(`http://localhost:${port}`);
-
-    const headers = {
-      [HTTP2_HEADER_PATH]: '/',
-      [HTTP2_HEADER_METHOD]: HTTP2_METHOD_POST
-    };
-    const req = client.request(headers);
-
-    req.setEncoding('utf8');
-    req.on('streamClosed', common.mustCall((actualRstCode) => {
-      assert.strictEqual(
-        expectRstCode, actualRstCode, `${rstMethod} is not match rstCode`);
-      server.close();
-      client.destroy();
+    req.on('streamClosed', common.mustCall((code) => {
+      assert.strictEqual(code, test[1]);
+      countdown.dec();
     }));
-    req.on('data', common.mustCall());
     req.on('aborted', common.mustCall());
-    req.on('end', common.mustCall());
-
-    if (expectRstCode !== NGHTTP2_NO_ERROR &&
-        expectRstCode !== NGHTTP2_CANCEL) {
-      req.on('error', common.mustCall(errCheck));
-    } else {
+    if (test[2])
+      req.on('error', common.mustCall());
+    else
       req.on('error', common.mustNotCall());
-    }
-
-  }));
-}
-
-checkRstCode('rstStream', NGHTTP2_NO_ERROR);
-checkRstCode('rstWithNoError', NGHTTP2_NO_ERROR);
-checkRstCode('rstWithProtocolError', NGHTTP2_PROTOCOL_ERROR);
-checkRstCode('rstWithCancel', NGHTTP2_CANCEL);
-checkRstCode('rstWithRefuse', NGHTTP2_REFUSED_STREAM);
-checkRstCode('rstWithInternalError', NGHTTP2_INTERNAL_ERROR);
+  });
+}));
-- 
2.15.0