|
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();
|
0 commit comments