forked from gree/futurama
-
Notifications
You must be signed in to change notification settings - Fork 0
/
helper_test.go
52 lines (45 loc) · 910 Bytes
/
helper_test.go
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package futurama
import (
"github.com/golang/glog"
"github.com/stretchr/testify/assert"
"strings"
"testing"
"time"
)
func TestHelper_EncoderPool_bufferOverwritten(t *testing.T) {
encoder := newEncoderPool()
o1 := struct {
A int
B int
}{1, 2}
b, _ := encoder.Marshal(o1)
o2 := struct {
A int
B int
}{3, 4}
encoder.Marshal(o2)
s := strings.TrimSpace(string(b))
glog.Infoln(s)
if s != `{"A":1,"B":2}` {
t.Errorf("Buffer is overwritten! %s", s)
}
}
func TestHelper_Backoff(t *testing.T) {
expected := []float64{
250, 500, 1000,
2000, 4000, 8000,
16000, 32000, 64000,
128000, 256000, 512000,
600000, 600000, 600000,
600000, 600000, 600000,
600000, 600000, 600000,
600000, 600000, 600000,
}
for i := 0; i < 20; i++ {
now := time.Now()
b := backoff(i)
du := b.Sub(now)
glog.Infoln(du)
assert.InDelta(t, du.Seconds()*1000, expected[i], 2*expected[i])
}
}