Skip to content

Commit 6afa1a8

Browse files
committed
Add DNS-lookup regression test for backpressure pool invalidation
1 parent 71c91f0 commit 6afa1a8

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

driver-core/src/test/unit/com/mongodb/internal/connection/DefaultServerSpecification.groovy

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,28 @@ class DefaultServerSpecification extends Specification {
259259
]
260260
}
261261

262+
def 'DNS lookup failure should invalidate the pool'() {
263+
given:
264+
def exceptionToThrow = new MongoSocketException('DNS lookup failed', new ServerAddress(),
265+
new UnknownHostException('no such host'))
266+
BackpressureErrorLabeler.applyLabelsIfEligible(exceptionToThrow)
267+
assert !exceptionToThrow.hasErrorLabel(MongoException.SYSTEM_OVERLOADED_ERROR_LABEL)
268+
269+
def connectionPool = Mock(ConnectionPool)
270+
connectionPool.get(_) >> { throw exceptionToThrow }
271+
def serverMonitor = Mock(ServerMonitor)
272+
def server = defaultServer(connectionPool, serverMonitor)
273+
274+
when:
275+
server.getConnection(OPERATION_CONTEXT)
276+
277+
then:
278+
def e = thrown(MongoException)
279+
e.is(exceptionToThrow)
280+
1 * connectionPool.invalidate(exceptionToThrow)
281+
1 * serverMonitor.cancelCurrentCheck()
282+
}
283+
262284
def 'failed authentication should invalidate the connection pool'() {
263285
given:
264286
def connectionPool = Mock(ConnectionPool)

0 commit comments

Comments
 (0)