Skip to content

Commit

Permalink
fix(tests): fix connection failed tcp test
Browse files Browse the repository at this point in the history
  • Loading branch information
dnlup authored and simonecorsi committed Oct 28, 2021
1 parent d3dd60e commit 77087af
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions test/index.spec.ts
Expand Up @@ -10,6 +10,9 @@ import { URL } from 'url';
import net from 'net';
import isCI from 'is-ci';
import buildLookupFunction from '../src/dns-cache';
import { promisify } from 'util';

const sleep = promisify(setTimeout);

const nodeVersion = process.version.split('.')[0];

Expand Down Expand Up @@ -609,6 +612,8 @@ test('if TCP connect fail then the socket should not reconnect', async (t) => {
const sockMock = sinon.fake(net.createConnection);
const socket = new SocketTcp(host, undefined, null, sockMock);
await t.throwsAsync(socket.connect());
// Wait a second to be sure that there is no reconnection attempt.
await sleep(1000);

t.true(sockMock.calledOnce);
socket.close();
Expand Down

0 comments on commit 77087af

Please sign in to comment.