0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-30 07:27:22 +01:00
nodejs/test/sequential/test-net-localport.js
Jon Moss af15b755c0
test: move common.PORT tests to sequential
Reasons:

- `test-async-wrap-getasyncid` binds a handle, so move to
  sequential because port cannot be already in use.
- `test-dgram-implicit-bind-failure` requires a hardcoded
  port number to properly send socket packet.
- `test-http-agent-uninitialized-with-handle` requires a
  hardcoded port number to properly send http request.
- `test-http-agent-uninitialized` requires a hardcoded port
  number to properly send http request.
- `test-net-localport` requires a hardcoded port number
  for assertions.

In addition this replaces two common.PORTs with a dynamic port.

PR-URL: https://github.com/nodejs/node/pull/15151
Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2017-09-10 23:56:30 -03:00

21 lines
547 B
JavaScript

'use strict';
const common = require('../common');
const assert = require('assert');
const net = require('net');
const server = net.createServer(function(socket) {
assert.strictEqual(socket.remotePort, common.PORT);
socket.end();
socket.on('close', function() {
server.close();
});
}).listen(0).on('listening', function() {
const client = net.connect({
host: '127.0.0.1',
port: this.address().port,
localPort: common.PORT,
}).on('connect', function() {
assert.strictEqual(client.localPort, common.PORT);
});
});