| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 4e789a3 commit 3d45a94
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,11 +1,21 @@ | |||
| 1 | 1 | 'use strict'; | |
| 2 | + | ||
| 3 | + // This tests that the error emitted on the socket does | ||
| 4 | + // not get fired again when the 'error' event handler throws | ||
| 5 | + // an error. | ||
| 6 | + | ||
| 2 | 7 | const assert = require('assert'); | |
| 3 | 8 | const http = require('http'); | |
| 4 | 9 | const common = require('../common'); | |
| 10 | + const { addresses } = require('../common/internet'); | ||
| 11 | + const { errorLookupMock } = require('../common/dns'); | ||
| 12 | + | ||
| 13 | + const host = addresses.INVALID_HOST; | ||
| 5 | 14 | ||
| 6 | - // Invalid hostname as per https://tools.ietf.org/html/rfc2606#section-2 | ||
| 7 | - const host = 'this.hostname.is.invalid'; | ||
| 8 | - const req = http.get({ host }); | ||
| 15 | + const req = http.get({ | ||
| 16 | + host, | ||
| 17 | + lookup: common.mustCall(errorLookupMock()) | ||
| 18 | + }); | ||
| 9 | 19 | const err = new Error('mock unexpected code error'); | |
| 10 | 20 | req.on('error', common.mustCall(() => { | |
| 11 | 21 | throw err; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,21 +1,30 @@ | |||
| 1 | 1 | 'use strict'; | |
| 2 | + | ||
| 3 | + // This tests that the error thrown from net.createConnection | ||
| 4 | + // comes with host and port properties. | ||
| 5 | + // See https://github.com/nodejs/node-v0.x-archive/issues/7005 | ||
| 6 | + | ||
| 2 | 7 | const common = require('../common'); | |
| 3 | 8 | const net = require('net'); | |
| 4 | 9 | const assert = require('assert'); | |
| 5 | 10 | ||
| 11 | + const { addresses } = require('../common/internet'); | ||
| 12 | + const { | ||
| 13 | + errorLookupMock, | ||
| 14 | + mockedErrorCode | ||
| 15 | + } = require('../common/dns'); | ||
| 16 | + | ||
| 6 | 17 | // Using port 0 as hostname used is already invalid. | |
| 7 | - const c = net.createConnection(0, 'this.hostname.is.invalid'); | ||
| 18 | + const c = net.createConnection({ | ||
| 19 | + port: 0, | ||
| 20 | + host: addresses.INVALID_HOST, | ||
| 21 | + lookup: common.mustCall(errorLookupMock()) | ||
| 22 | + }); | ||
| 8 | 23 | ||
| 9 | 24 | c.on('connect', common.mustNotCall()); | |
| 10 | 25 | ||
| 11 | 26 | c.on('error', common.mustCall(function(e) { | |
| 12 | - // If Name Service Switch is available on the operating system then it | ||
| 13 | - // might be configured differently (/etc/nsswitch.conf). | ||
| 14 | - // If the system is configured with no dns the error code will be EAI_AGAIN, | ||
| 15 | - // but if there are more services after the dns entry, for example some | ||
| 16 | - // linux distributions ship a myhostname service by default which would | ||
| 17 | - // still produce the ENOTFOUND error. | ||
| 18 | - assert.ok(e.code === 'ENOTFOUND' || e.code === 'EAI_AGAIN'); | ||
| 27 | + assert.strictEqual(e.code, mockedErrorCode); | ||
| 19 | 28 | assert.strictEqual(e.port, 0); | |
| 20 | - assert.strictEqual(e.hostname, 'this.hostname.is.invalid'); | ||
| 29 | + assert.strictEqual(e.hostname, addresses.INVALID_HOST); | ||
| 21 | 30 | })); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -20,28 +20,35 @@ | |||
| 20 | 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE. | |
| 21 | 21 | ||
| 22 | 22 | 'use strict'; | |
| 23 | + | ||
| 24 | + // This tests that if the socket is still in the 'connecting' state | ||
| 25 | + // when the user calls socket.end() ('finish'), the socket would emit | ||
| 26 | + // 'connect' and defer the handling until the 'connect' event is handled. | ||
| 27 | + | ||
| 23 | 28 | const common = require('../common'); | |
| 24 | 29 | const assert = require('assert'); | |
| 25 | 30 | const net = require('net'); | |
| 26 | 31 | ||
| 32 | + const { addresses } = require('../common/internet'); | ||
| 33 | + const { | ||
| 34 | + errorLookupMock, | ||
| 35 | + mockedErrorCode, | ||
| 36 | + mockedSysCall | ||
| 37 | + } = require('../common/dns'); | ||
| 38 | + | ||
| 27 | 39 | const client = net.connect({ | |
| 28 | - host: 'this.hostname.is.invalid', | ||
| 29 | - port: common.PORT | ||
| 40 | + host: addresses.INVALID_HOST, | ||
| 41 | + port: common.PORT, | ||
| 42 | + lookup: common.mustCall(errorLookupMock()) | ||
| 30 | 43 | }); | |
| 31 | 44 | ||
| 32 | 45 | client.once('error', common.mustCall((err) => { | |
| 33 | 46 | assert(err); | |
| 34 | 47 | assert.strictEqual(err.code, err.errno); | |
| 35 | - // If Name Service Switch is available on the operating system then it | ||
| 36 | - // might be configured differently (/etc/nsswitch.conf). | ||
| 37 | - // If the system is configured with no dns the error code will be EAI_AGAIN, | ||
| 38 | - // but if there are more services after the dns entry, for example some | ||
| 39 | - // linux distributions ship a myhostname service by default which would | ||
| 40 | - // still produce the ENOTFOUND error. | ||
| 41 | - assert.ok(err.code === 'ENOTFOUND' || err.code === 'EAI_AGAIN'); | ||
| 48 | + assert.strictEqual(err.code, mockedErrorCode); | ||
| 42 | 49 | assert.strictEqual(err.host, err.hostname); | |
| 43 | - assert.strictEqual(err.host, 'this.hostname.is.invalid'); | ||
| 44 | - assert.strictEqual(err.syscall, 'getaddrinfo'); | ||
| 50 | + assert.strictEqual(err.host, addresses.INVALID_HOST); | ||
| 51 | + assert.strictEqual(err.syscall, mockedSysCall); | ||
| 45 | 52 | })); | |
| 46 | 53 | ||
| 47 | 54 | client.end(); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments