@@ -177,6 +177,60 @@ func TestCSOTProse(t *testing.T) {
177177 "expected ping to fail within 150ms" )
178178 })
179179 })
180+
181+ mt .RunOpts ("11. multi-batch bulkWrites" , mtest .NewOptions ().MinServerVersion ("8.0" ).
182+ AtlasDataLake (false ).Topologies (mtest .Single ), func (mt * mtest.T ) {
183+ coll := mt .CreateCollection (mtest.Collection {DB : "db" , Name : "coll" }, false )
184+ err := coll .Drop (context .Background ())
185+ require .NoError (mt , err , "Drop error: %v" , err )
186+
187+ mt .SetFailPoint (failpoint.FailPoint {
188+ ConfigureFailPoint : "failCommand" ,
189+ Mode : failpoint.Mode {
190+ Times : 2 ,
191+ },
192+ Data : failpoint.Data {
193+ FailCommands : []string {"bulkWrite" },
194+ BlockConnection : true ,
195+ BlockTimeMS : 1010 ,
196+ },
197+ })
198+
199+ var hello struct {
200+ MaxBsonObjectSize int
201+ MaxMessageSizeBytes int
202+ }
203+ err = mt .DB .RunCommand (context .Background (), bson.D {{"hello" , 1 }}).Decode (& hello )
204+ require .NoError (mt , err , "Hello error: %v" , err )
205+
206+ models := & mongo.ClientWriteModels {}
207+ n := hello .MaxMessageSizeBytes / hello .MaxBsonObjectSize + 1
208+ for i := 0 ; i < n ; i ++ {
209+ models .
210+ AppendInsertOne ("db" , "coll" , & mongo.ClientInsertOneModel {
211+ Document : bson.D {{"a" , strings .Repeat ("b" , hello .MaxBsonObjectSize - 500 )}},
212+ })
213+ }
214+
215+ var cnt int
216+ cm := & event.CommandMonitor {
217+ Started : func (_ context.Context , evt * event.CommandStartedEvent ) {
218+ if evt .CommandName == "bulkWrite" {
219+ cnt ++
220+ }
221+ },
222+ }
223+ cliOptions := options .Client ().
224+ SetTimeout (2 * time .Second ).
225+ SetMonitor (cm ).
226+ ApplyURI (mtest .ClusterURI ())
227+ integtest .AddTestServerAPIVersion (cliOptions )
228+ cli , err := mongo .Connect (cliOptions )
229+ require .NoError (mt , err , "Connect error: %v" , err )
230+ _ , err = cli .BulkWrite (context .Background (), models )
231+ assert .ErrorContains (mt , err , "context deadline exceeded" , "expected a timeout error, got: %v" , err )
232+ assert .Equal (mt , 2 , cnt , "expected bulkWrite calls: %d, got: %d" , 2 , cnt )
233+ })
180234}
181235
182236func TestCSOTProse_GridFS (t * testing.T ) {
0 commit comments