@@ -20,7 +20,6 @@ import (
2020 "github.com/10gen/migration-verifier/internal/testutil"
2121 "github.com/cespare/permute/v2"
2222 "github.com/rs/zerolog"
23- "github.com/rs/zerolog/log"
2423 "github.com/samber/lo"
2524 "github.com/stretchr/testify/assert"
2625 "github.com/stretchr/testify/require"
@@ -29,7 +28,6 @@ import (
2928 "go.mongodb.org/mongo-driver/bson/primitive"
3029 "go.mongodb.org/mongo-driver/mongo"
3130 "go.mongodb.org/mongo-driver/mongo/options"
32- "golang.org/x/sync/errgroup"
3331)
3432
3533func TestIntegration (t * testing.T ) {
@@ -1292,7 +1290,7 @@ func (suite *IntegrationTestSuite) TestGenerationalRechecking() {
12921290 verifier .SetDstNamespaces ([]string {"testDb2.testColl3" })
12931291 verifier .SetNamespaceMap ()
12941292
1295- ctx := context . Background ()
1293+ ctx := suite . Context ()
12961294
12971295 srcColl := suite .srcMongoClient .Database ("testDb1" ).Collection ("testColl1" )
12981296 dstColl := suite .dstMongoClient .Database ("testDb2" ).Collection ("testColl3" )
@@ -1303,18 +1301,7 @@ func (suite *IntegrationTestSuite) TestGenerationalRechecking() {
13031301 _ , err = dstColl .InsertOne (ctx , bson.M {"_id" : 1 , "x" : 42 })
13041302 suite .Require ().NoError (err )
13051303
1306- checkDoneChan := make (chan struct {})
1307- checkContinueChan := make (chan struct {})
1308-
1309- errGroup , errGrpCtx := errgroup .WithContext (context .Background ())
1310- errGroup .Go (func () error {
1311- checkDriverErr := verifier .CheckDriver (errGrpCtx , nil , checkDoneChan , checkContinueChan )
1312- // Log this as fatal error so that the test doesn't hang.
1313- if checkDriverErr != nil {
1314- log .Fatal ().Err (checkDriverErr ).Msg ("check driver error" )
1315- }
1316- return checkDriverErr
1317- })
1304+ runner := RunVerifierCheck (ctx , suite .T (), verifier )
13181305
13191306 waitForTasks := func () * VerificationStatus {
13201307 status , err := verifier .GetVerificationStatus ()
@@ -1326,16 +1313,16 @@ func (suite *IntegrationTestSuite) TestGenerationalRechecking() {
13261313 suite .T ().Logf ("TotalTasks is 0 (generation=%d); waiting %s then will run another generation …" , verifier .generation , delay )
13271314
13281315 time .Sleep (delay )
1329- checkContinueChan <- struct {}{}
1330- <- checkDoneChan
1316+ runner . StartNextGeneration ()
1317+ runner . AwaitGenerationEnd ()
13311318 status , err = verifier .GetVerificationStatus ()
13321319 suite .Require ().NoError (err )
13331320 }
13341321 return status
13351322 }
13361323
13371324 // wait for one generation to finish
1338- <- checkDoneChan
1325+ runner . AwaitGenerationEnd ()
13391326 status := waitForTasks ()
13401327 suite .Require ().Equal (VerificationStatus {TotalTasks : 2 , FailedTasks : 1 , CompletedTasks : 1 }, * status )
13411328
@@ -1344,10 +1331,10 @@ func (suite *IntegrationTestSuite) TestGenerationalRechecking() {
13441331 suite .Require ().NoError (err )
13451332
13461333 // tell check to start the next generation
1347- checkContinueChan <- struct {}{}
1334+ runner . StartNextGeneration ()
13481335
13491336 // wait for generation to finish
1350- <- checkDoneChan
1337+ runner . AwaitGenerationEnd ()
13511338 status = waitForTasks ()
13521339 // there should be no failures now, since they are are equivalent at this point in time
13531340 suite .Require ().Equal (VerificationStatus {TotalTasks : 1 , CompletedTasks : 1 }, * status )
@@ -1357,10 +1344,10 @@ func (suite *IntegrationTestSuite) TestGenerationalRechecking() {
13571344 suite .Require ().NoError (err )
13581345
13591346 // tell check to start the next generation
1360- checkContinueChan <- struct {}{}
1347+ runner . StartNextGeneration ()
13611348
13621349 // wait for one generation to finish
1363- <- checkDoneChan
1350+ runner . AwaitGenerationEnd ()
13641351 status = waitForTasks ()
13651352
13661353 // there should be a failure from the src insert
@@ -1371,19 +1358,20 @@ func (suite *IntegrationTestSuite) TestGenerationalRechecking() {
13711358 suite .Require ().NoError (err )
13721359
13731360 // continue
1374- checkContinueChan <- struct {}{}
1361+ runner . StartNextGeneration ()
13751362
13761363 // wait for it to finish again, this should be a clean run
1377- <- checkDoneChan
1364+ runner . AwaitGenerationEnd ()
13781365 status = waitForTasks ()
13791366
13801367 // there should be no failures now, since they are are equivalent at this point in time
13811368 suite .Assert ().Equal (VerificationStatus {TotalTasks : 1 , CompletedTasks : 1 }, * status )
13821369
1370+ // We could just abandon this verifier, but we might as well shut it down
1371+ // gracefully. That prevents a spurious error in the log from “drop”
1372+ // change events.
13831373 suite .Require ().NoError (verifier .WritesOff (ctx ))
1384-
1385- checkContinueChan <- struct {}{}
1386- require .NoError (suite .T (), errGroup .Wait ())
1374+ suite .Require ().NoError (runner .Await ())
13871375}
13881376
13891377func (suite * IntegrationTestSuite ) TestVerifierWithFilter () {
0 commit comments