summaryrefslogtreecommitdiff
path: root/test/sequential/test-net-server-bind.js
diff options
context:
space:
mode:
authorRich Trott <rtrott@gmail.com>2017-05-28 21:00:44 -0700
committerRich Trott <rtrott@gmail.com>2017-05-31 22:09:54 -0700
commite824c75c3e71c1069d8a34984df0d92438813ee6 (patch)
tree895e14c035d0a477c140019db8274fe56c32d4f0 /test/sequential/test-net-server-bind.js
parentf1b2e68d651e4fb68ad3b27e1138542673d3b502 (diff)
downloadandroid-node-v8-e824c75c3e71c1069d8a34984df0d92438813ee6.tar.gz
android-node-v8-e824c75c3e71c1069d8a34984df0d92438813ee6.tar.bz2
android-node-v8-e824c75c3e71c1069d8a34984df0d92438813ee6.zip
test: refactor test-net-server-bind
* Use common.mustNotCall() and common.mustCall() as appropriate * Use block scoping * Move assertions out of `exit` handler and into callbacks * Order assert.strictEqual() args per docs * Remove console.log() calls * Move test from `parallel` to `sequential` so `common.PORT` can be used without conflicting with OS-provided ports in other `parallel` tests PR-URL: https://github.com/nodejs/node/pull/13273 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Diffstat (limited to 'test/sequential/test-net-server-bind.js')
-rw-r--r--test/sequential/test-net-server-bind.js64
1 files changed, 64 insertions, 0 deletions
diff --git a/test/sequential/test-net-server-bind.js b/test/sequential/test-net-server-bind.js
new file mode 100644
index 0000000000..56216d0ed6
--- /dev/null
+++ b/test/sequential/test-net-server-bind.js
@@ -0,0 +1,64 @@
+'use strict';
+const common = require('../common');
+const assert = require('assert');
+const net = require('net');
+
+
+// With only a callback, server should get a port assigned by the OS
+{
+ const server = net.createServer(common.mustNotCall());
+
+ server.listen(common.mustCall(function() {
+ assert.ok(server.address().port > 100);
+ server.close();
+ }));
+}
+
+// No callback to listen(), assume we can bind in 100 ms
+{
+ const server = net.createServer(common.mustNotCall());
+
+ server.listen(common.PORT);
+
+ setTimeout(function() {
+ const address = server.address();
+ assert.strictEqual(address.port, common.PORT);
+
+ if (address.family === 'IPv6')
+ assert.strictEqual(server._connectionKey, `6::::${address.port}`);
+ else
+ assert.strictEqual(server._connectionKey, `4:0.0.0.0:${address.port}`);
+
+ server.close();
+ }, 100);
+}
+
+// Callback to listen()
+{
+ const server = net.createServer(common.mustNotCall());
+
+ server.listen(common.PORT + 1, common.mustCall(function() {
+ assert.strictEqual(server.address().port, common.PORT + 1);
+ server.close();
+ }));
+}
+
+// Backlog argument
+{
+ const server = net.createServer(common.mustNotCall());
+
+ server.listen(common.PORT + 2, '0.0.0.0', 127, common.mustCall(function() {
+ assert.strictEqual(server.address().port, common.PORT + 2);
+ server.close();
+ }));
+}
+
+// Backlog argument without host argument
+{
+ const server = net.createServer(common.mustNotCall());
+
+ server.listen(common.PORT + 3, 127, common.mustCall(function() {
+ assert.strictEqual(server.address().port, common.PORT + 3);
+ server.close();
+ }));
+}