Skip to content

Commit 82effb4

Browse files
committed
save
1 parent 7c547be commit 82effb4

File tree

9 files changed

+548
-304
lines changed

9 files changed

+548
-304
lines changed

internal/util/askserver.go

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package util
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"slices"
7+
8+
"github.com/10gen/migration-verifier/mslices"
9+
"github.com/10gen/migration-verifier/option"
10+
"github.com/pkg/errors"
11+
"go.mongodb.org/mongo-driver/bson"
12+
"go.mongodb.org/mongo-driver/mongo"
13+
)
14+
15+
// ServerThinksTheseMatch runs an aggregation on the server that determines
16+
// whether the server thinks a & b are equal. This allows you, e.g., to
17+
// ignore BSON type differences for equivalent numbers.
18+
func ServerThinksTheseMatch(
19+
ctx context.Context,
20+
client *mongo.Client,
21+
a, b any,
22+
tinker option.Option[mongo.Pipeline],
23+
) (bool, error) {
24+
fmt.Printf("----------- a: %+v\n\n", a)
25+
fmt.Printf("----------- b: %+v\n\n", b)
26+
27+
pipeline := mongo.Pipeline{
28+
{{"$documents", []bson.D{
29+
{
30+
{"a", bson.D{{"$literal", a}}},
31+
{"b", bson.D{{"$literal", b}}},
32+
},
33+
}}},
34+
35+
// Now check to be sure that those specs match.
36+
{{"$match", bson.D{
37+
{"$expr", bson.D{
38+
{"$eq", mslices.Of("$a", "$b")},
39+
}},
40+
}}},
41+
}
42+
43+
if extra, hasExtra := tinker.Get(); hasExtra {
44+
pipeline = slices.Insert(
45+
pipeline,
46+
1,
47+
extra...,
48+
)
49+
}
50+
51+
cursor, err := client.Database("admin").Aggregate(ctx, pipeline)
52+
53+
if err == nil {
54+
defer cursor.Close(ctx)
55+
56+
if cursor.Next(ctx) {
57+
return true, nil
58+
}
59+
60+
err = cursor.Err()
61+
}
62+
63+
return false, errors.Wrapf(err, "failed to ask server if a (%v) matches b (%v)", a, b)
64+
}

internal/verifier/check.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const (
2020
GenerationComplete GenerationStatus = "complete"
2121
)
2222

23-
var failedStatus = mapset.NewSet(
23+
var failedStatuses = mapset.NewSet(
2424
verificationTaskFailed,
2525
verificationTaskMetadataMismatch,
2626
)
@@ -406,7 +406,7 @@ func FetchFailedAndIncompleteTasks(ctx context.Context, coll *mongo.Collection,
406406
return FailedTasks, IncompleteTasks, err
407407
}
408408
for _, t := range allTasks {
409-
if failedStatus.Contains(t.Status) {
409+
if failedStatuses.Contains(t.Status) {
410410
FailedTasks = append(FailedTasks, t)
411411
} else if t.Status != verificationTaskCompleted {
412412
IncompleteTasks = append(IncompleteTasks, t)

internal/verifier/integration_test_suite.go

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import (
55
"strings"
66
"time"
77

8+
"github.com/10gen/migration-verifier/internal/util"
89
mapset "github.com/deckarep/golang-set/v2"
910
"github.com/pkg/errors"
10-
"github.com/samber/lo"
1111
"github.com/stretchr/testify/suite"
1212
"go.mongodb.org/mongo-driver/bson"
1313
"go.mongodb.org/mongo-driver/mongo"
@@ -16,13 +16,8 @@ import (
1616
"go.mongodb.org/mongo-driver/mongo/writeconcern"
1717
)
1818

19-
type TestTopology string
20-
2119
const (
22-
metaDBName = "VERIFIER_TEST_META"
23-
topologyEnvVar = "MVTEST_TOPOLOGY"
24-
TopologyReplset TestTopology = "replset"
25-
TopologySharded TestTopology = "sharded"
20+
metaDBName = "VERIFIER_TEST_META"
2621
)
2722

2823
type IntegrationTestSuite struct {
@@ -139,22 +134,14 @@ func (suite *IntegrationTestSuite) TearDownTest() {
139134
}
140135
}
141136

142-
func (suite *IntegrationTestSuite) GetSrcTopology() TestTopology {
143-
hello := struct {
144-
Msg string
145-
}{}
146-
147-
resp := suite.srcMongoClient.Database("admin").RunCommand(
137+
func (suite *IntegrationTestSuite) GetSrcTopology() util.ClusterTopology {
138+
clusterInfo, err := util.GetClusterInfo(
148139
suite.Context(),
149-
bson.D{{"hello", 1}},
150-
)
151-
152-
suite.Require().NoError(
153-
resp.Decode(&hello),
154-
"should fetch & decode hello",
140+
suite.srcMongoClient,
155141
)
142+
suite.Require().NoError(err, "should fetch src cluster info")
156143

157-
return lo.Ternary(hello.Msg == "isdbgrid", TopologySharded, "")
144+
return clusterInfo.Topology
158145
}
159146

160147
func (suite *IntegrationTestSuite) BuildVerifier() *Verifier {

0 commit comments

Comments
 (0)