diff --git a/test/test_client.py b/test/test_client.py index 59a8324d6e..3630cec06c 100644 --- a/test/test_client.py +++ b/test/test_client.py @@ -1596,7 +1596,6 @@ def test_direct_connection(self): with self.assertRaises(ConfigurationError): MongoClient(["host1", "host2"], directConnection=True) - @unittest.skipIf(sys.platform.startswith("java"), "Jython does not support gc.get_objects") @unittest.skipIf("PyPy" in sys.version, "PYTHON-2927 fails often on PyPy") def test_continuous_network_errors(self): def server_description_count(): @@ -1612,7 +1611,7 @@ def server_description_count(): gc.collect() with client_knobs(min_heartbeat_interval=0.003): client = MongoClient( - "invalid:27017", heartbeatFrequencyMS=3, serverSelectionTimeoutMS=100 + "invalid:27017", heartbeatFrequencyMS=3, serverSelectionTimeoutMS=150 ) initial_count = server_description_count() self.addCleanup(client.close) @@ -1622,8 +1621,8 @@ def server_description_count(): final_count = server_description_count() # If a bug like PYTHON-2433 is reintroduced then too many # ServerDescriptions will be kept alive and this test will fail: - # AssertionError: 4 != 22 within 5 delta (18 difference) - self.assertAlmostEqual(initial_count, final_count, delta=10) + # AssertionError: 19 != 46 within 15 delta (27 difference) + self.assertAlmostEqual(initial_count, final_count, delta=15) @client_context.require_failCommand_fail_point def test_network_error_message(self): diff --git a/test/test_transactions.py b/test/test_transactions.py index 34dbbba34b..136a19baaa 100644 --- a/test/test_transactions.py +++ b/test/test_transactions.py @@ -30,6 +30,8 @@ ) from test.utils_spec_runner import SpecRunner +from bson import encode +from bson.raw_bson import RawBSONDocument from gridfs import GridFS, GridFSBucket from pymongo import WriteConcern, client_session from pymongo.client_session import TransactionOptions @@ -330,14 +332,14 @@ def test_transaction_starts_with_batched_write(self): listener.reset() self.addCleanup(client.close) self.addCleanup(coll.drop) - large_str = "\0" * (10 * 1024 * 1024) - ops = [InsertOne({"a": large_str}) for _ in range(10)] + large_str = "\0" * (1 * 1024 * 1024) + ops = [InsertOne(RawBSONDocument(encode({"a": large_str}))) for _ in range(48)] with client.start_session() as session: with session.start_transaction(): coll.bulk_write(ops, session=session) # Assert commands were constructed properly. self.assertEqual( - ["insert", "insert", "insert", "commitTransaction"], listener.started_command_names() + ["insert", "insert", "commitTransaction"], listener.started_command_names() ) first_cmd = listener.results["started"][0].command self.assertTrue(first_cmd["startTransaction"]) @@ -347,7 +349,7 @@ def test_transaction_starts_with_batched_write(self): self.assertNotIn("startTransaction", event.command) self.assertEqual(lsid, event.command["lsid"]) self.assertEqual(txn_number, event.command["txnNumber"]) - self.assertEqual(10, coll.count_documents({})) + self.assertEqual(48, coll.count_documents({})) class PatchSessionTimeout(object):