Skip to content

Commit a624197

Browse files
authored
PYTHON-3260 Improve test_transaction_starts_with_batched_write and test_continuous_network_errors (#945)
1 parent a1c33e0 commit a624197

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

test/test_client.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1596,7 +1596,6 @@ def test_direct_connection(self):
15961596
with self.assertRaises(ConfigurationError):
15971597
MongoClient(["host1", "host2"], directConnection=True)
15981598

1599-
@unittest.skipIf(sys.platform.startswith("java"), "Jython does not support gc.get_objects")
16001599
@unittest.skipIf("PyPy" in sys.version, "PYTHON-2927 fails often on PyPy")
16011600
def test_continuous_network_errors(self):
16021601
def server_description_count():
@@ -1612,7 +1611,7 @@ def server_description_count():
16121611
gc.collect()
16131612
with client_knobs(min_heartbeat_interval=0.003):
16141613
client = MongoClient(
1615-
"invalid:27017", heartbeatFrequencyMS=3, serverSelectionTimeoutMS=100
1614+
"invalid:27017", heartbeatFrequencyMS=3, serverSelectionTimeoutMS=150
16161615
)
16171616
initial_count = server_description_count()
16181617
self.addCleanup(client.close)
@@ -1622,8 +1621,8 @@ def server_description_count():
16221621
final_count = server_description_count()
16231622
# If a bug like PYTHON-2433 is reintroduced then too many
16241623
# ServerDescriptions will be kept alive and this test will fail:
1625-
# AssertionError: 4 != 22 within 5 delta (18 difference)
1626-
self.assertAlmostEqual(initial_count, final_count, delta=10)
1624+
# AssertionError: 19 != 46 within 15 delta (27 difference)
1625+
self.assertAlmostEqual(initial_count, final_count, delta=15)
16271626

16281627
@client_context.require_failCommand_fail_point
16291628
def test_network_error_message(self):

test/test_transactions.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
)
3131
from test.utils_spec_runner import SpecRunner
3232

33+
from bson import encode
34+
from bson.raw_bson import RawBSONDocument
3335
from gridfs import GridFS, GridFSBucket
3436
from pymongo import WriteConcern, client_session
3537
from pymongo.client_session import TransactionOptions
@@ -330,14 +332,14 @@ def test_transaction_starts_with_batched_write(self):
330332
listener.reset()
331333
self.addCleanup(client.close)
332334
self.addCleanup(coll.drop)
333-
large_str = "\0" * (10 * 1024 * 1024)
334-
ops = [InsertOne({"a": large_str}) for _ in range(10)]
335+
large_str = "\0" * (1 * 1024 * 1024)
336+
ops = [InsertOne(RawBSONDocument(encode({"a": large_str}))) for _ in range(48)]
335337
with client.start_session() as session:
336338
with session.start_transaction():
337339
coll.bulk_write(ops, session=session)
338340
# Assert commands were constructed properly.
339341
self.assertEqual(
340-
["insert", "insert", "insert", "commitTransaction"], listener.started_command_names()
342+
["insert", "insert", "commitTransaction"], listener.started_command_names()
341343
)
342344
first_cmd = listener.results["started"][0].command
343345
self.assertTrue(first_cmd["startTransaction"])
@@ -347,7 +349,7 @@ def test_transaction_starts_with_batched_write(self):
347349
self.assertNotIn("startTransaction", event.command)
348350
self.assertEqual(lsid, event.command["lsid"])
349351
self.assertEqual(txn_number, event.command["txnNumber"])
350-
self.assertEqual(10, coll.count_documents({}))
352+
self.assertEqual(48, coll.count_documents({}))
351353

352354

353355
class PatchSessionTimeout(object):

0 commit comments

Comments
 (0)