@@ -2,13 +2,16 @@ package verifier
22
33import (
44 "context"
5+ "strings"
56 "testing"
67 "time"
78
9+ "github.com/10gen/migration-verifier/internal/testutil"
810 "github.com/10gen/migration-verifier/internal/util"
911 "github.com/10gen/migration-verifier/mslices"
1012 "github.com/pkg/errors"
1113 "github.com/samber/lo"
14+ "github.com/stretchr/testify/assert"
1215 "github.com/stretchr/testify/require"
1316 "go.mongodb.org/mongo-driver/bson"
1417 "go.mongodb.org/mongo-driver/bson/primitive"
@@ -20,19 +23,24 @@ import (
2023func TestChangeStreamFilter (t * testing.T ) {
2124 verifier := Verifier {}
2225 verifier .SetMetaDBName ("metadb" )
23- require .Equal (t , []bson.D {{{"$match" , bson.D {{"ns.db" , bson.D {{"$ne" , "metadb" }}}}}}},
24- verifier .GetChangeStreamFilter ())
26+ assert .Contains (t ,
27+ verifier .GetChangeStreamFilter (),
28+ bson.D {
29+ {"$match" , bson.D {{"ns.db" , bson.D {{"$ne" , "metadb" }}}}},
30+ },
31+ )
2532 verifier .srcNamespaces = []string {"foo.bar" , "foo.baz" , "test.car" , "test.chaz" }
26- require .Equal (t , []bson.D {
27- {{"$match" , bson.D {
28- {"$or" , bson.A {
29- bson.D {{"ns" , bson.D {{"db" , "foo" }, {"coll" , "bar" }}}},
30- bson.D {{"ns" , bson.D {{"db" , "foo" }, {"coll" , "baz" }}}},
31- bson.D {{"ns" , bson.D {{"db" , "test" }, {"coll" , "car" }}}},
32- bson.D {{"ns" , bson.D {{"db" , "test" }, {"coll" , "chaz" }}}},
33+ assert .Contains (t ,
34+ verifier .GetChangeStreamFilter (),
35+ bson.D {{"$match" , bson.D {
36+ {"$or" , []bson.D {
37+ {{"ns" , bson.D {{"db" , "foo" }, {"coll" , "bar" }}}},
38+ {{"ns" , bson.D {{"db" , "foo" }, {"coll" , "baz" }}}},
39+ {{"ns" , bson.D {{"db" , "test" }, {"coll" , "car" }}}},
40+ {{"ns" , bson.D {{"db" , "test" }, {"coll" , "chaz" }}}},
3341 }},
3442 }}},
35- }, verifier . GetChangeStreamFilter () )
43+ )
3644}
3745
3846// TestChangeStreamResumability creates a verifier, starts its change stream,
@@ -445,3 +453,59 @@ func (suite *IntegrationTestSuite) TestCreateForbidden() {
445453 suite .Require ().ErrorAs (err , & eventErr )
446454 suite .Assert ().Equal ("create" , eventErr .Event .OpType )
447455}
456+
457+ func (suite * IntegrationTestSuite ) TestLargeEvents () {
458+ ctx := suite .Context ()
459+
460+ docID := 123
461+
462+ makeDoc := func (char string , len int ) bson.D {
463+ return bson.D {{"_id" , docID }, {"str" , strings .Repeat (char , len )}}
464+ }
465+
466+ smallDoc := testutil .MustMarshal (makeDoc ("a" , 1 ))
467+ suite .T ().Logf ("small size: %v" , len (smallDoc ))
468+ maxBSONSize := 16 * 1024 * 1024
469+
470+ maxStringLen := maxBSONSize - len (smallDoc ) - 1
471+
472+ db := suite .srcMongoClient .Database (suite .DBNameForTest ())
473+ suite .Require ().NoError (db .CreateCollection (ctx , "mystuff" ))
474+
475+ verifier := suite .BuildVerifier ()
476+ verifierRunner := RunVerifierCheck (suite .Context (), suite .T (), verifier )
477+ suite .Require ().NoError (verifierRunner .AwaitGenerationEnd ())
478+
479+ coll := db .Collection ("mystuff" )
480+ _ , err := coll .InsertOne (
481+ ctx ,
482+ makeDoc ("a" , maxStringLen ),
483+ )
484+ suite .Require ().NoError (err , "should insert" )
485+
486+ updated , err := coll .UpdateByID (
487+ ctx ,
488+ docID ,
489+ bson.D {
490+ {"$set" , bson.D {
491+ // smallDoc happens to be the minimum length to subtract
492+ // in order to satisfy the server’s requirements on
493+ // document sizes in updates.
494+ {"str" , strings .Repeat ("b" , maxStringLen - len (smallDoc ))},
495+ }},
496+ },
497+ )
498+ suite .Require ().NoError (err , "should update" )
499+ suite .Require ().EqualValues (1 , updated .ModifiedCount )
500+
501+ replaced , err := coll .ReplaceOne (
502+ ctx ,
503+ bson.D {{"_id" , docID }},
504+ makeDoc ("c" , maxStringLen - len (smallDoc )),
505+ )
506+ suite .Require ().NoError (err , "should replace" )
507+ suite .Require ().EqualValues (1 , replaced .ModifiedCount )
508+
509+ suite .Require ().NoError (verifier .WritesOff (ctx ))
510+ suite .Require ().NoError (verifierRunner .Await ())
511+ }
0 commit comments