1
0
Fork 0
mirror of https://github.com/Luzifer/elastic_cron.git synced 2024-11-14 00:12:46 +00:00
elastic_cron/vendor/github.com/cenkalti/backoff/ticker_test.go
Knut Ahlers da8edd41c2
Move to dep instead of godeps
Signed-off-by: Knut Ahlers <knut@ahlers.me>
2017-09-13 13:13:34 +02:00

45 lines
680 B
Go

package backoff
import (
"errors"
"log"
"testing"
)
func TestTicker(t *testing.T) {
const successOn = 3
var i = 0
// This function is successfull on "successOn" calls.
f := func() error {
i++
log.Printf("function is called %d. time\n", i)
if i == successOn {
log.Println("OK")
return nil
}
log.Println("error")
return errors.New("error")
}
b := NewExponentialBackOff()
ticker := NewTicker(b)
var err error
for _ = range ticker.C {
if err = f(); err != nil {
t.Log(err)
continue
}
break
}
if err != nil {
t.Errorf("unexpected error: %s", err.Error())
}
if i != successOn {
t.Errorf("invalid number of retries: %d", i)
}
}