Skip to content

Commit e1c5106

Browse files
committed
more replacements
1 parent a681dbf commit e1c5106

File tree

11 files changed

+63
-47
lines changed

11 files changed

+63
-47
lines changed

internal/retry/retry.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,12 @@ func (r *Retryer) RunForUUIDAndTransientErrors(
5959
//
6060
// RunForUUIDErrorOnly returns the collection's current name in all cases.
6161
func (r *Retryer) RunForUUIDErrorOnly(
62-
logger *logger.Logger, expectedCollName string, f func(*Info, string) error,
62+
ctx context.Context, logger *logger.Logger, expectedCollName string, f func(*Info, string) error,
6363
) (string, error) {
6464
// Since we're not actually sleeping when checking for UUID/name mismatch
6565
// errors, we don't need to provide a real context to handle
6666
// cancellations.
67-
return r.runRetryLoop(context.Background(), logger, expectedCollName, f, false, true)
67+
return r.runRetryLoop(ctx, logger, expectedCollName, f, false, true)
6868
}
6969

7070
// RunForTransientErrorsOnly retries f() for transient errors only, and

internal/retry/retryer_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func (suite *UnitTestSuite) TestRetryer() {
2626
suite.NoError(err)
2727
suite.Equal(0, attemptNumber)
2828

29-
_, err = retryer.RunForUUIDErrorOnly(logger, "foo", f)
29+
_, err = retryer.RunForUUIDErrorOnly(suite.Context(), logger, "foo", f)
3030
suite.NoError(err)
3131
suite.Equal(0, attemptNumber)
3232

@@ -92,7 +92,7 @@ func (suite *UnitTestSuite) TestRetryer() {
9292
}
9393
return nil
9494
}
95-
_, err := retryer.RunForUUIDErrorOnly(logger, "bar", f)
95+
_, err := retryer.RunForUUIDErrorOnly(suite.Context(), logger, "bar", f)
9696
suite.NoError(err)
9797
suite.Equal(attemptLimit/2, attemptNumber)
9898
})
@@ -109,7 +109,7 @@ func (suite *UnitTestSuite) TestRetryer() {
109109
Raw: bson.Raw(raw),
110110
}
111111
}
112-
_, err := retryer.RunForUUIDErrorOnly(logger, "bar", f)
112+
_, err := retryer.RunForUUIDErrorOnly(suite.Context(), logger, "bar", f)
113113
suite.NoError(err)
114114
// We only did one retry because the actual collection name matched the
115115
// previous attempt.
@@ -130,7 +130,7 @@ func (suite *UnitTestSuite) TestRetryerDurationLimitIsZero() {
130130
return cmdErr
131131
}
132132

133-
_, err := retryer.RunForUUIDErrorOnly(suite.Logger(), "bar", f)
133+
_, err := retryer.RunForUUIDErrorOnly(suite.Context(), suite.Logger(), "bar", f)
134134
suite.Equal(cmdErr, err)
135135
suite.Equal(0, attemptNumber)
136136
}
@@ -280,7 +280,7 @@ func (suite *UnitTestSuite) TestRetryerWithEmptyCollectionName() {
280280
return nil
281281
}
282282

283-
name, err := retryer.RunForUUIDErrorOnly(suite.Logger(), "", f)
283+
name, err := retryer.RunForUUIDErrorOnly(suite.Context(), suite.Logger(), "", f)
284284
suite.NoError(err)
285285
suite.Equal("", name)
286286
}

