summaryrefslogtreecommitdiff
path: root/test/parallel/test-http-server-close-all.js
diff options
context:
space:
mode:
Diffstat (limited to 'test/parallel/test-http-server-close-all.js')
-rw-r--r--test/parallel/test-http-server-close-all.js40
1 files changed, 21 insertions, 19 deletions
diff --git a/test/parallel/test-http-server-close-all.js b/test/parallel/test-http-server-close-all.js
index 79fc5c75b7..cf7d90b868 100644
--- a/test/parallel/test-http-server-close-all.js
+++ b/test/parallel/test-http-server-close-all.js
@@ -26,32 +26,34 @@ server.listen(0, function() {
// Create a first request but never finish it
const client1 = connect(port);
- client1.on('close', common.mustCall());
-
- client1.on('error', () => {});
+ client1.on('connect', common.mustCall(() => {
+ // Create a second request, let it finish but leave the connection opened using HTTP keep-alive
+ const client2 = connect(port);
+ let response = '';
- client1.write('GET / HTTP/1.1');
+ client2.on('data', common.mustCall((chunk) => {
+ response += chunk.toString('utf-8');
- // Create a second request, let it finish but leave the connection opened using HTTP keep-alive
- const client2 = connect(port);
- let response = '';
+ if (response.endsWith('0\r\n\r\n')) {
+ assert(response.startsWith('HTTP/1.1 200 OK\r\nConnection: keep-alive'));
+ assert.strictEqual(connections, 2);
- client2.on('data', common.mustCall((chunk) => {
- response += chunk.toString('utf-8');
+ server.closeAllConnections();
+ server.close(common.mustCall());
- if (response.endsWith('0\r\n\r\n')) {
- assert(response.startsWith('HTTP/1.1 200 OK\r\nConnection: keep-alive'));
- assert.strictEqual(connections, 2);
+ // This timer should never go off as the server.close should shut everything down
+ setTimeout(common.mustNotCall(), common.platformTimeout(1500)).unref();
+ }
+ }));
- server.closeAllConnections();
- server.close(common.mustCall());
+ client2.on('close', common.mustCall());
- // This timer should never go off as the server.close should shut everything down
- setTimeout(common.mustNotCall(), common.platformTimeout(1500)).unref();
- }
+ client2.write('GET / HTTP/1.1\r\n\r\n');
}));
- client2.on('close', common.mustCall());
+ client1.on('close', common.mustCall());
+
+ client1.on('error', () => {});
- client2.write('GET / HTTP/1.1\r\n\r\n');
+ client1.write('GET / HTTP/1.1');
});