@@ -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