Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Heads up: github.com/Rican7/retry >= 0.3.0 backwards-incompatible changes #190

Closed
gibmat opened this issue May 4, 2022 · 2 comments · Fixed by #191
Closed

Heads up: github.com/Rican7/retry >= 0.3.0 backwards-incompatible changes #190

gibmat opened this issue May 4, 2022 · 2 comments · Fixed by #191
Assignees

Comments

@gibmat
Copy link

gibmat commented May 4, 2022

Just a heads up that github.com/Rican7/retry >= 0.3.0 has backwards-incompatible changes that will cause test failures in internal/protocol/connector_test.go. Debian updated that library about a month ago, which has then exposed this issue when running tests for go-dqlite.

It would be great if this library could be updated to use the current version of github.com/Rican7/retry.

@gibmat
Copy link
Author

gibmat commented May 5, 2022

The following changes seem sufficient to keep all the tests happy:

diff --git a/internal/protocol/connector.go b/internal/protocol/connector.go
index e777d65..f89f556 100644
--- a/internal/protocol/connector.go
+++ b/internal/protocol/connector.go
@@ -301,11 +301,12 @@ func (c *Connector) connectAttemptOne(ctx context.Context, address string, versi
 // Return a retry strategy with exponential backoff, capped at the given amount
 // of time and possibly with a maximum number of retries.
 func makeRetryStrategies(factor, cap time.Duration, limit uint) []strategy.Strategy {
+       limit += 1 // Fix for change in behavior: https://github.com/Rican7/retry/pull/12
        backoff := backoff.BinaryExponential(factor)
 
        strategies := []strategy.Strategy{}
 
-       if limit > 0 {
+       if limit > 1 {
                strategies = append(strategies, strategy.Limit(limit))
        }
 
diff --git a/internal/protocol/connector_test.go b/internal/protocol/connector_test.go
index 54340aa..1704841 100644
--- a/internal/protocol/connector_test.go
+++ b/internal/protocol/connector_test.go
@@ -35,7 +35,7 @@ func TestConnector_Success(t *testing.T) {
        assert.NoError(t, client.Close())
 
        check([]string{
-               "DEBUG: attempt 0: server @test-0: connected",
+               "DEBUG: attempt 1: server @test-0: connected",
        })
 }
 
@@ -53,9 +53,9 @@ func TestConnector_LimitRetries(t *testing.T) {
        assert.Equal(t, protocol.ErrNoAvailableLeader, err)
 
        check([]string{
-               "WARN: attempt 0: server @test-123: dial: dial unix @test-123: connect: connection refused",
                "WARN: attempt 1: server @test-123: dial: dial unix @test-123: connect: connection refused",
                "WARN: attempt 2: server @test-123: dial: dial unix @test-123: connect: connection refused",
+               "WARN: attempt 3: server @test-123: dial: dial unix @test-123: connect: connection refused",
        })
 }
 
@@ -73,8 +73,8 @@ func TestConnector_DialTimeout(t *testing.T) {
        assert.Equal(t, protocol.ErrNoAvailableLeader, err)
 
        check([]string{
-               "WARN: attempt 0: server 8.8.8.8:9000: dial: dial tcp 8.8.8.8:9000: i/o timeout",
                "WARN: attempt 1: server 8.8.8.8:9000: dial: dial tcp 8.8.8.8:9000: i/o timeout",
+               "WARN: attempt 2: server 8.8.8.8:9000: dial: dial tcp 8.8.8.8:9000: i/o timeout",
        })
 }
 
@@ -107,7 +107,7 @@ func TestConnector_ContextCanceled(t *testing.T) {
        assert.Equal(t, protocol.ErrNoAvailableLeader, err)
 
        check([]string{
-               "WARN: attempt 0: server 1.2.3.4:666: dial: dial tcp 1.2.3.4:666: i/o timeout",
+               "WARN: attempt 1: server 1.2.3.4:666: dial: dial tcp 1.2.3.4:666: i/o timeout",
        })
 }
 

@stgraber
Copy link
Contributor

stgraber commented May 5, 2022

@MathieuBordere probably time for a gomod update and applying that fix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants