Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(402)

Unified Diff: client/internal/retry/retry_test.go

Issue 1135173003: Create packages client/internal/ retry and lhttp. (Closed) Base URL: git@github.com:luci/luci-go@3_UI
Patch Set: Create lhttp.Retriable interface Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « client/internal/retry/retry.go ('k') | client/isolatedclient/isolatedclient.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: client/internal/retry/retry_test.go
diff --git a/client/internal/retry/retry_test.go b/client/internal/retry/retry_test.go
new file mode 100644
index 0000000000000000000000000000000000000000..33c45dacfefbe335eaa7e4e96c6377db90d6cec7
--- /dev/null
+++ b/client/internal/retry/retry_test.go
@@ -0,0 +1,70 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package retry
+
+import (
+ "errors"
+ "testing"
+ "time"
+
+ "github.com/maruel/ut"
+)
+
+func TestDoOnce(t *testing.T) {
+ c := &Config{1, 0, 0, 0}
+ r := &retriable{}
+ ut.AssertEqual(t, nil, c.Do(r))
+ ut.AssertEqual(t, 1, r.closed)
+ ut.AssertEqual(t, 1, r.tries)
+}
+
+func TestDoRetryExceeded(t *testing.T) {
+ c := &Config{1, 0, 0, 0}
+ r := &retriable{errs: []error{errRetry}}
+ ut.AssertEqual(t, errRetry, c.Do(r))
+ ut.AssertEqual(t, 1, r.closed)
+ ut.AssertEqual(t, 1, r.tries)
+}
+
+func TestDoRetry(t *testing.T) {
+ c := &Config{2, 0, time.Millisecond, 0}
+ r := &retriable{errs: []error{errRetry}}
+ ut.AssertEqual(t, nil, c.Do(r))
+ ut.AssertEqual(t, 1, r.closed)
+ ut.AssertEqual(t, 2, r.tries)
+}
+
+func TestError(t *testing.T) {
+ ut.AssertEqual(t, "please try again", errRetry.Error())
+}
+
+// Private details.
+
+var errYo = errors.New("yo")
+var errRetry = Error{errors.New("please try again")}
+
+type retriable struct {
+ closed int
+ tries int
+ errs []error
+}
+
+func (r *retriable) Close() error {
+ r.closed++
+ if r.closed > 1 {
+ return errYo
+ }
+ return nil
+}
+
+func (r *retriable) Do() error {
+ r.tries++
+ if len(r.errs) != 0 {
+ err := r.errs[0]
+ r.errs = r.errs[1:]
+ return err
+ }
+ return nil
+}
« no previous file with comments | « client/internal/retry/retry.go ('k') | client/isolatedclient/isolatedclient.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698