-
Notifications
You must be signed in to change notification settings - Fork 1.1k
PYTHON-3636 MongoClient should perform SRV resolution lazily #2191
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 25 commits
ead780a
79c09ea
3afd732
7d771cb
0f64689
ed50141
ed25867
8d48f44
1a3efed
d94743b
ad20606
dfa0639
57edcbc
58a58a0
35a41e9
d343311
d03c78f
e1d091f
8efd549
4c06dec
511fcc4
40509a1
97e0778
1de56d4
2653a56
4c23ee0
bc61199
8c2b368
e38c2ad
3c1bb28
94fec44
99a07fe
32fabb9
af568da
82bcd38
60bf17d
63ba7be
7585e04
2c69412
f834b89
d450457
2a8b1b2
c82cf50
9256808
c6d2ceb
d8d2c26
8927a27
76a68b2
b60eb60
0b6d303
0ca6afd
259d36b
d616135
379dfb6
5466484
2900718
63676b6
cd9bd92
f33d091
a7c090d
93bc3c9
afd82f4
99a5c8a
21d3f58
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1911,28 +1911,37 @@ async def test_service_name_from_kwargs(self): | |
srvServiceName="customname", | ||
connect=False, | ||
) | ||
await client.aconnect() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are these open/close calls still needed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes because these are srv uris |
||
self.assertEqual(client._topology_settings.srv_service_name, "customname") | ||
await client.close() | ||
client = AsyncMongoClient( | ||
"mongodb+srv://user:[email protected]" | ||
"/?srvServiceName=shouldbeoverriden", | ||
srvServiceName="customname", | ||
connect=False, | ||
) | ||
await client.aconnect() | ||
self.assertEqual(client._topology_settings.srv_service_name, "customname") | ||
await client.close() | ||
client = AsyncMongoClient( | ||
"mongodb+srv://user:[email protected]/?srvServiceName=customname", | ||
connect=False, | ||
) | ||
await client.aconnect() | ||
self.assertEqual(client._topology_settings.srv_service_name, "customname") | ||
await client.close() | ||
|
||
async def test_srv_max_hosts_kwarg(self): | ||
client = self.simple_client("mongodb+srv://test1.test.build.10gen.cc/") | ||
await client.aconnect() | ||
self.assertGreater(len(client.topology_description.server_descriptions()), 1) | ||
client = self.simple_client("mongodb+srv://test1.test.build.10gen.cc/", srvmaxhosts=1) | ||
await client.aconnect() | ||
self.assertEqual(len(client.topology_description.server_descriptions()), 1) | ||
client = self.simple_client( | ||
"mongodb+srv://test1.test.build.10gen.cc/?srvMaxHosts=1", srvmaxhosts=2 | ||
) | ||
await client.aconnect() | ||
self.assertEqual(len(client.topology_description.server_descriptions()), 2) | ||
|
||
@unittest.skipIf( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -185,35 +185,24 @@ def create_tests(cls): | |
|
||
class TestParsingErrors(AsyncPyMongoTestCase): | ||
async def test_invalid_host(self): | ||
self.assertRaisesRegex( | ||
ConfigurationError, | ||
"Invalid URI host: mongodb is not", | ||
self.simple_client, | ||
"mongodb+srv://mongodb", | ||
) | ||
self.assertRaisesRegex( | ||
ConfigurationError, | ||
"Invalid URI host: mongodb.com is not", | ||
self.simple_client, | ||
"mongodb+srv://mongodb.com", | ||
) | ||
self.assertRaisesRegex( | ||
ConfigurationError, | ||
"Invalid URI host: an IP address is not", | ||
self.simple_client, | ||
"mongodb+srv://127.0.0.1", | ||
) | ||
self.assertRaisesRegex( | ||
ConfigurationError, | ||
"Invalid URI host: an IP address is not", | ||
self.simple_client, | ||
"mongodb+srv://[::1]", | ||
) | ||
with self.assertRaisesRegex(ConfigurationError, "Invalid URI host: mongodb is not"): | ||
client = self.simple_client("mongodb+srv://mongodb") | ||
await client.aconnect() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This behavior change is important to call out in the changelog and jira ticket. |
||
with self.assertRaisesRegex(ConfigurationError, "Invalid URI host: mongodb.com is not"): | ||
client = self.simple_client("mongodb+srv://mongodb.com") | ||
await client.aconnect() | ||
with self.assertRaisesRegex(ConfigurationError, "Invalid URI host: an IP address is not"): | ||
client = self.simple_client("mongodb+srv://127.0.0.1") | ||
await client.aconnect() | ||
with self.assertRaisesRegex(ConfigurationError, "Invalid URI host: an IP address is not"): | ||
client = self.simple_client("mongodb+srv://[::1]") | ||
await client.aconnect() | ||
|
||
|
||
class IsolatedAsyncioTestCaseInsensitive(AsyncIntegrationTest): | ||
async def test_connect_case_insensitive(self): | ||
client = self.simple_client("mongodb+srv://TEST1.TEST.BUILD.10GEN.cc/") | ||
await client.aconnect() | ||
self.assertGreater(len(client.topology_description.server_descriptions()), 1) | ||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1868,28 +1868,37 @@ def test_service_name_from_kwargs(self): | |
srvServiceName="customname", | ||
connect=False, | ||
) | ||
client._connect() | ||
self.assertEqual(client._topology_settings.srv_service_name, "customname") | ||
client.close() | ||
client = MongoClient( | ||
"mongodb+srv://user:[email protected]" | ||
"/?srvServiceName=shouldbeoverriden", | ||
srvServiceName="customname", | ||
connect=False, | ||
) | ||
client._connect() | ||
self.assertEqual(client._topology_settings.srv_service_name, "customname") | ||
client.close() | ||
client = MongoClient( | ||
"mongodb+srv://user:[email protected]/?srvServiceName=customname", | ||
connect=False, | ||
) | ||
client._connect() | ||
self.assertEqual(client._topology_settings.srv_service_name, "customname") | ||
client.close() | ||
|
||
def test_srv_max_hosts_kwarg(self): | ||
client = self.simple_client("mongodb+srv://test1.test.build.10gen.cc/") | ||
client._connect() | ||
self.assertGreater(len(client.topology_description.server_descriptions()), 1) | ||
client = self.simple_client("mongodb+srv://test1.test.build.10gen.cc/", srvmaxhosts=1) | ||
client._connect() | ||
self.assertEqual(len(client.topology_description.server_descriptions()), 1) | ||
client = self.simple_client( | ||
"mongodb+srv://test1.test.build.10gen.cc/?srvMaxHosts=1", srvmaxhosts=2 | ||
) | ||
client._connect() | ||
self.assertEqual(len(client.topology_description.server_descriptions()), 2) | ||
|
||
@unittest.skipIf( | ||
|
Uh oh!
There was an error while loading. Please reload this page.