@@ -16,17 +16,17 @@ class DNSSomethingError extends Error {
16
16
}
17
17
18
18
const CONNECTION_STRING = `mongodb+srv://test1.test.build.10gen.cc` ;
19
- // 27018 localhost.test.build.10gen.cc.
20
- // 27017 localhost.test.build.10gen.cc.
21
19
22
20
describe ( 'DNS timeout errors' , ( ) => {
23
21
let client : MongoClient ;
22
+ let stub ;
24
23
25
24
beforeEach ( async function ( ) {
26
25
client = new MongoClient ( CONNECTION_STRING , { serverSelectionTimeoutMS : 2000 , tls : false } ) ;
27
26
} ) ;
28
27
29
28
afterEach ( async function ( ) {
29
+ stub = undefined ;
30
30
sinon . restore ( ) ;
31
31
await client . close ( ) ;
32
32
} ) ;
@@ -40,7 +40,7 @@ describe('DNS timeout errors', () => {
40
40
41
41
describe ( 'when SRV record look up times out' , ( ) => {
42
42
beforeEach ( ( ) => {
43
- sinon
43
+ stub = sinon
44
44
. stub ( dns . promises , 'resolveSrv' )
45
45
. onFirstCall ( )
46
46
. rejects ( new DNSTimeoutError ( ) )
@@ -54,12 +54,13 @@ describe('DNS timeout errors', () => {
54
54
55
55
it ( 'retries timeout error' , metadata , async ( ) => {
56
56
await client . connect ( ) ;
57
+ expect ( stub ) . to . have . been . calledTwice ;
57
58
} ) ;
58
59
} ) ;
59
60
60
61
describe ( 'when TXT record look up times out' , ( ) => {
61
62
beforeEach ( ( ) => {
62
- sinon
63
+ stub = sinon
63
64
. stub ( dns . promises , 'resolveTxt' )
64
65
. onFirstCall ( )
65
66
. rejects ( new DNSTimeoutError ( ) )
@@ -73,12 +74,13 @@ describe('DNS timeout errors', () => {
73
74
74
75
it ( 'retries timeout error' , metadata , async ( ) => {
75
76
await client . connect ( ) ;
77
+ expect ( stub ) . to . have . been . calledTwice ;
76
78
} ) ;
77
79
} ) ;
78
80
79
81
describe ( 'when SRV record look up times out twice' , ( ) => {
80
82
beforeEach ( ( ) => {
81
- sinon
83
+ stub = sinon
82
84
. stub ( dns . promises , 'resolveSrv' )
83
85
. onFirstCall ( )
84
86
. rejects ( new DNSTimeoutError ( ) )
@@ -100,7 +102,7 @@ describe('DNS timeout errors', () => {
100
102
101
103
describe ( 'when TXT record look up times out twice' , ( ) => {
102
104
beforeEach ( ( ) => {
103
- sinon
105
+ stub = sinon
104
106
. stub ( dns . promises , 'resolveTxt' )
105
107
. onFirstCall ( )
106
108
. rejects ( new DNSTimeoutError ( ) )
@@ -117,12 +119,13 @@ describe('DNS timeout errors', () => {
117
119
it ( 'throws timeout error' , metadata , async ( ) => {
118
120
const error = await client . connect ( ) . catch ( error => error ) ;
119
121
expect ( error ) . to . be . instanceOf ( DNSTimeoutError ) ;
122
+ expect ( stub ) . to . have . been . calledTwice ;
120
123
} ) ;
121
124
} ) ;
122
125
123
126
describe ( 'when SRV record look up throws a non-timeout error' , ( ) => {
124
127
beforeEach ( ( ) => {
125
- sinon
128
+ stub = sinon
126
129
. stub ( dns . promises , 'resolveSrv' )
127
130
. onFirstCall ( )
128
131
. rejects ( new DNSSomethingError ( ) )
@@ -137,12 +140,13 @@ describe('DNS timeout errors', () => {
137
140
it ( 'throws that error' , metadata , async ( ) => {
138
141
const error = await client . connect ( ) . catch ( error => error ) ;
139
142
expect ( error ) . to . be . instanceOf ( DNSSomethingError ) ;
143
+ expect ( stub ) . to . have . been . calledOnce ;
140
144
} ) ;
141
145
} ) ;
142
146
143
147
describe ( 'when TXT record look up throws a non-timeout error' , ( ) => {
144
148
beforeEach ( ( ) => {
145
- sinon
149
+ stub = sinon
146
150
. stub ( dns . promises , 'resolveTxt' )
147
151
. onFirstCall ( )
148
152
. rejects ( new DNSSomethingError ( ) )
@@ -157,6 +161,7 @@ describe('DNS timeout errors', () => {
157
161
it ( 'throws that error' , metadata , async ( ) => {
158
162
const error = await client . connect ( ) . catch ( error => error ) ;
159
163
expect ( error ) . to . be . instanceOf ( DNSSomethingError ) ;
164
+ expect ( stub ) . to . have . been . calledOnce ;
160
165
} ) ;
161
166
} ) ;
162
167
} ) ;
0 commit comments