Skip to content

Commit 9b5b0a8

Browse files
committed
update sinon stubs
1 parent 38b46c1 commit 9b5b0a8

2 files changed

Lines changed: 32 additions & 44 deletions

File tree

src/connection_string.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,17 @@ const LB_REPLICA_SET_ERROR = 'loadBalanced option not supported with a replicaSe
4141
const LB_DIRECT_CONNECTION_ERROR =
4242
'loadBalanced option not supported when directConnection is provided';
4343

44-
function retryDNSTimeoutFor(api: 'SRV'): (a: string) => Promise<dns.SrvRecord[]>;
45-
function retryDNSTimeoutFor(api: 'TXT'): (a: string) => Promise<string[][]>;
44+
function retryDNSTimeoutFor(rrtype: 'SRV'): (a: string) => Promise<dns.SrvRecord[]>;
45+
function retryDNSTimeoutFor(rrtype: 'TXT'): (a: string) => Promise<string[][]>;
4646
function retryDNSTimeoutFor(
47-
api: 'SRV' | 'TXT'
47+
rrtype: 'SRV' | 'TXT'
4848
): (a: string) => Promise<dns.SrvRecord[] | string[][]> {
4949
return async function dnsReqRetryTimeout(lookupAddress: string) {
5050
try {
51-
return (await dns.promises.resolve(lookupAddress, api)) as dns.SrvRecord[] | string[][];
51+
return (await dns.promises.resolve(lookupAddress, rrtype)) as dns.SrvRecord[] | string[][];
5252
} catch (firstDNSError) {
5353
if (firstDNSError.code === dns.TIMEOUT) {
54-
return (await dns.promises.resolve(lookupAddress, api)) as dns.SrvRecord[] | string[][];
54+
return (await dns.promises.resolve(lookupAddress, rrtype)) as dns.SrvRecord[] | string[][];
5555
} else {
5656
throw firstDNSError;
5757
}

test/integration/initial-dns-seedlist-discovery/dns_seedlist.test.ts

Lines changed: 27 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -31,25 +31,23 @@ describe('DNS timeout errors', () => {
3131
await client.close();
3232
});
3333

34-
const restoreDNS = api => async args => {
35-
sinon.restore();
36-
return await dns.promises.resolve(args, api);
34+
const restoreDNS = rrtype => async hostname => {
35+
stub.restore();
36+
return await dns.promises.resolve(hostname, rrtype);
3737
};
3838

3939
describe('when SRV record look up times out', () => {
4040
beforeEach(() => {
41-
stub = sinon
42-
.stub(dns.promises, 'resolve')
41+
stub = sinon.stub(dns.promises, 'resolve').callThrough();
42+
43+
stub
44+
.withArgs(sinon.match.string, 'SRV')
4345
.onFirstCall()
4446
.rejects(new DNSTimeoutError())
4547
.onSecondCall()
4648
.callsFake(restoreDNS('SRV'));
4749
});
4850

49-
afterEach(async function () {
50-
sinon.restore();
51-
});
52-
5351
it('retries timeout error', metadata, async () => {
5452
await client.connect();
5553
expect(stub).to.have.been.calledTwice;
@@ -58,18 +56,16 @@ describe('DNS timeout errors', () => {
5856

5957
describe('when TXT record look up times out', () => {
6058
beforeEach(() => {
61-
stub = sinon
62-
.stub(dns.promises, 'resolve')
59+
stub = sinon.stub(dns.promises, 'resolve').callThrough();
60+
61+
stub
62+
.withArgs(sinon.match.string, 'TXT')
6363
.onFirstCall()
6464
.rejects(new DNSTimeoutError())
6565
.onSecondCall()
6666
.callsFake(restoreDNS('TXT'));
6767
});
6868

69-
afterEach(async function () {
70-
sinon.restore();
71-
});
72-
7369
it('retries timeout error', metadata, async () => {
7470
await client.connect();
7571
expect(stub).to.have.been.calledTwice;
@@ -78,18 +74,16 @@ describe('DNS timeout errors', () => {
7874

7975
describe('when SRV record look up times out twice', () => {
8076
beforeEach(() => {
81-
stub = sinon
82-
.stub(dns.promises, 'resolve')
77+
stub = sinon.stub(dns.promises, 'resolve').callThrough();
78+
79+
stub
80+
.withArgs(sinon.match.string, 'SRV')
8381
.onFirstCall()
8482
.rejects(new DNSTimeoutError())
8583
.onSecondCall()
8684
.rejects(new DNSTimeoutError());
8785
});
8886

89-
afterEach(async function () {
90-
sinon.restore();
91-
});
92-
9387
it('throws timeout error', metadata, async () => {
9488
const error = await client.connect().catch(error => error);
9589
expect(error).to.be.instanceOf(DNSTimeoutError);
@@ -99,18 +93,16 @@ describe('DNS timeout errors', () => {
9993

10094
describe('when TXT record look up times out twice', () => {
10195
beforeEach(() => {
102-
stub = sinon
103-
.stub(dns.promises, 'resolve')
96+
stub = sinon.stub(dns.promises, 'resolve').callThrough();
97+
98+
stub
99+
.withArgs(sinon.match.string, 'TXT')
104100
.onFirstCall()
105101
.rejects(new DNSTimeoutError())
106102
.onSecondCall()
107103
.rejects(new DNSTimeoutError());
108104
});
109105

110-
afterEach(async function () {
111-
sinon.restore();
112-
});
113-
114106
it('throws timeout error', metadata, async () => {
115107
const error = await client.connect().catch(error => error);
116108
expect(error).to.be.instanceOf(DNSTimeoutError);
@@ -120,18 +112,16 @@ describe('DNS timeout errors', () => {
120112

121113
describe('when SRV record look up throws a non-timeout error', () => {
122114
beforeEach(() => {
123-
stub = sinon
124-
.stub(dns.promises, 'resolve')
115+
stub = sinon.stub(dns.promises, 'resolve').callThrough();
116+
117+
stub
118+
.withArgs(sinon.match.string, 'SRV')
125119
.onFirstCall()
126120
.rejects(new DNSSomethingError())
127121
.onSecondCall()
128122
.callsFake(restoreDNS('SRV'));
129123
});
130124

131-
afterEach(async function () {
132-
sinon.restore();
133-
});
134-
135125
it('throws that error', metadata, async () => {
136126
const error = await client.connect().catch(error => error);
137127
expect(error).to.be.instanceOf(DNSSomethingError);
@@ -141,18 +131,16 @@ describe('DNS timeout errors', () => {
141131

142132
describe('when TXT record look up throws a non-timeout error', () => {
143133
beforeEach(() => {
144-
stub = sinon
145-
.stub(dns.promises, 'resolve')
134+
stub = sinon.stub(dns.promises, 'resolve').callThrough();
135+
136+
stub
137+
.withArgs(sinon.match.string, 'TXT')
146138
.onFirstCall()
147139
.rejects(new DNSSomethingError())
148140
.onSecondCall()
149141
.callsFake(restoreDNS('TXT'));
150142
});
151143

152-
afterEach(async function () {
153-
sinon.restore();
154-
});
155-
156144
it('throws that error', metadata, async () => {
157145
const error = await client.connect().catch(error => error);
158146
expect(error).to.be.instanceOf(DNSSomethingError);

0 commit comments

Comments
 (0)