internal/verifier/change_stream_test.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func (suite *IntegrationTestSuite) TestChangeStreamResumability() {
5555

5656
func() {
5757
verifier1 := suite.BuildVerifier()
58-
ctx, cancel := context.WithCancel(context.Background())
58+
ctx, cancel := context.WithCancel(suite.Context())
5959
defer cancel()
6060
err := verifier1.StartChangeStream(ctx)
6161
suite.Require().NoError(err)
@@ -147,8 +147,7 @@ func (suite *IntegrationTestSuite) fetchVerifierRechecks(ctx context.Context, ve
147147

148148
func (suite *IntegrationTestSuite) TestStartAtTimeNoChanges() {
149149
verifier := suite.BuildVerifier()
150-
ctx, cancel := context.WithCancel(context.Background())
151-
defer cancel()
150+
ctx := suite.Context()
152151
sess, err := suite.srcMongoClient.StartSession()
153152
suite.Require().NoError(err)
154153
sctx := mongo.NewSessionContext(ctx, sess)
@@ -167,8 +166,7 @@ func (suite *IntegrationTestSuite) TestStartAtTimeNoChanges() {
167166

168167
func (suite *IntegrationTestSuite) TestStartAtTimeWithChanges() {
169168
verifier := suite.BuildVerifier()
170-
ctx, cancel := context.WithCancel(context.Background())
171-
defer cancel()
169+
ctx := suite.Context()
172170
sess, err := suite.srcMongoClient.StartSession()
173171
suite.Require().NoError(err)
174172
sctx := mongo.NewSessionContext(ctx, sess)
@@ -220,8 +218,7 @@ func (suite *IntegrationTestSuite) TestStartAtTimeWithChanges() {
220218

221219
func (suite *IntegrationTestSuite) TestNoStartAtTime() {
222220
verifier := suite.BuildVerifier()
223-
ctx, cancel := context.WithCancel(context.Background())
224-
defer cancel()
221+
ctx := suite.Context()
225222
sess, err := suite.srcMongoClient.StartSession()
226223
suite.Require().NoError(err)
227224
sctx := mongo.NewSessionContext(ctx, sess)

internal/verifier/check.go

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ func (verifier *Verifier) CheckWorker(ctxIn context.Context) error {
9393
for i := 0; i < verifier.numWorkers; i++ {
9494
eg.Go(func() error {
9595
return errors.Wrapf(
96-
verifier.Work(ctx, i),
96+
verifier.work(ctx, i),
9797
"worker %d failed",
9898
i,
9999
)
@@ -103,7 +103,7 @@ func (verifier *Verifier) CheckWorker(ctxIn context.Context) error {
103103

104104
waitForTaskCreation := 0
105105

106-
succeededErr := errors.Errorf("generation %d finished", generation)
106+
succeeded := false
107107

108108
eg.Go(func() error {
109109
for {
@@ -130,15 +130,16 @@ func (verifier *Verifier) CheckWorker(ctxIn context.Context) error {
130130
continue
131131
} else {
132132
verifier.PrintVerificationSummary(ctx, GenerationComplete)
133-
canceler(succeededErr)
133+
succeeded = true
134+
canceler(errors.New("ok"))
134135
return nil
135136
}
136137
}
137138
})
138139

139140
err := eg.Wait()
140141

141-
if errors.Is(err, succeededErr) {
142+
if succeeded {
142143
err = nil
143144
}
144145

@@ -225,7 +226,7 @@ func (verifier *Verifier) CheckDriver(ctx context.Context, filter map[string]any
225226
verifier.logger.Debug().Msgf("Initial verification phase: %+v", verificationStatus)
226227
}
227228

228-
err = verifier.CreateInitialTasks()
229+
err = verifier.CreateInitialTasks(ctx)
229230
if err != nil {
230231
return err
231232
}
@@ -335,7 +336,7 @@ func (verifier *Verifier) setupAllNamespaceList(ctx context.Context) error {
335336
return nil
336337
}
337338

338-
func (verifier *Verifier) CreateInitialTasks() error {
339+
func (verifier *Verifier) CreateInitialTasks(ctx context.Context) error {
339340
// If we don't know the src namespaces, we're definitely not the primary task.
340341
if !verifier.verifyAll {
341342
if len(verifier.srcNamespaces) == 0 {
@@ -359,13 +360,13 @@ func (verifier *Verifier) CreateInitialTasks() error {
359360
return nil
360361
}
361362
if verifier.verifyAll {
362-
err := verifier.setupAllNamespaceList(context.Background())
363+
err := verifier.setupAllNamespaceList(ctx)
363364
if err != nil {
364365
return err
365366
}
366367
}
367368
for _, src := range verifier.srcNamespaces {
368-
_, err := verifier.InsertCollectionVerificationTask(src)
369+
_, err := verifier.InsertCollectionVerificationTask(ctx, src)
369370
if err != nil {
370371
verifier.logger.Error().Msgf("Failed to insert collection verification task: %s", err)
371372
return err
@@ -407,8 +408,8 @@ func FetchFailedAndIncompleteTasks(ctx context.Context, coll *mongo.Collection,
407408
return FailedTasks, IncompleteTasks, nil
408409
}
409410

410-
// Work is the logic for an individual worker thread.
411-
func (verifier *Verifier) Work(ctx context.Context, workerNum int) error {
411+
// work is the logic for an individual worker thread.
412+
func (verifier *Verifier) work(ctx context.Context, workerNum int) error {
412413
verifier.logger.Debug().
413414
Int("workerNum", workerNum).
414415
Msg("Worker started.")
@@ -432,9 +433,12 @@ func (verifier *Verifier) Work(ctx context.Context, workerNum int) error {
432433
}
433434

434435
continue
435-
} else if errors.Is(err, context.Canceled) {
436-
return nil
436+
/*
437+
} else if errors.Is(err, context.Canceled) {
438+
return nil
439+
*/
437440
} else if err != nil {
441+
438442
return errors.Wrap(
439443
err,
440444
"failed to seek next task",

internal/verifier/clustertime_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
package verifier
22

33
import (
4-
"context"
5-
64
"go.mongodb.org/mongo-driver/bson"
75
"go.mongodb.org/mongo-driver/bson/primitive"
86
"go.mongodb.org/mongo-driver/mongo"
97
)
108

119
func (suite *IntegrationTestSuite) TestGetNewClusterTime() {
12-
ctx := context.Background()
10+
ctx := suite.Context()
1311
logger, _ := getLoggerAndWriter("stdout")
1412

1513
sess, err := suite.srcMongoClient.StartSession()

internal/verifier/migration_verifier.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1142,7 +1142,7 @@ func (verifier *Verifier) verifyMetadataAndPartitionCollection(
11421142
}
11431143

11441144
insertFailedCollection := func() error {
1145-
_, err := verifier.InsertFailedCollectionVerificationTask(srcNs)
1145+
_, err := verifier.InsertFailedCollectionVerificationTask(ctx, srcNs)
11461146
return errors.Wrapf(
11471147
err,
11481148
"failed to persist metadata mismatch for collection %#q",
@@ -1236,7 +1236,7 @@ func (verifier *Verifier) verifyMetadataAndPartitionCollection(
12361236
task.SourceByteCount = bytesCount
12371237

12381238
for _, partition := range partitions {
1239-
_, err := verifier.InsertPartitionVerificationTask(partition, shardKeys, dstNs)
1239+
_, err := verifier.InsertPartitionVerificationTask(ctx, partition, shardKeys, dstNs)
12401240
if err != nil {
12411241
return errors.Wrapf(
12421242
err,

internal/verifier/migration_verifier_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,10 +216,10 @@ func (suite *IntegrationTestSuite) TestGetNamespaceStatistics_Gen0() {
216216
// Now add 2 namespaces. Add them “out of order” to test
217217
// that we sort the returned array by Namespace.
218218

219-
task2, err := verifier.InsertCollectionVerificationTask("mydb.coll2")
219+
task2, err := verifier.InsertCollectionVerificationTask(ctx, "mydb.coll2")
220220
suite.Require().NoError(err)
221221

222-
task1, err := verifier.InsertCollectionVerificationTask("mydb.coll1")
222+
task1, err := verifier.InsertCollectionVerificationTask(ctx, "mydb.coll1")
223223
suite.Require().NoError(err)
224224

225225
stats, err = verifier.GetNamespaceStatistics(ctx)
@@ -276,6 +276,7 @@ func (suite *IntegrationTestSuite) TestGetNamespaceStatistics_Gen0() {
276276
task2parts := [2]*VerificationTask{}
277277
for i := range task1parts {
278278
task1part, err := verifier.InsertPartitionVerificationTask(
279+
ctx,
279280
&partitions.Partition{
280281
Ns: &partitions.Namespace{DB: "mydb", Coll: "coll1"},
281282
},
@@ -287,6 +288,7 @@ func (suite *IntegrationTestSuite) TestGetNamespaceStatistics_Gen0() {
287288
task1parts[i] = task1part
288289

289290
task2part, err := verifier.InsertPartitionVerificationTask(
291+
ctx,
290292
&partitions.Partition{
291293
Ns: &partitions.Namespace{DB: "mydb", Coll: "coll2"},
292294
},

internal/verifier/recheck.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ func (verifier *Verifier) GenerateRecheckTasks(ctx context.Context) error {
261261
namespace := prevDBName + "." + prevCollName
262262

263263
err := verifier.InsertDocumentRecheckTask(
264+
ctx,
264265
idAccum,
265266
types.ByteCount(dataSizeAccum),
266267
namespace,

internal/verifier/recheck_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func (suite *IntegrationTestSuite) fetchRecheckDocs(ctx context.Context, verifie
8989

9090
func (suite *IntegrationTestSuite) TestLargeIDInsertions() {
9191
verifier := suite.BuildVerifier()
92-
ctx := context.Background()
92+
ctx := suite.Context()
9393

9494
overlyLarge := 7 * 1024 * 1024 // Three of these exceed our 16MB limit, but two do not
9595
id1 := strings.Repeat("a", overlyLarge)
@@ -151,7 +151,7 @@ func (suite *IntegrationTestSuite) TestLargeIDInsertions() {
151151
func (suite *IntegrationTestSuite) TestLargeDataInsertions() {
152152
verifier := suite.BuildVerifier()
153153
verifier.partitionSizeInBytes = 1024 * 1024
154-
ctx := context.Background()
154+
ctx := suite.Context()
155155

156156
id1 := "a"
157157
id2 := "b"
@@ -212,7 +212,7 @@ func (suite *IntegrationTestSuite) TestLargeDataInsertions() {
212212

213213
func (suite *IntegrationTestSuite) TestMultipleNamespaces() {
214214
verifier := suite.BuildVerifier()
215-
ctx := context.Background()
215+
ctx := suite.Context()
216216

217217
id1 := "a"
218218
id2 := "b"
@@ -263,7 +263,7 @@ func (suite *IntegrationTestSuite) TestMultipleNamespaces() {
263263

264264
func (suite *IntegrationTestSuite) TestGenerationalClear() {
265265
verifier := suite.BuildVerifier()
266-
ctx := context.Background()
266+
ctx := suite.Context()
267267

268268
id1 := "a"
269269
id2 := "b"

internal/verifier/reset_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@ import (
1111
)
1212

1313
func (suite *IntegrationTestSuite) TestResetPrimaryTask() {
14+
ctx := suite.Context()
15+
1416
verifier := suite.BuildVerifier()
1517

1618
created, err := verifier.CheckIsPrimary()
1719
suite.Require().NoError(err)
1820
suite.Require().True(created)
1921

20-
_, err = verifier.InsertCollectionVerificationTask("foo.bar")
22+
_, err = verifier.InsertCollectionVerificationTask(ctx, "foo.bar")
2123
suite.Require().NoError(err)
2224

23-
ctx := context.Background()
24-
2525
err = verifier.doInMetaTransaction(
2626
ctx,
2727
func(_ context.Context, ctx mongo.SessionContext) error {
@@ -55,7 +55,7 @@ func (suite *IntegrationTestSuite) TestResetNonPrimaryTasks() {
5555
ns2 := "qux.quux"
5656

5757
// Create a collection-verification task, and set it to processing.
58-
collTask, err := verifier.InsertCollectionVerificationTask(ns1)
58+
collTask, err := verifier.InsertCollectionVerificationTask(ctx, ns1)
5959
suite.Require().NoError(err)
6060

6161
collTask.Status = verificationTaskProcessing
@@ -79,6 +79,7 @@ func (suite *IntegrationTestSuite) TestResetNonPrimaryTasks() {
7979
{verificationTaskCompleted, ns2},
8080
} {
8181
task, err := verifier.InsertPartitionVerificationTask(
82+
ctx,
8283
&partitions.Partition{
8384
Ns: &partitions.Namespace{
8485
DB: strings.Split(taskParts.Namespace, ".")[0],

0 commit comments

Comments
 (0)