File: retry_test.go

package info (click to toggle)
golang-github-cenkalti-backoff 1.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch, stretch-backports
  • size: 100 kB
  • ctags: 61
  • sloc: makefile: 2
file content (34 lines) | stat: -rw-r--r-- 554 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package backoff

import (
	"errors"
	"log"
	"testing"
)

func TestRetry(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")
	}

	err := Retry(f, NewExponentialBackOff())
	if err != nil {
		t.Errorf("unexpected error: %s", err.Error())
	}
	if i != successOn {
		t.Errorf("invalid number of retries: %d", i)
	}
}