Skip to content

Commit 7ef64fc

Browse files
committed
retryer trim & test tweak
1 parent 4c54c68 commit 7ef64fc

File tree

2 files changed

+24
-33
lines changed

2 files changed

+24
-33
lines changed

internal/retry/retry.go

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -42,31 +42,6 @@ func (r *Retryer) RunForUUIDAndTransientErrors(
4242
return r.runRetryLoop(ctx, logger, expectedCollName, f, true, true)
4343
}
4444

45-
// RunForUUIDErrorOnly retries f() for the CollectionUUIDMismatch error only. This should primarily
46-
// be used to wrap a transaction callback containing an operation that specifies the `collectionUUID`
47-
// parameter for a collection that may have been:
48-
//
49-
// - Dropped and requires no further action from f().
50-
// - Renamed and requires a retry for f() with an updated collection name.
51-
//
52-
// We retry only CollectionUUIDMismatch errors for transactions since transactions are already sufficiently
53-
// retried for transient errors by the driver.
54-
//
55-
// The collection's expected name should be provided as the expectedCollName parameter and shouldn't be blank.
56-
//
57-
// f() is provided with a collection name string, which is the one that should be used in the body
58-
// of f() where a collection name is needed. The initial value of this string is expectedCollName.
59-
//
60-
// RunForUUIDErrorOnly returns the collection's current name in all cases.
61-
func (r *Retryer) RunForUUIDErrorOnly(
62-
ctx context.Context, logger *logger.Logger, expectedCollName string, f func(*Info, string) error,
63-
) (string, error) {
64-
// Since we're not actually sleeping when checking for UUID/name mismatch
65-
// errors, we don't need to provide a real context to handle
66-
// cancellations.
67-
return r.runRetryLoop(ctx, logger, expectedCollName, f, false, true)
68-
}
69-
7045
// RunForTransientErrorsOnly retries f() for transient errors only, and
7146
// does not check for UUID mismatch error.
7247
//

internal/retry/retryer_test.go

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import (
1212
)
1313

1414
func (suite *UnitTestSuite) TestRetryer() {
15+
suite.T().Parallel()
16+
1517
retryer := New(DefaultDurationLimit)
1618
logger := suite.Logger()
1719

@@ -26,7 +28,7 @@ func (suite *UnitTestSuite) TestRetryer() {
2628
suite.NoError(err)
2729
suite.Equal(0, attemptNumber)
2830

29-
_, err = retryer.RunForUUIDErrorOnly(suite.Context(), logger, "foo", f)
31+
_, err = retryer.RunForUUIDAndTransientErrors(suite.Context(), logger, "foo", f)
3032
suite.NoError(err)
3133
suite.Equal(0, attemptNumber)
3234

@@ -92,7 +94,7 @@ func (suite *UnitTestSuite) TestRetryer() {
9294
}
9395
return nil
9496
}
95-
_, err := retryer.RunForUUIDErrorOnly(suite.Context(), logger, "bar", f)
97+
_, err := retryer.RunForUUIDAndTransientErrors(suite.Context(), logger, "bar", f)
9698
suite.NoError(err)
9799
suite.Equal(attemptLimit/2, attemptNumber)
98100
})
@@ -109,7 +111,7 @@ func (suite *UnitTestSuite) TestRetryer() {
109111
Raw: bson.Raw(raw),
110112
}
111113
}
112-
_, err := retryer.RunForUUIDErrorOnly(suite.Context(), logger, "bar", f)
114+
_, err := retryer.RunForUUIDAndTransientErrors(suite.Context(), logger, "bar", f)
113115
suite.NoError(err)
114116
// We only did one retry because the actual collection name matched the
115117
// previous attempt.
@@ -118,24 +120,28 @@ func (suite *UnitTestSuite) TestRetryer() {
118120
}
119121

120122
func (suite *UnitTestSuite) TestRetryerDurationLimitIsZero() {
123+
suite.T().Parallel()
124+
121125
retryer := New(0)
122126

123127
attemptNumber := -1
124128
cmdErr := mongo.CommandError{
125-
Labels: []string{"NetworkError"},
126-
Name: "NetworkError",
129+
Labels: []string{"SomethingWeird"},
130+
Name: "SomethingWeird",
127131
}
128-
f := func(ri *Info, _ string) error {
132+
f := func(ri *Info) error {
129133
attemptNumber = ri.attemptNumber
130134
return cmdErr
131135
}
132136

133-
_, err := retryer.RunForUUIDErrorOnly(suite.Context(), suite.Logger(), "bar", f)
137+
err := retryer.RunForTransientErrorsOnly(suite.Context(), suite.Logger(), f)
134138
suite.Equal(cmdErr, err)
135139
suite.Equal(0, attemptNumber)
136140
}
137141

138142
func (suite *UnitTestSuite) TestRetryerDurationReset() {
143+
suite.T().Parallel()
144+
139145
retryer := New(DefaultDurationLimit)
140146
logger := suite.Logger()
141147

@@ -192,6 +198,8 @@ func (suite *UnitTestSuite) TestRetryerDurationReset() {
192198
}
193199

194200
func (suite *UnitTestSuite) TestCancelViaContext() {
201+
suite.T().Parallel()
202+
195203
retryer := New(DefaultDurationLimit)
196204
logger := suite.Logger()
197205

@@ -222,6 +230,8 @@ func (suite *UnitTestSuite) TestCancelViaContext() {
222230
}
223231

224232
func (suite *UnitTestSuite) TestRetryerAdditionalErrorCodes() {
233+
suite.T().Parallel()
234+
225235
logger := suite.Logger()
226236

227237
customError := mongo.CommandError{
@@ -271,6 +281,8 @@ func (suite *UnitTestSuite) TestRetryerAdditionalErrorCodes() {
271281
}
272282

273283
func (suite *UnitTestSuite) TestRetryerWithEmptyCollectionName() {
284+
suite.T().Parallel()
285+
274286
retryer := New(DefaultDurationLimit)
275287
emptyCollNameError := errors.New("Empty collection name")
276288
f := func(_ *Info, collName string) error {
@@ -280,13 +292,15 @@ func (suite *UnitTestSuite) TestRetryerWithEmptyCollectionName() {
280292
return nil
281293
}
282294

283-
name, err := retryer.RunForUUIDErrorOnly(suite.Context(), suite.Logger(), "", f)
295+
name, err := retryer.RunForUUIDAndTransientErrors(suite.Context(), suite.Logger(), "", f)
284296
suite.NoError(err)
285297
suite.Equal("", name)
286298
}
287299

288300
// Test fix for REP-4197
289301
func (suite *UnitTestSuite) TestV50RetryerWithUUIDNotSupportedError() {
302+
suite.T().Parallel()
303+
290304
retryer := New(0)
291305

292306
attemptNumber := 0
@@ -312,6 +326,8 @@ func (suite *UnitTestSuite) TestV50RetryerWithUUIDNotSupportedError() {
312326
}
313327

314328
func (suite *UnitTestSuite) TestPreV50RetryerWithUUIDNotSupportedError() {
329+
suite.T().Parallel()
330+
315331
retryer := New(0)
316332

317333
attemptNumber := 0

0 commit comments

Comments
 (0)