summaryrefslogtreecommitdiff
path: root/test/parallel/test-net-server-connections-child-null.js
diff options
context:
space:
mode:
authorRich Trott <rtrott@gmail.com>2017-01-11 23:20:54 -0800
committerRich Trott <rtrott@gmail.com>2017-01-14 20:57:26 -0800
commit97f001ab167875c8e8e8418fa55ff14ef76a4064 (patch)
treeb4837d95bae42d3b9c3155204de344dc389c5965 /test/parallel/test-net-server-connections-child-null.js
parent66f09be74399b61a433a58dfe48c6fd5b9d66594 (diff)
downloadandroid-node-v8-97f001ab167875c8e8e8418fa55ff14ef76a4064.tar.gz
android-node-v8-97f001ab167875c8e8e8418fa55ff14ef76a4064.tar.bz2
android-node-v8-97f001ab167875c8e8e8418fa55ff14ef76a4064.zip
test,net: add tests for server.connections
There were no tests confirming situations where server.connections should return `null`. Add a test for that situation. Expand existing server.connection test slightly to check value. Refactor (mostly spacing) code for server.connections setter. PR-URL: https://github.com/nodejs/node/pull/10762 Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'test/parallel/test-net-server-connections-child-null.js')
-rw-r--r--test/parallel/test-net-server-connections-child-null.js44
1 files changed, 44 insertions, 0 deletions
diff --git a/test/parallel/test-net-server-connections-child-null.js b/test/parallel/test-net-server-connections-child-null.js
new file mode 100644
index 0000000000..a8a1346fec
--- /dev/null
+++ b/test/parallel/test-net-server-connections-child-null.js
@@ -0,0 +1,44 @@
+'use strict';
+const common = require('../common');
+const assert = require('assert');
+const fork = require('child_process').fork;
+const net = require('net');
+
+if (process.argv[2] === 'child') {
+
+ process.on('message', (msg, socket) => {
+ socket.end('goodbye');
+ });
+
+ process.send('hello');
+
+} else {
+
+ const child = fork(process.argv[1], ['child']);
+
+ const runTest = common.mustCall(() => {
+
+ const server = net.createServer();
+
+ // server.connections should start as 0
+ assert.strictEqual(server.connections, 0);
+ server.on('connection', (socket) => {
+ child.send({what: 'socket'}, socket);
+ });
+ server.on('close', () => {
+ child.kill();
+ });
+
+ server.listen(0, common.mustCall(() => {
+ const connect = net.connect(server.address().port);
+
+ connect.on('close', common.mustCall(() => {
+ // now server.connections should be null
+ assert.strictEqual(server.connections, null);
+ server.close();
+ }));
+ }));
+ });
+
+ child.on('message', runTest);
+}