Skip to content

Commit 7f74b9b

Browse files
committed
- Replace the dedicated DNS test with a generic one.
- Add the complementary test to cover the suppress-on-label branch.
1 parent 75a5ea4 commit 7f74b9b

1 file changed

Lines changed: 35 additions & 6 deletions

File tree

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

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ import org.bson.BsonInt32
5151
import org.bson.codecs.BsonDocumentCodec
5252
import spock.lang.Specification
5353

54+
import java.security.cert.CertificateException
5455
import java.util.concurrent.CountDownLatch
5556

5657
import static com.mongodb.ClusterFixture.CLIENT_METADATA
@@ -258,12 +259,9 @@ class DefaultServerSpecification extends Specification {
258259
]
259260
}
260261

261-
def 'DNS lookup failure should not be labeled as backpressure and should invalidate the pool'() {
262+
def 'should invalidate the pool when the exception without system overloaded label'() {
262263
given:
263-
def exceptionToThrow = new MongoSocketException('DNS lookup failed', new ServerAddress(),
264-
new UnknownHostException('no such host'))
265-
BackpressureErrorLabeler.applyLabelsIfEligible(exceptionToThrow)
266-
264+
assert !exceptionToThrow.hasErrorLabel(MongoException.SYSTEM_OVERLOADED_ERROR_LABEL)
267265
def connectionPool = Mock(ConnectionPool)
268266
connectionPool.get(_) >> { throw exceptionToThrow }
269267
def serverMonitor = Mock(ServerMonitor)
@@ -275,9 +273,40 @@ class DefaultServerSpecification extends Specification {
275273
then:
276274
def e = thrown(MongoException)
277275
e.is(exceptionToThrow)
278-
!e.hasErrorLabel(MongoException.SYSTEM_OVERLOADED_ERROR_LABEL)
279276
1 * connectionPool.invalidate(exceptionToThrow)
280277
1 * serverMonitor.cancelCurrentCheck()
278+
279+
where:
280+
exceptionToThrow << [
281+
new MongoSocketException('establishment failed', new ServerAddress()),
282+
new MongoSocketOpenException('open failed', new ServerAddress(), new IOException()),
283+
new MongoSocketReadTimeoutException('Read timed out', new ServerAddress(), new IOException()),
284+
new MongoSocketException('DNS lookup failed', new ServerAddress(),
285+
new UnknownHostException('no such host')),
286+
new MongoSocketException('TLS config error', new ServerAddress(),
287+
new CertificateException('bad cert')),
288+
]
289+
}
290+
291+
def 'should not invalidate the pool when the exception carries SystemOverloadedError'() {
292+
given:
293+
def exceptionToThrow = new MongoSocketException('rate-limited establishment', new ServerAddress())
294+
exceptionToThrow.addLabel(MongoException.SYSTEM_OVERLOADED_ERROR_LABEL)
295+
296+
def connectionPool = Mock(ConnectionPool)
297+
connectionPool.get(_) >> { throw exceptionToThrow }
298+
def serverMonitor = Mock(ServerMonitor)
299+
def server = defaultServer(connectionPool, serverMonitor)
300+
301+
when:
302+
server.getConnection(createOperationContext())
303+
304+
then:
305+
def e = thrown(MongoException)
306+
e.is(exceptionToThrow)
307+
e.hasErrorLabel(MongoException.SYSTEM_OVERLOADED_ERROR_LABEL)
308+
0 * connectionPool.invalidate(_)
309+
0 * serverMonitor.cancelCurrentCheck()
281310
}
282311

283312
def 'failed authentication should invalidate the connection pool'() {

0 commit comments

Comments
 (0)