3030from test .utils_spec_runner import SpecRunner
3131
3232from bson .py3compat import StringIO
33+ from bson import encode
34+ from bson .raw_bson import RawBSONDocument
35+
3336from gridfs import GridFS , GridFSBucket
3437from pymongo import WriteConcern , client_session
3538from pymongo .client_session import TransactionOptions
@@ -332,14 +335,14 @@ def test_transaction_starts_with_batched_write(self):
332335 listener .reset ()
333336 self .addCleanup (client .close )
334337 self .addCleanup (coll .drop )
335- large_str = "\0 " * (10 * 1024 * 1024 )
336- ops = [InsertOne ({"a" : large_str }) for _ in range (10 )]
338+ large_str = "\0 " * (1 * 1024 * 1024 )
339+ ops = [InsertOne (RawBSONDocument ( encode ( {"a" : large_str }))) for _ in range (48 )]
337340 with client .start_session () as session :
338341 with session .start_transaction ():
339342 coll .bulk_write (ops , session = session )
340343 # Assert commands were constructed properly.
341344 self .assertEqual (
342- ["insert" , "insert" , "insert" , " commitTransaction" ], listener .started_command_names ()
345+ ["insert" , "insert" , "commitTransaction" ], listener .started_command_names ()
343346 )
344347 first_cmd = listener .results ["started" ][0 ].command
345348 self .assertTrue (first_cmd ["startTransaction" ])
@@ -349,7 +352,7 @@ def test_transaction_starts_with_batched_write(self):
349352 self .assertNotIn ("startTransaction" , event .command )
350353 self .assertEqual (lsid , event .command ["lsid" ])
351354 self .assertEqual (txn_number , event .command ["txnNumber" ])
352- self .assertEqual (10 , coll .count_documents ({}))
355+ self .assertEqual (48 , coll .count_documents ({}))
353356
354357
355358class PatchSessionTimeout (object ):
0 commit comments