Skip to content

Commit 6001a4b

Browse files
committed
Merge branch 'main' into felipe_hide_updatedescription
2 parents 4618e0c + 5fc7a04 commit 6001a4b

File tree

4 files changed

+101
-25
lines changed

4 files changed

+101
-25
lines changed

internal/verifier/change_stream_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ func (suite *IntegrationTestSuite) TestCursorKilledResilience() {
282282
verifierRunner := RunVerifierCheck(suite.Context(), suite.T(), verifier)
283283

284284
// wait for generation 0 to end
285-
verifierRunner.AwaitGenerationEnd()
285+
suite.Require().NoError(verifierRunner.AwaitGenerationEnd())
286286

287287
const mvName = "Migration Verifier"
288288

@@ -376,7 +376,7 @@ func (suite *IntegrationTestSuite) testInsertsBeforeWritesOff(docsCount int) {
376376
verifierRunner := RunVerifierCheck(suite.Context(), suite.T(), verifier)
377377

378378
// wait for generation 0 to end
379-
verifierRunner.AwaitGenerationEnd()
379+
suite.Require().NoError(verifierRunner.AwaitGenerationEnd())
380380

381381
docs := lo.RepeatBy(docsCount, func(_ int) bson.D { return bson.D{} })
382382
_, err := coll.InsertMany(
@@ -426,7 +426,7 @@ func (suite *IntegrationTestSuite) TestCreateForbidden() {
426426
verifierRunner := RunVerifierCheck(suite.Context(), suite.T(), verifier)
427427

428428
// wait for generation 0 to end
429-
verifierRunner.AwaitGenerationEnd()
429+
suite.Require().NoError(verifierRunner.AwaitGenerationEnd())
430430

431431
db := suite.srcMongoClient.Database(suite.DBNameForTest())
432432
coll := db.Collection("mycoll")

internal/verifier/check_runner.go

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package verifier
33
import (
44
"context"
55
"testing"
6+
7+
"github.com/pkg/errors"
68
)
79

810
type CheckRunner struct {
@@ -30,14 +32,25 @@ func RunVerifierCheck(ctx context.Context, t *testing.T, verifier *Verifier) *Ch
3032
}
3133

3234
// AwaitGenerationEnd blocks until the check’s current generation ends.
33-
func (cr *CheckRunner) AwaitGenerationEnd() {
34-
<-cr.generationDoneChan
35+
func (cr *CheckRunner) AwaitGenerationEnd() error {
36+
select {
37+
case <-cr.generationDoneChan:
38+
return nil
39+
case err := <-cr.checkDoneChan:
40+
return errors.Wrap(err, "verifier failed while test awaited generation completion")
41+
}
3542
}
3643

3744
// StartNextGeneration blocks until it can tell the check to start
3845
// the next generation.
39-
func (cr *CheckRunner) StartNextGeneration() {
40-
cr.doNextGenerationChan <- struct{}{}
46+
func (cr *CheckRunner) StartNextGeneration() error {
47+
select {
48+
case cr.doNextGenerationChan <- struct{}{}:
49+
return nil
50+
case err := <-cr.checkDoneChan:
51+
return errors.Wrap(err, "verifier failed while test waited to start next generation")
52+
}
53+
4154
}
4255

4356
// Await will await generations and start new ones until the check

internal/verifier/migration_verifier.go

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"github.com/10gen/migration-verifier/option"
2828
"github.com/olekukonko/tablewriter"
2929
"github.com/pkg/errors"
30+
"github.com/samber/lo"
3031
"go.mongodb.org/mongo-driver/bson"
3132
"go.mongodb.org/mongo-driver/bson/primitive"
3233
"go.mongodb.org/mongo-driver/mongo"
@@ -888,6 +889,14 @@ func (verifier *Verifier) doIndexSpecsMatch(ctx context.Context, srcSpec bson.Ra
888889
return true, nil
889890
}
890891

892+
var fieldsToRemove = []string{
893+
// v4.4 stopped adding “ns” to index fields.
894+
"ns",
895+
896+
// v4.2+ ignores this field.
897+
"background",
898+
}
899+
891900
// Next check to see if the only differences are type differences.
892901
// (We can safely use $documents here since this is against the metadata
893902
// cluster, which we can require to be v5+.)
@@ -904,12 +913,13 @@ func (verifier *Verifier) doIndexSpecsMatch(ctx context.Context, srcSpec bson.Ra
904913
{"dstSpec", dstSpec},
905914
}}},
906915

907-
// Remove the “ns” field from both. (NB: 4.4+ don’t create these,
908-
// though in-place upgrades may cause them still to exist.)
909-
{{"$addFields", bson.D{
910-
{"spec.ns", "$$REMOVE"},
911-
{"dstSpec.ns", "$$REMOVE"},
912-
}}},
916+
{{"$unset", lo.Reduce(
917+
fieldsToRemove,
918+
func(cur []string, field string, _ int) []string {
919+
return append(cur, "spec."+field, "dstSpec."+field)
920+
},
921+
[]string{},
922+
)}},
913923

914924
// Now check to be sure that those specs match.
915925
{{"$match", bson.D{

internal/verifier/migration_verifier_test.go

Lines changed: 65 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1245,7 +1245,7 @@ func (suite *IntegrationTestSuite) TestMetadataMismatchAndPartitioning() {
12451245
suite.Require().NoError(err)
12461246

12471247
runner := RunVerifierCheck(ctx, suite.T(), verifier)
1248-
runner.AwaitGenerationEnd()
1248+
suite.Require().NoError(runner.AwaitGenerationEnd())
12491249

12501250
cursor, err := verifier.verificationTaskCollection().Find(
12511251
ctx,
@@ -1263,8 +1263,8 @@ func (suite *IntegrationTestSuite) TestMetadataMismatchAndPartitioning() {
12631263
suite.Require().Equal(verificationTaskVerifyCollection, tasks[1].Type)
12641264
suite.Require().Equal(verificationTaskMetadataMismatch, tasks[1].Status)
12651265

1266-
runner.StartNextGeneration()
1267-
runner.AwaitGenerationEnd()
1266+
suite.Require().NoError(runner.StartNextGeneration())
1267+
suite.Require().NoError(runner.AwaitGenerationEnd())
12681268

12691269
cursor, err = verifier.verificationTaskCollection().Find(
12701270
ctx,
@@ -1310,16 +1310,16 @@ func (suite *IntegrationTestSuite) TestGenerationalRechecking() {
13101310
suite.T().Logf("TotalTasks is 0 (generation=%d); waiting %s then will run another generation …", verifier.generation, delay)
13111311

13121312
time.Sleep(delay)
1313-
runner.StartNextGeneration()
1314-
runner.AwaitGenerationEnd()
1313+
suite.Require().NoError(runner.StartNextGeneration())
1314+
suite.Require().NoError(runner.AwaitGenerationEnd())
13151315
status, err = verifier.GetVerificationStatus()
13161316
suite.Require().NoError(err)
13171317
}
13181318
return status
13191319
}
13201320

13211321
// wait for one generation to finish
1322-
runner.AwaitGenerationEnd()
1322+
suite.Require().NoError(runner.AwaitGenerationEnd())
13231323
status := waitForTasks()
13241324
suite.Require().Equal(VerificationStatus{TotalTasks: 2, FailedTasks: 1, CompletedTasks: 1}, *status)
13251325

@@ -1328,10 +1328,10 @@ func (suite *IntegrationTestSuite) TestGenerationalRechecking() {
13281328
suite.Require().NoError(err)
13291329

13301330
// tell check to start the next generation
1331-
runner.StartNextGeneration()
1331+
suite.Require().NoError(runner.StartNextGeneration())
13321332

13331333
// wait for generation to finish
1334-
runner.AwaitGenerationEnd()
1334+
suite.Require().NoError(runner.AwaitGenerationEnd())
13351335
status = waitForTasks()
13361336
// there should be no failures now, since they are are equivalent at this point in time
13371337
suite.Require().Equal(VerificationStatus{TotalTasks: 1, CompletedTasks: 1}, *status)
@@ -1341,10 +1341,10 @@ func (suite *IntegrationTestSuite) TestGenerationalRechecking() {
13411341
suite.Require().NoError(err)
13421342

13431343
// tell check to start the next generation
1344-
runner.StartNextGeneration()
1344+
suite.Require().NoError(runner.StartNextGeneration())
13451345

13461346
// wait for one generation to finish
1347-
runner.AwaitGenerationEnd()
1347+
suite.Require().NoError(runner.AwaitGenerationEnd())
13481348
status = waitForTasks()
13491349

13501350
// there should be a failure from the src insert
@@ -1355,10 +1355,10 @@ func (suite *IntegrationTestSuite) TestGenerationalRechecking() {
13551355
suite.Require().NoError(err)
13561356

13571357
// continue
1358-
runner.StartNextGeneration()
1358+
suite.Require().NoError(runner.StartNextGeneration())
13591359

13601360
// wait for it to finish again, this should be a clean run
1361-
runner.AwaitGenerationEnd()
1361+
suite.Require().NoError(runner.AwaitGenerationEnd())
13621362
status = waitForTasks()
13631363

13641364
// there should be no failures now, since they are are equivalent at this point in time
@@ -1493,6 +1493,59 @@ func (suite *IntegrationTestSuite) TestVerifierWithFilter() {
14931493
<-checkDoneChan
14941494
}
14951495

1496+
func (suite *IntegrationTestSuite) TestBackgroundInIndexSpec() {
1497+
ctx := suite.Context()
1498+
1499+
srcDB := suite.srcMongoClient.Database(suite.DBNameForTest())
1500+
dstDB := suite.dstMongoClient.Database(suite.DBNameForTest())
1501+
1502+
suite.Require().NoError(
1503+
srcDB.RunCommand(
1504+
ctx,
1505+
bson.D{
1506+
{"createIndexes", "mycoll"},
1507+
{"indexes", []bson.D{
1508+
{
1509+
{"name", "index1"},
1510+
{"key", bson.D{{"someField", 1}}},
1511+
},
1512+
}},
1513+
},
1514+
).Err(),
1515+
)
1516+
1517+
suite.Require().NoError(
1518+
dstDB.RunCommand(
1519+
ctx,
1520+
bson.D{
1521+
{"createIndexes", "mycoll"},
1522+
{"indexes", []bson.D{
1523+
{
1524+
{"name", "index1"},
1525+
{"key", bson.D{{"someField", 1}}},
1526+
{"background", 1},
1527+
},
1528+
}},
1529+
},
1530+
).Err(),
1531+
)
1532+
1533+
verifier := suite.BuildVerifier()
1534+
verifier.SetSrcNamespaces([]string{srcDB.Name() + ".mycoll"})
1535+
verifier.SetDstNamespaces([]string{dstDB.Name() + ".mycoll"})
1536+
verifier.SetNamespaceMap()
1537+
1538+
runner := RunVerifierCheck(ctx, suite.T(), verifier)
1539+
runner.AwaitGenerationEnd()
1540+
1541+
status, err := verifier.GetVerificationStatus()
1542+
suite.Require().NoError(err)
1543+
suite.Assert().Zero(
1544+
status.MetadataMismatchTasks,
1545+
"no metadata mismatch",
1546+
)
1547+
}
1548+
14961549
func (suite *IntegrationTestSuite) TestPartitionWithFilter() {
14971550
zerolog.SetGlobalLevel(zerolog.DebugLevel)
14981551

0 commit comments

Comments
 (0)