-
Notifications
You must be signed in to change notification settings - Fork 1
/
eznode_load_stats_test.go
115 lines (102 loc) · 2.38 KB
/
eznode_load_stats_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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package eznode
import (
"net/http"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestLoadWithEmptyStorageShouldBeEmpty(t *testing.T) {
t.Parallel()
chainNode1 := NewChainNode(NewChainNodeConfig{
Name: "Node 1",
Url: "http://example.com",
Limit: ChainNodeLimit{
Count: 1,
Per: 2 * time.Second,
},
RequestTimeout: 1 * time.Second,
Priority: 1,
})
createdChain := NewChain(
NewChainConfig{
Id: "test-chain",
Nodes: []*ChainNode{
chainNode1,
},
CheckTickRate: CheckTick{
TickRate: 100 * time.Millisecond,
MaxCheckDuration: 200 * time.Millisecond,
},
FailureStatusCodes: []int{},
RetryCount: 2,
},
)
ezNode := NewEzNode(
[]*Chain{
createdChain,
},
)
ezNode.LoadStats([]ChainStats{})
assert.Equal(t, uint(0), ezNode.chains["test-chain"].nodes[0].hits)
assert.Equal(t, uint64(0), ezNode.chains["test-chain"].nodes[0].totalHits)
assert.Equal(t, 0, len(ezNode.chains["test-chain"].nodes[0].responseStats))
}
func TestShouldLoadCorrectly(t *testing.T) {
t.Parallel()
currentHit := uint(2)
totalHits := uint64(141)
chainNode1 := NewChainNode(NewChainNodeConfig{
Name: "Node 1",
Url: "http://example.com",
Limit: ChainNodeLimit{
Count: 1,
Per: 2 * time.Second,
},
RequestTimeout: 1 * time.Second,
Priority: 1,
Middleware: func(request *http.Request) *http.Request {
return request
},
})
createdChain := NewChain(
NewChainConfig{
Id: "test-chain",
Nodes: []*ChainNode{
chainNode1,
},
CheckTickRate: CheckTick{
TickRate: 100 * time.Millisecond,
MaxCheckDuration: 200 * time.Millisecond,
},
FailureStatusCodes: []int{},
RetryCount: 2,
},
)
ezNode := NewEzNode(
[]*Chain{
createdChain,
},
)
ezNode.LoadStats([]ChainStats{
{
Id: "test-chain",
Nodes: []ChainNodeStats{
{
Name: "Node 1",
CurrentHits: currentHit,
TotalHits: totalHits,
ResponseStats: map[int]uint64{
0: 10,
200: 5,
},
Limits: 0,
Priority: 0,
},
},
},
})
assert.Equal(t, uint(0), ezNode.chains["test-chain"].nodes[0].hits)
assert.Equal(t, totalHits, ezNode.chains["test-chain"].nodes[0].totalHits)
assert.Equal(t, uint64(10), ezNode.chains["test-chain"].nodes[0].responseStats[0])
assert.Equal(t, uint64(5), ezNode.chains["test-chain"].nodes[0].responseStats[200])
}