Remove total retry timeout option (#13)
Changes the retrying call to use the parent total timeout.
diff --git a/call_option.go b/call_option.go
index d7dfa2b..d605132 100644
--- a/call_option.go
+++ b/call_option.go
@@ -35,7 +35,6 @@
type BackoffSettings struct {
DelayTimeoutSettings MultipliableDuration
RPCTimeoutSettings MultipliableDuration
- TotalTimeout time.Duration
}
type MultipliableDuration struct {
@@ -117,16 +116,3 @@
func WithRPCTimeoutSettings(initial time.Duration, max time.Duration, multiplier float64) CallOption {
return withRPCTimeoutSettings(MultipliableDuration{initial, max, multiplier})
}
-
-type withTotalRetryTimeout time.Duration
-
-func (w withTotalRetryTimeout) Resolve(s *CallSettings) {
- s.RetrySettings.BackoffSettings.TotalTimeout = time.Duration(w)
-}
-
-// WithTotalRetryTimeout sets the total time, in milliseconds, starting from
-// when the initial request is sent, after which an error will be returned
-// regardless of the retrying attempts made meanwhile.
-func WithTotalRetryTimeout(totalRetryTimeout time.Duration) CallOption {
- return withTotalRetryTimeout(totalRetryTimeout)
-}
diff --git a/call_option_test.go b/call_option_test.go
index 190221f..ce07d9f 100644
--- a/call_option_test.go
+++ b/call_option_test.go
@@ -16,7 +16,6 @@
BackoffSettings{
MultipliableDuration{time.Second * 2, time.Second * 4, 3.0},
MultipliableDuration{time.Second * 5, time.Second * 7, 6.0},
- time.Second * 8,
},
},
}
@@ -27,7 +26,6 @@
WithRetryCodes([]codes.Code{codes.Unavailable, codes.DeadlineExceeded}),
WithDelayTimeoutSettings(time.Second*2, time.Second*4, 3.0),
WithRPCTimeoutSettings(time.Second*5, time.Second*7, 6.0),
- WithTotalRetryTimeout(time.Second * 8),
}
callOptions(opts).Resolve(settings)
diff --git a/invoke.go b/invoke.go
index 7a368f0..4505635 100644
--- a/invoke.go
+++ b/invoke.go
@@ -19,10 +19,11 @@
// invokeWithRetry calls stub using an exponential backoff retry mechanism
// based on the values provided in retrySettings.
-func invokeWithRetry(ctx context.Context, stub APICall, retrySettings RetrySettings) error {
- backoffSettings := retrySettings.BackoffSettings
+func invokeWithRetry(ctx context.Context, stub APICall, callSettings CallSettings) error {
+ retrySettings := callSettings.RetrySettings
+ backoffSettings := callSettings.RetrySettings.BackoffSettings
// Forces ctx to expire after a deadline.
- childCtx, _ := context.WithTimeout(ctx, backoffSettings.TotalTimeout)
+ childCtx, _ := context.WithTimeout(ctx, callSettings.Timeout)
delay := backoffSettings.DelayTimeoutSettings.Initial
timeout := backoffSettings.RPCTimeoutSettings.Initial
for {
@@ -60,7 +61,7 @@
settings := &CallSettings{}
callOptions(opts).Resolve(settings)
if len(settings.RetrySettings.RetryCodes) > 0 {
- return invokeWithRetry(ctx, stub, settings.RetrySettings)
+ return invokeWithRetry(ctx, stub, *settings)
}
return invokeWithTimeout(ctx, stub, settings.Timeout)
}
diff --git a/invoke_test.go b/invoke_test.go
index de05681..37f7b0a 100644
--- a/invoke_test.go
+++ b/invoke_test.go
@@ -15,7 +15,7 @@
// initial, max, multiplier
WithDelayTimeoutSettings(100*time.Millisecond, 300*time.Millisecond, 1.5),
WithRPCTimeoutSettings(50*time.Millisecond, 500*time.Millisecond, 3.0),
- WithTotalRetryTimeout(1000 * time.Millisecond),
+ WithTimeout(1000*time.Millisecond),
}
)
@@ -25,7 +25,7 @@
Invoke(ctx, func(childCtx context.Context) error {
_, ok = childCtx.Deadline()
return nil
- }, WithTimeout(10000*time.Millisecond))
+ }, WithTimeout(1000*time.Millisecond))
if !ok {
t.Errorf("expected call to have an assigned timeout")
}
@@ -37,7 +37,7 @@
err := Invoke(ctx, func(childCtx context.Context) error {
resp = 42
return nil
- }, WithTimeout(10000*time.Millisecond))
+ }, WithTimeout(1000*time.Millisecond))
if resp != 42 || err != nil {
t.Errorf("expected call to return nil and set resp to 42")
}