@@ -567,6 +567,113 @@ func (suite *IntegrationTestSuite) TestVerifierFetchDocuments() {
567567 )
568568}
569569
570+ func (suite * IntegrationTestSuite ) TestGetPersistedNamespaceStatistics_Metadata () {
571+ ctx := suite .Context ()
572+ verifier := suite .BuildVerifier ()
573+ verifier .SetVerifyAll (true )
574+
575+ dbName := suite .DBNameForTest ()
576+
577+ err := verifier .srcClient .Database (dbName ).CreateCollection (
578+ ctx ,
579+ "foo" ,
580+ )
581+ suite .Require ().NoError (err )
582+
583+ runner := RunVerifierCheck (ctx , suite .T (), verifier )
584+ suite .Require ().NoError (runner .AwaitGenerationEnd ())
585+
586+ stats , err := verifier .GetPersistedNamespaceStatistics (ctx )
587+ suite .Require ().NoError (err )
588+
589+ suite .Assert ().Equal (
590+ mslices .Of (NamespaceStats {
591+ Namespace : dbName + ".foo" ,
592+ }),
593+ stats ,
594+ "stats should be as expected" ,
595+ )
596+
597+ suite .Require ().NoError (runner .StartNextGeneration ())
598+ suite .Require ().NoError (runner .AwaitGenerationEnd ())
599+
600+ stats , err = verifier .GetPersistedNamespaceStatistics (ctx )
601+ suite .Require ().NoError (err )
602+
603+ suite .Assert ().Equal (
604+ mslices .Of (NamespaceStats {
605+ Namespace : dbName + ".foo" ,
606+ }),
607+ stats ,
608+ "stats should be as expected" ,
609+ )
610+ }
611+
612+ func (suite * IntegrationTestSuite ) TestGetPersistedNamespaceStatistics_OneDoc () {
613+ ctx := suite .Context ()
614+ verifier := suite .BuildVerifier ()
615+ verifier .SetVerifyAll (true )
616+
617+ bsonDoc := lo .Must (bson .Marshal (bson.D {{"_id" , "foo" }}))
618+
619+ dbName := suite .DBNameForTest ()
620+ _ , err := verifier .srcClient .Database (dbName ).Collection ("foo" ).
621+ InsertOne (ctx , bsonDoc )
622+ suite .Require ().NoError (err )
623+
624+ err = verifier .dstClient .Database (dbName ).CreateCollection (
625+ ctx ,
626+ "foo" ,
627+ )
628+ suite .Require ().NoError (err )
629+
630+ runner := RunVerifierCheck (ctx , suite .T (), verifier )
631+ suite .Require ().NoError (runner .AwaitGenerationEnd ())
632+
633+ stats , err := verifier .GetPersistedNamespaceStatistics (ctx )
634+ suite .Require ().NoError (err )
635+
636+ suite .Require ().NotEmpty (stats )
637+ suite .Assert ().NotZero (stats [0 ].BytesCompared , "bytes compared should be set" )
638+
639+ suite .Assert ().Equal (
640+ mslices .Of (NamespaceStats {
641+ Namespace : dbName + ".foo" ,
642+ DocsCompared : 1 ,
643+ TotalDocs : 1 ,
644+ BytesCompared : stats [0 ].BytesCompared ,
645+ TotalBytes : types .ByteCount (len (bsonDoc )),
646+ PartitionsDone : 1 ,
647+ }),
648+ stats ,
649+ "stats should be as expected" ,
650+ )
651+
652+ suite .Require ().NoError (runner .StartNextGeneration ())
653+ suite .Require ().NoError (runner .AwaitGenerationEnd ())
654+
655+ stats , err = verifier .GetPersistedNamespaceStatistics (ctx )
656+ suite .Require ().NoError (err )
657+
658+ suite .Require ().NotEmpty (stats )
659+ suite .Assert ().NotZero (stats [0 ].BytesCompared , "bytes compared should be set" )
660+
661+ suite .Assert ().Equal (
662+ mslices .Of (NamespaceStats {
663+ Namespace : dbName + ".foo" ,
664+ DocsCompared : 1 ,
665+ TotalDocs : 1 ,
666+ BytesCompared : stats [0 ].BytesCompared ,
667+ PartitionsDone : 1 ,
668+
669+ // NB: TotalBytes is 0 because we can’t compute that from the
670+ // change stream.
671+ }),
672+ stats ,
673+ "stats should be as expected" ,
674+ )
675+ }
676+
570677func (suite * IntegrationTestSuite ) TestGetPersistedNamespaceStatistics_Recheck () {
571678 ctx := suite .Context ()
572679 verifier := suite .BuildVerifier ()
0 commit comments