@@ -1621,7 +1621,6 @@ def test_direct_connection(self):
1621
1621
with self .assertRaises (ConfigurationError ):
1622
1622
MongoClient (["host1" , "host2" ], directConnection = True )
1623
1623
1624
- @unittest .skipIf (sys .platform .startswith ("java" ), "Jython does not support gc.get_objects" )
1625
1624
@unittest .skipIf ("PyPy" in sys .version , "PYTHON-2927 fails often on PyPy" )
1626
1625
def test_continuous_network_errors (self ):
1627
1626
def server_description_count ():
@@ -1637,7 +1636,7 @@ def server_description_count():
1637
1636
gc .collect ()
1638
1637
with client_knobs (min_heartbeat_interval = 0.003 ):
1639
1638
client = MongoClient (
1640
- "invalid:27017" , heartbeatFrequencyMS = 3 , serverSelectionTimeoutMS = 100
1639
+ "invalid:27017" , heartbeatFrequencyMS = 3 , serverSelectionTimeoutMS = 150
1641
1640
)
1642
1641
initial_count = server_description_count ()
1643
1642
self .addCleanup (client .close )
@@ -1651,6 +1650,70 @@ def server_description_count():
1651
1650
# On Python 3.11 we seem to get more of a delta.
1652
1651
self .assertAlmostEqual (initial_count , final_count , delta = 20 )
1653
1652
1653
+ @client_context .require_failCommand_fail_point
1654
+ def test_network_error_message (self ):
1655
+ client = single_client (retryReads = False )
1656
+ self .addCleanup (client .close )
1657
+ client .admin .command ("ping" ) # connect
1658
+ with self .fail_point (
1659
+ {"mode" : {"times" : 1 }, "data" : {"closeConnection" : True , "failCommands" : ["find" ]}}
1660
+ ):
1661
+ expected = "%s:%s: " % client .address
1662
+ with self .assertRaisesRegex (AutoReconnect , expected ):
1663
+ client .pymongo_test .test .find_one ({})
1664
+
1665
+ @unittest .skipIf ("PyPy" in sys .version , "PYTHON-2938 could fail on PyPy" )
1666
+ def test_process_periodic_tasks (self ):
1667
+ client = rs_or_single_client ()
1668
+ coll = client .db .collection
1669
+ coll .insert_many ([{} for _ in range (5 )])
1670
+ cursor = coll .find (batch_size = 2 )
1671
+ cursor .next ()
1672
+ c_id = cursor .cursor_id
1673
+ self .assertIsNotNone (c_id )
1674
+ client .close ()
1675
+ # Add cursor to kill cursors queue
1676
+ del cursor
1677
+ wait_until (
1678
+ lambda : client ._MongoClient__kill_cursors_queue ,
1679
+ "waited for cursor to be added to queue" ,
1680
+ )
1681
+ client ._process_periodic_tasks () # This must not raise or print any exceptions
1682
+ with self .assertRaises (InvalidOperation ):
1683
+ coll .insert_many ([{} for _ in range (5 )])
1684
+
1685
+ @unittest .skipUnless (_HAVE_DNSPYTHON , "DNS-related tests need dnspython to be installed" )
1686
+ def test_service_name_from_kwargs (self ):
1687
+ client = MongoClient (
1688
+ "mongodb+srv://user:[email protected] " ,
1689
+ srvServiceName = "customname" ,
1690
+ connect = False ,
1691
+ )
1692
+ self .assertEqual (client ._topology_settings .srv_service_name , "customname" )
1693
+ client = MongoClient (
1694
+ "mongodb+srv://user:[email protected] "
1695
+ "/?srvServiceName=shouldbeoverriden" ,
1696
+ srvServiceName = "customname" ,
1697
+ connect = False ,
1698
+ )
1699
+ self .assertEqual (client ._topology_settings .srv_service_name , "customname" )
1700
+ client = MongoClient (
1701
+ "mongodb+srv://user:[email protected] /?srvServiceName=customname" ,
1702
+ connect = False ,
1703
+ )
1704
+ self .assertEqual (client ._topology_settings .srv_service_name , "customname" )
1705
+
1706
+ @unittest .skipUnless (_HAVE_DNSPYTHON , "DNS-related tests need dnspython to be installed" )
1707
+ def test_srv_max_hosts_kwarg (self ):
1708
+ client = MongoClient ("mongodb+srv://test1.test.build.10gen.cc/" )
1709
+ self .assertGreater (len (client .topology_description .server_descriptions ()), 1 )
1710
+ client = MongoClient ("mongodb+srv://test1.test.build.10gen.cc/" , srvmaxhosts = 1 )
1711
+ self .assertEqual (len (client .topology_description .server_descriptions ()), 1 )
1712
+ client = MongoClient (
1713
+ "mongodb+srv://test1.test.build.10gen.cc/?srvMaxHosts=1" , srvmaxhosts = 2
1714
+ )
1715
+ self .assertEqual (len (client .topology_description .server_descriptions ()), 2 )
1716
+
1654
1717
@unittest .skipIf (_HAVE_DNSPYTHON , "dnspython must not be installed" )
1655
1718
def test_srv_no_dnspython_error (self ):
1656
1719
with self .assertRaisesRegex (ConfigurationError , 'The "dnspython" module must be' ):
0 commit comments