Skip to content

Commit f5836b3

Browse files
authored
PYTHON-5346: [v4.12] test_init_disconnected_with_srv cannot run against sharded Topologies (#2304) (#2309)
1 parent 38bc13d commit f5836b3

File tree

2 files changed

+104
-0
lines changed

2 files changed

+104
-0
lines changed

test/asynchronous/test_client.py

+52
Original file line numberDiff line numberDiff line change
@@ -849,6 +849,58 @@ async def test_init_disconnected_with_auth(self):
849849
with self.assertRaises(ConnectionFailure):
850850
await c.pymongo_test.test.find_one()
851851

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

test/test_client.py

+52
Original file line numberDiff line numberDiff line change
@@ -824,6 +824,58 @@ def test_init_disconnected_with_auth(self):
824824
with self.assertRaises(ConnectionFailure):
825825
c.pymongo_test.test.find_one()
826826

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

0 commit comments

Comments
 (0)