@@ -11,6 +11,7 @@ import (
11
11
"errors"
12
12
"fmt"
13
13
"os"
14
+ "strings"
14
15
"testing"
15
16
"time"
16
17
@@ -69,6 +70,36 @@ func initCollection(t *testing.T, coll *Collection) {
69
70
require .Nil (t , err )
70
71
}
71
72
73
+ func create16MBDocument (t * testing.T ) bsoncore.Document {
74
+ // 4 bytes = document length
75
+ // 1 byte = element type (ObjectID = \x07)
76
+ // 4 bytes = key name ("_id" + \x00)
77
+ // 12 bytes = ObjectID value
78
+ // 1 byte = element type (string = \x02)
79
+ // 4 bytes = key name ("key" + \x00)
80
+ // 4 bytes = string length
81
+ // X bytes = string of length X bytes
82
+ // 1 byte = \x00
83
+ // 1 byte = \x00
84
+ //
85
+ // Therefore the string length should be: 1024*1024*16 - 32
86
+
87
+ targetDocSize := 1024 * 1024 * 16
88
+ strSize := targetDocSize - 32
89
+ var b strings.Builder
90
+ b .Grow (strSize )
91
+ for i := 0 ; i < strSize ; i ++ {
92
+ b .WriteByte ('A' )
93
+ }
94
+
95
+ idx , doc := bsoncore .AppendDocumentStart (nil )
96
+ doc = bsoncore .AppendObjectIDElement (doc , "_id" , primitive .NewObjectID ())
97
+ doc = bsoncore .AppendStringElement (doc , "key" , b .String ())
98
+ doc , _ = bsoncore .AppendDocumentEnd (doc , idx )
99
+ require .Equal (t , targetDocSize , len (doc ), "expected document length %v, got %v" , targetDocSize , len (doc ))
100
+ return doc
101
+ }
102
+
72
103
func TestCollection_initialize (t * testing.T ) {
73
104
dbName := "foo"
74
105
collName := "bar"
@@ -625,6 +656,36 @@ func TestCollection_InsertMany_Batches(t *testing.T) {
625
656
626
657
}
627
658
659
+ func TestCollection_InsertMany_LargeDocumentBatches (t * testing.T ) {
660
+ // TODO(GODRIVER-425): remove this as part a larger project to
661
+ // refactor integration and other longrunning tasks.
662
+ if os .Getenv ("EVR_TASK_ID" ) == "" {
663
+ t .Skip ("skipping long running integration test outside of evergreen" )
664
+ }
665
+
666
+ client := createMonitoredClient (t , monitor )
667
+ db := client .Database ("insertmany_largebatches_db" )
668
+ coll := db .Collection ("insertmany_largebatches_coll" )
669
+ err := coll .Drop (ctx )
670
+ require .NoError (t , err , "Drop error: %v" , err )
671
+ docs := []interface {}{create16MBDocument (t ), create16MBDocument (t )}
672
+
673
+ drainChannels ()
674
+ _ , err = coll .InsertMany (ctx , docs )
675
+ require .NoError (t , err , "InsertMany error: %v" , err )
676
+
677
+ for i := 0 ; i < 2 ; i ++ {
678
+ var evt * event.CommandStartedEvent
679
+ select {
680
+ case evt = <- startedChan :
681
+ default :
682
+ t .Fatalf ("no insert event found for iteration %v" , i )
683
+ }
684
+
685
+ require .Equal (t , "insert" , evt .CommandName , "expected 'insert' event, got '%v'" , evt .CommandName )
686
+ }
687
+ }
688
+
628
689
func TestCollection_InsertMany_ErrorCases (t * testing.T ) {
629
690
if testing .Short () {
630
691
t .Skip ("skipping integration test in short mode" )
0 commit comments