Skip to content

Commit 42c7401

Browse files
committed
add more tests and prove it
1 parent f5daa4a commit 42c7401

File tree

5 files changed

+46
-0
lines changed

5 files changed

+46
-0
lines changed

.drone.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
workspace:
2+
base: /go
3+
path: src/github.com/codyoss/retry
4+
5+
pipeline:
6+
test:
7+
image: golang:1.11-stretch
8+
secrets: [ CODECOV_TOKEN ]
9+
commands:
10+
- go test -race -coverprofile=coverage.txt -covermode=atomic
11+
- curl -s https://codecov.io/bash > .codecov && chmod +x .codecov && ./.codecov

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
# Test binary, build with `go test -c`
1313
*.test
14+
coverage.txt
15+
.codecov
1416

1517
# Output of the go coverage tool, specifically when used with LiteIDE
1618
*.out

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
retry is a package that enables retrying code.
44

55
[![GoDoc](https://godoc.org/github.com/codyoss/retry?status.svg)](https://godoc.org/github.com/codyoss/retry)
6+
[![Build Status](https://cloud.drone.io/api/badges/codyoss/retry/status.svg)](https://cloud.drone.io/codyoss/retry)
7+
[![codecov](https://codecov.io/gh/codyoss/retry/branch/master/graph/badge.svg)](https://codecov.io/gh/codyoss/retry)
68
[![Go Report Card](https://goreportcard.com/badge/github.com/codyoss/retry)](https://goreportcard.com/report/github.com/codyoss/retry)
79

810
It has:

retry_internal_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,32 @@ func TestFreezeBackoffAfterFirstUse(t *testing.T) {
4242
t.Error("public fields should change, private should have been frozen")
4343
}
4444
}
45+
46+
func TestFreezeBackoffWithBadInputs(t *testing.T) {
47+
attempts := -1
48+
initialDelay := -1 * time.Millisecond
49+
maxDelay := 0 * time.Millisecond
50+
factor := 0.0
51+
jitter := -1.0
52+
53+
b := &Backoff{
54+
Attempts: attempts,
55+
InitialDelay: initialDelay,
56+
MaxDelay: maxDelay,
57+
Factor: factor,
58+
Jitter: jitter,
59+
}
60+
61+
It(b, func() error {
62+
return nil
63+
})
64+
65+
if b.attempts != 1 ||
66+
b.initialDelay != 0 ||
67+
b.maxDelay != Forever ||
68+
b.factor != 1 ||
69+
b.jitter != 0 ||
70+
b.skipJitter != true {
71+
t.Error("public fields should change, private should have been frozen")
72+
}
73+
}

retry_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ func TestIt(t *testing.T) {
2929
wantErr error
3030
}{
3131
{"works", &retry.Backoff{Attempts: 3, Factor: 1.0, InitialDelay: 1 * time.Millisecond, MaxDelay: retry.Forever, Jitter: .1}, "It Worked", nil},
32+
{"works, uses maxDelay", &retry.Backoff{Attempts: 3, Factor: 2.0, InitialDelay: 1 * time.Millisecond, MaxDelay: 2 * time.Millisecond, Jitter: .1}, "It Worked", nil},
3233
{"not work, no retries", &retry.Backoff{Attempts: 1, Factor: 1.0, InitialDelay: 500 * time.Millisecond, MaxDelay: retry.Forever, Jitter: .1}, "", retry.Me},
3334
{"not work, one retry", &retry.Backoff{Attempts: 2, Factor: 1.0, InitialDelay: 1 * time.Millisecond, MaxDelay: retry.Forever, Jitter: .1}, "", retry.Me},
3435
}
@@ -65,6 +66,7 @@ func TestItContext(t *testing.T) {
6566
wantErr error
6667
}{
6768
{"works", &retry.Backoff{Attempts: 3, Factor: 1.0, InitialDelay: 1 * time.Millisecond, MaxDelay: retry.Forever, Jitter: .1}, 10 * time.Millisecond, "It Worked", nil},
69+
{"works, uses maxDelay", &retry.Backoff{Attempts: 3, Factor: 2.0, InitialDelay: 1 * time.Millisecond, MaxDelay: 2 * time.Millisecond, Jitter: .1}, 10 * time.Millisecond, "It Worked", nil},
6870
{"not work, no retries", &retry.Backoff{Attempts: 1, Factor: 1.0, InitialDelay: 500 * time.Millisecond, MaxDelay: retry.Forever, Jitter: .1}, 10 * time.Millisecond, "", retry.Me},
6971
{"not work, one retry", &retry.Backoff{Attempts: 2, Factor: 1.0, InitialDelay: 1 * time.Millisecond, MaxDelay: retry.Forever, Jitter: .1}, 10 * time.Millisecond, "", retry.Me},
7072
{"not work, deadline exceeded", retry.ExponentialBackoff, 10 * time.Millisecond, "", context.DeadlineExceeded},

0 commit comments

Comments
 (0)