PYTHON-3260 Improve test_transaction_starts_with_batched_write and test_continuous_network_errors (#945)

This commit is contained in:
Shane Harvey 2022-05-10 10:29:48 -07:00 committed by GitHub
parent a1c33e0b84
commit a624197338
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 8 deletions

View File

@ -1596,7 +1596,6 @@ class TestClient(IntegrationTest):
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 @@ class TestClient(IntegrationTest):
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 @@ class TestClient(IntegrationTest):
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):

View File

@ -30,6 +30,8 @@ from test.utils import (
)
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 @@ class TestTransactions(TransactionsBase):
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 @@ class TestTransactions(TransactionsBase):
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):