File: backoff_test.go

package info (click to toggle)
golang-github-hlandau-goutils 0.0~git20160722.0.0cdb66a-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch, stretch-backports
  • size: 156 kB
  • ctags: 107
  • sloc: makefile: 2
file content (28 lines) | stat: -rw-r--r-- 591 bytes parent folder | download | duplicates (4)
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
package net_test

import "testing"
import "github.com/hlandau/goutils/net"
import "time"

func TestBackoff(t *testing.T) {
	b := net.Backoff{}

	eq := func(d time.Duration, ms int) {
		a := int(d / time.Millisecond)
		if a != ms {
			t.Errorf("Backoff #%d:  %v should be %v", b.CurrentTry, a, ms)
		}
	}

	eq(b.NextDelay(), 5000)
	eq(b.NextDelay(), 6870)
	eq(b.NextDelay(), 9440)
	eq(b.NextDelay(), 12972)
	eq(b.NextDelay(), 17826)
	eq(b.NextDelay(), 24494)
	eq(b.NextDelay(), 33658)
	eq(b.NextDelay(), 46250)
	eq(b.NextDelay(), 63553)
	eq(b.NextDelay(), 87329)
	eq(b.NextDelay(), 120000)
}