Skip to content

Commit 135efdd

Browse files
authored
PYTHON-3153 Update initial DNS seedlist discovery tests to support dedicated load balancer port (#1002)
1 parent 418130d commit 135efdd

8 files changed

+23
-20
lines changed

pymongo/mongo_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2102,12 +2102,12 @@ def __init__(self, client, server, session):
21022102
self.service_id = None
21032103
self.handled = False
21042104

2105-
def contribute_socket(self, sock_info):
2105+
def contribute_socket(self, sock_info, completed_handshake=True):
21062106
"""Provide socket information to the error handler."""
21072107
self.max_wire_version = sock_info.max_wire_version
21082108
self.sock_generation = sock_info.generation
21092109
self.service_id = sock_info.service_id
2110-
self.completed_handshake = True
2110+
self.completed_handshake = completed_handshake
21112111

21122112
def handle(self, exc_type, exc_val):
21132113
if self.handled or exc_type is None:

pymongo/pool.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1344,7 +1344,7 @@ def remove_stale_sockets(self, reference_generation):
13441344
self.requests -= 1
13451345
self.size_cond.notify()
13461346

1347-
def connect(self):
1347+
def connect(self, handler=None):
13481348
"""Connect to Mongo and return a new SocketInfo.
13491349
13501350
Can raise ConnectionFailure.
@@ -1378,6 +1378,8 @@ def connect(self):
13781378
if self.handshake:
13791379
sock_info.hello()
13801380
self.is_writable = sock_info.is_writable
1381+
if handler:
1382+
handler.contribute_socket(sock_info, completed_handshake=False)
13811383

13821384
sock_info.authenticate()
13831385
except BaseException:
@@ -1408,7 +1410,8 @@ def get_socket(self, handler=None):
14081410
if self.enabled_for_cmap:
14091411
listeners.publish_connection_check_out_started(self.address)
14101412

1411-
sock_info = self._get_socket()
1413+
sock_info = self._get_socket(handler=handler)
1414+
14121415
if self.enabled_for_cmap:
14131416
listeners.publish_connection_checked_out(self.address, sock_info.id)
14141417
try:
@@ -1446,7 +1449,7 @@ def _raise_if_not_ready(self, emit_event):
14461449
)
14471450
_raise_connection_failure(self.address, AutoReconnect("connection pool paused"))
14481451

1449-
def _get_socket(self):
1452+
def _get_socket(self, handler=None):
14501453
"""Get or create a SocketInfo. Can raise ConnectionFailure."""
14511454
# We use the pid here to avoid issues with fork / multiprocessing.
14521455
# See test.test_client:TestClient.test_fork for an example of
@@ -1520,7 +1523,7 @@ def _get_socket(self):
15201523
continue
15211524
else: # We need to create a new connection
15221525
try:
1523-
sock_info = self.connect()
1526+
sock_info = self.connect(handler=handler)
15241527
finally:
15251528
with self._max_connecting_cond:
15261529
self._pending -= 1

test/srv_seedlist/load-balanced/loadBalanced-directConnection.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
2-
"uri": "mongodb+srv://test20.test.build.10gen.cc/?directConnection=false",
2+
"uri": "mongodb+srv://test24.test.build.10gen.cc/?directConnection=false",
33
"seeds": [
4-
"localhost.test.build.10gen.cc:27017"
4+
"localhost.test.build.10gen.cc:8000"
55
],
66
"hosts": [
7-
"localhost.test.build.10gen.cc:27017"
7+
"localhost.test.build.10gen.cc:8000"
88
],
99
"options": {
1010
"loadBalanced": true,

test/srv_seedlist/load-balanced/loadBalanced-replicaSet-errors.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"uri": "mongodb+srv://test20.test.build.10gen.cc/?replicaSet=replset",
2+
"uri": "mongodb+srv://test24.test.build.10gen.cc/?replicaSet=replset",
33
"seeds": [],
44
"hosts": [],
55
"error": true,

test/srv_seedlist/load-balanced/loadBalanced-true-txt.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
2-
"uri": "mongodb+srv://test20.test.build.10gen.cc/",
2+
"uri": "mongodb+srv://test24.test.build.10gen.cc/",
33
"seeds": [
4-
"localhost.test.build.10gen.cc:27017"
4+
"localhost.test.build.10gen.cc:8000"
55
],
66
"hosts": [
7-
"localhost.test.build.10gen.cc:27017"
7+
"localhost.test.build.10gen.cc:8000"
88
],
99
"options": {
1010
"loadBalanced": true,

test/srv_seedlist/load-balanced/srvMaxHosts-conflicts_with_loadBalanced-true-txt.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"uri": "mongodb+srv://test20.test.build.10gen.cc/?srvMaxHosts=1",
2+
"uri": "mongodb+srv://test24.test.build.10gen.cc/?srvMaxHosts=1",
33
"seeds": [],
44
"hosts": [],
55
"error": true,

test/srv_seedlist/load-balanced/srvMaxHosts-zero-txt.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
2-
"uri": "mongodb+srv://test20.test.build.10gen.cc/?srvMaxHosts=0",
2+
"uri": "mongodb+srv://test24.test.build.10gen.cc/?srvMaxHosts=0",
33
"seeds": [
4-
"localhost.test.build.10gen.cc:27017"
4+
"localhost.test.build.10gen.cc:8000"
55
],
66
"hosts": [
7-
"localhost.test.build.10gen.cc:27017"
7+
"localhost.test.build.10gen.cc:8000"
88
],
99
"options": {
1010
"loadBalanced": true,

test/srv_seedlist/load-balanced/srvMaxHosts-zero.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
2-
"uri": "mongodb+srv://test3.test.build.10gen.cc/?loadBalanced=true&srvMaxHosts=0",
2+
"uri": "mongodb+srv://test23.test.build.10gen.cc/?loadBalanced=true&srvMaxHosts=0",
33
"seeds": [
4-
"localhost.test.build.10gen.cc:27017"
4+
"localhost.test.build.10gen.cc:8000"
55
],
66
"hosts": [
7-
"localhost.test.build.10gen.cc:27017"
7+
"localhost.test.build.10gen.cc:8000"
88
],
99
"options": {
1010
"loadBalanced": true,

0 commit comments

Comments
 (0)