diff options
author | Jon Moss <me@jonathanmoss.me> | 2017-09-01 12:37:41 -0400 |
---|---|---|
committer | Ruben Bridgewater <ruben@bridgewater.de> | 2017-09-10 23:56:30 -0300 |
commit | af15b755c08370d4224541205f9e3e9ff54a4325 (patch) | |
tree | 00da6ddcf5ad8650b2852da3542f59872c230d64 /test/sequential/test-dgram-implicit-bind-failure.js | |
parent | 45357d055694000b78a27e1959f304f5838005be (diff) | |
download | android-node-v8-af15b755c08370d4224541205f9e3e9ff54a4325.tar.gz android-node-v8-af15b755c08370d4224541205f9e3e9ff54a4325.tar.bz2 android-node-v8-af15b755c08370d4224541205f9e3e9ff54a4325.zip |
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>
Diffstat (limited to 'test/sequential/test-dgram-implicit-bind-failure.js')
-rw-r--r-- | test/sequential/test-dgram-implicit-bind-failure.js | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/test/sequential/test-dgram-implicit-bind-failure.js b/test/sequential/test-dgram-implicit-bind-failure.js new file mode 100644 index 0000000000..2944c9aae7 --- /dev/null +++ b/test/sequential/test-dgram-implicit-bind-failure.js @@ -0,0 +1,55 @@ +'use strict'; +const common = require('../common'); +const assert = require('assert'); +const dgram = require('dgram'); +const dns = require('dns'); + +// Monkey patch dns.lookup() so that it always fails. +dns.lookup = function(address, family, callback) { + process.nextTick(() => { callback(new Error('fake DNS')); }); +}; + +const socket = dgram.createSocket('udp4'); +let dnsFailures = 0; +let sendFailures = 0; + +process.on('exit', () => { + assert.strictEqual(dnsFailures, 3); + assert.strictEqual(sendFailures, 3); +}); + +socket.on('error', (err) => { + if (/^Error: fake DNS$/.test(err)) { + // The DNS lookup should fail since it is monkey patched. At that point in + // time, the send queue should be populated with the send() operation. There + // should also be two listeners - this function and the dgram internal one + // time error handler. + dnsFailures++; + assert(Array.isArray(socket._queue)); + assert.strictEqual(socket._queue.length, 1); + assert.strictEqual(socket.listenerCount('error'), 2); + return; + } + + if (err.code === 'ERR_SOCKET_CANNOT_SEND') { + // On error, the queue should be destroyed and this function should be + // the only listener. + sendFailures++; + assert.strictEqual(socket._queue, undefined); + assert.strictEqual(socket.listenerCount('error'), 1); + return; + } + + assert.fail(`Unexpected error: ${err}`); +}); + +// Initiate a few send() operations, which will fail. +socket.send('foobar', common.PORT, 'localhost'); + +process.nextTick(() => { + socket.send('foobar', common.PORT, 'localhost'); +}); + +setImmediate(() => { + socket.send('foobar', common.PORT, 'localhost'); +}); |