3030)
3131from test .utils_spec_runner import SpecRunner
3232
33+ from bson import encode
34+ from bson .raw_bson import RawBSONDocument
3335from gridfs import GridFS , GridFSBucket
3436from pymongo import WriteConcern , client_session
3537from 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
353355class PatchSessionTimeout (object ):
0 commit comments