Skip to content

Commit 5f7f84a

Browse files
committed
Fix SRV test
1 parent 66b7e8d commit 5f7f84a

File tree

4 files changed

+98
-72
lines changed

4 files changed

+98
-72
lines changed

pymongo/asynchronous/mongo_client.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -1209,9 +1209,7 @@ def topology_description(self) -> TopologyDescription:
12091209
.. versionadded:: 4.0
12101210
"""
12111211
if self._topology is None:
1212-
servers = {
1213-
(host, self._port): ServerDescription((host, self._port)) for host in self._seeds
1214-
}
1212+
servers = {(host, port): ServerDescription((host, port)) for host, port in self._seeds}
12151213
td = TopologyDescription(
12161214
TOPOLOGY_TYPE.Unknown,
12171215
servers,

pymongo/synchronous/mongo_client.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -1207,9 +1207,7 @@ def topology_description(self) -> TopologyDescription:
12071207
.. versionadded:: 4.0
12081208
"""
12091209
if self._topology is None:
1210-
servers = {
1211-
(host, self._port): ServerDescription((host, self._port)) for host in self._seeds
1212-
}
1210+
servers = {(host, port): ServerDescription((host, port)) for host, port in self._seeds}
12131211
td = TopologyDescription(
12141212
TOPOLOGY_TYPE.Unknown,
12151213
servers,

test/asynchronous/test_client.py

+48-33
Original file line numberDiff line numberDiff line change
@@ -815,39 +815,6 @@ async def test_constants(self):
815815

816816
async def test_init_disconnected(self):
817817
host, port = await async_client_context.host, await async_client_context.port
818-
c = await self.async_rs_or_single_client(connect=False)
819-
# nodes returns an empty set if not connected
820-
self.assertEqual(c.nodes, frozenset())
821-
# topology_description returns the initial seed description if not connected
822-
topology_description = c.topology_description
823-
self.assertEqual(topology_description.topology_type, TOPOLOGY_TYPE.Unknown)
824-
self.assertEqual(
825-
topology_description.server_descriptions(),
826-
{(host, port): ServerDescription((host, port))},
827-
)
828-
829-
# address causes client to block until connected
830-
self.assertIsNotNone(await c.address)
831-
# Initial seed topology and connected topology have the same ID
832-
self.assertEqual(
833-
c._topology._topology_id, topology_description._topology_settings._topology_id
834-
)
835-
836-
c = await self.async_rs_or_single_client(connect=False)
837-
# primary causes client to block until connected
838-
await c.primary
839-
self.assertIsNotNone(c._topology)
840-
841-
c = await self.async_rs_or_single_client(connect=False)
842-
# secondaries causes client to block until connected
843-
await c.secondaries
844-
self.assertIsNotNone(c._topology)
845-
846-
c = await self.async_rs_or_single_client(connect=False)
847-
# arbiters causes client to block until connected
848-
await c.arbiters
849-
self.assertIsNotNone(c._topology)
850-
851818
c = await self.async_rs_or_single_client(connect=False)
852819
# is_primary causes client to block until connected
853820
self.assertIsInstance(await c.is_primary, bool)
@@ -882,6 +849,54 @@ async def test_init_disconnected_with_auth(self):
882849
with self.assertRaises(ConnectionFailure):
883850
await c.pymongo_test.test.find_one()
884851

852+
@async_client_context.require_replica_set
853+
@async_client_context.require_tls
854+
async def test_init_disconnected_with_srv(self):
855+
c = await self.async_rs_or_single_client(
856+
"mongodb+srv://test1.test.build.10gen.cc", connect=False, tlsInsecure=True
857+
)
858+
# nodes returns an empty set if not connected
859+
self.assertEqual(c.nodes, frozenset())
860+
# topology_description returns the initial seed description if not connected
861+
topology_description = c.topology_description
862+
self.assertEqual(topology_description.topology_type, TOPOLOGY_TYPE.Unknown)
863+
self.assertEqual(
864+
{
865+
("test1.test.build.10gen.cc", None): ServerDescription(
866+
("test1.test.build.10gen.cc", None)
867+
)
868+
},
869+
topology_description.server_descriptions(),
870+
)
871+
872+
# address causes client to block until connected
873+
self.assertIsNotNone(await c.address)
874+
# Initial seed topology and connected topology have the same ID
875+
self.assertEqual(
876+
c._topology._topology_id, topology_description._topology_settings._topology_id
877+
)
878+
879+
c = await self.async_rs_or_single_client(
880+
"mongodb+srv://test1.test.build.10gen.cc", connect=False, tlsInsecure=True
881+
)
882+
# primary causes client to block until connected
883+
await c.primary
884+
self.assertIsNotNone(c._topology)
885+
886+
c = await self.async_rs_or_single_client(
887+
"mongodb+srv://test1.test.build.10gen.cc", connect=False, tlsInsecure=True
888+
)
889+
# secondaries causes client to block until connected
890+
await c.secondaries
891+
self.assertIsNotNone(c._topology)
892+
893+
c = await self.async_rs_or_single_client(
894+
"mongodb+srv://test1.test.build.10gen.cc", connect=False, tlsInsecure=True
895+
)
896+
# arbiters causes client to block until connected
897+
await c.arbiters
898+
self.assertIsNotNone(c._topology)
899+
885900
async def test_equality(self):
886901
seed = "{}:{}".format(*list(self.client._topology_settings.seeds)[0])
887902
c = await self.async_rs_or_single_client(seed, connect=False)

test/test_client.py

+48-33
Original file line numberDiff line numberDiff line change
@@ -790,39 +790,6 @@ def test_constants(self):
790790

791791
def test_init_disconnected(self):
792792
host, port = client_context.host, client_context.port
793-
c = self.rs_or_single_client(connect=False)
794-
# nodes returns an empty set if not connected
795-
self.assertEqual(c.nodes, frozenset())
796-
# topology_description returns the initial seed description if not connected
797-
topology_description = c.topology_description
798-
self.assertEqual(topology_description.topology_type, TOPOLOGY_TYPE.Unknown)
799-
self.assertEqual(
800-
topology_description.server_descriptions(),
801-
{(host, port): ServerDescription((host, port))},
802-
)
803-
804-
# address causes client to block until connected
805-
self.assertIsNotNone(c.address)
806-
# Initial seed topology and connected topology have the same ID
807-
self.assertEqual(
808-
c._topology._topology_id, topology_description._topology_settings._topology_id
809-
)
810-
811-
c = self.rs_or_single_client(connect=False)
812-
# primary causes client to block until connected
813-
c.primary
814-
self.assertIsNotNone(c._topology)
815-
816-
c = self.rs_or_single_client(connect=False)
817-
# secondaries causes client to block until connected
818-
c.secondaries
819-
self.assertIsNotNone(c._topology)
820-
821-
c = self.rs_or_single_client(connect=False)
822-
# arbiters causes client to block until connected
823-
c.arbiters
824-
self.assertIsNotNone(c._topology)
825-
826793
c = self.rs_or_single_client(connect=False)
827794
# is_primary causes client to block until connected
828795
self.assertIsInstance(c.is_primary, bool)
@@ -857,6 +824,54 @@ def test_init_disconnected_with_auth(self):
857824
with self.assertRaises(ConnectionFailure):
858825
c.pymongo_test.test.find_one()
859826

827+
@client_context.require_replica_set
828+
@client_context.require_tls
829+
def test_init_disconnected_with_srv(self):
830+
c = self.rs_or_single_client(
831+
"mongodb+srv://test1.test.build.10gen.cc", connect=False, tlsInsecure=True
832+
)
833+
# nodes returns an empty set if not connected
834+
self.assertEqual(c.nodes, frozenset())
835+
# topology_description returns the initial seed description if not connected
836+
topology_description = c.topology_description
837+
self.assertEqual(topology_description.topology_type, TOPOLOGY_TYPE.Unknown)
838+
self.assertEqual(
839+
{
840+
("test1.test.build.10gen.cc", None): ServerDescription(
841+
("test1.test.build.10gen.cc", None)
842+
)
843+
},
844+
topology_description.server_descriptions(),
845+
)
846+
847+
# address causes client to block until connected
848+
self.assertIsNotNone(c.address)
849+
# Initial seed topology and connected topology have the same ID
850+
self.assertEqual(
851+
c._topology._topology_id, topology_description._topology_settings._topology_id
852+
)
853+
854+
c = self.rs_or_single_client(
855+
"mongodb+srv://test1.test.build.10gen.cc", connect=False, tlsInsecure=True
856+
)
857+
# primary causes client to block until connected
858+
c.primary
859+
self.assertIsNotNone(c._topology)
860+
861+
c = self.rs_or_single_client(
862+
"mongodb+srv://test1.test.build.10gen.cc", connect=False, tlsInsecure=True
863+
)
864+
# secondaries causes client to block until connected
865+
c.secondaries
866+
self.assertIsNotNone(c._topology)
867+
868+
c = self.rs_or_single_client(
869+
"mongodb+srv://test1.test.build.10gen.cc", connect=False, tlsInsecure=True
870+
)
871+
# arbiters causes client to block until connected
872+
c.arbiters
873+
self.assertIsNotNone(c._topology)
874+
860875
def test_equality(self):
861876
seed = "{}:{}".format(*list(self.client._topology_settings.seeds)[0])
862877
c = self.rs_or_single_client(seed, connect=False)

0 commit comments

Comments
 (0)