mirror of https://github.com/jpillora/backoff.git
Add test to prove the data race
This commit is contained in:
parent
3050d21c67
commit
f452bc980a
|
@ -2,6 +2,7 @@ package backoff
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"reflect"
|
"reflect"
|
||||||
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
@ -120,6 +121,26 @@ func TestCopy(t *testing.T) {
|
||||||
equals(t, b, b2)
|
equals(t, b, b2)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestConcurrent(t *testing.T) {
|
||||||
|
b := &Backoff{
|
||||||
|
Min: 100 * time.Millisecond,
|
||||||
|
Max: 10 * time.Second,
|
||||||
|
Factor: 2,
|
||||||
|
}
|
||||||
|
|
||||||
|
wg := &sync.WaitGroup{}
|
||||||
|
|
||||||
|
test := func() {
|
||||||
|
time.Sleep(b.Duration())
|
||||||
|
wg.Done()
|
||||||
|
}
|
||||||
|
|
||||||
|
wg.Add(2)
|
||||||
|
go test()
|
||||||
|
go test()
|
||||||
|
wg.Wait()
|
||||||
|
}
|
||||||
|
|
||||||
func between(t *testing.T, actual, low, high time.Duration) {
|
func between(t *testing.T, actual, low, high time.Duration) {
|
||||||
if actual < low {
|
if actual < low {
|
||||||
t.Fatalf("Got %s, Expecting >= %s", actual, low)
|
t.Fatalf("Got %s, Expecting >= %s", actual, low)
|
||||||
|
|
Loading…
Reference in New Issue