MCPcopy
hub / github.com/CodisLabs/codis / TestRedisStats

Function TestRedisStats

pkg/topom/topom_stats_test.go:67–122  ·  view source on GitHub ↗
(x *testing.T)

Source from the content-addressed store, hash-verified

65}
66
67func TestRedisStats(x *testing.T) {
68 t := openTopom()
69 defer t.Close()
70
71 check := func(succ, fail []string) {
72 w, err := t.RefreshRedisStats(time.Second * 5)
73 assert.MustNoError(err)
74 m := w.Wait()
75 assert.Must(len(m) == len(succ)+len(fail))
76 for _, addr := range succ {
77 s, ok := m[addr].(*RedisStats)
78 assert.Must(ok && s != nil && s.Stats != nil)
79 }
80 for _, addr := range fail {
81 s, ok := m[addr].(*RedisStats)
82 assert.Must(ok && s != nil && s.Stats == nil)
83 assert.Must(s.Error != nil)
84 }
85 }
86
87 g := &models.Group{Id: 1}
88
89 s1 := newFakeServer()
90 defer s1.Close()
91
92 s2 := newFakeServer()
93 defer s2.Close()
94
95 g.Servers = []*models.GroupServer{
96 &models.GroupServer{Addr: s1.Addr},
97 &models.GroupServer{Addr: s2.Addr},
98 }
99
100 check([]string{}, []string{})
101
102 contextCreateGroup(t, g)
103 check([]string{s1.Addr, s2.Addr}, []string{})
104
105 s1.Close()
106 check([]string{s2.Addr}, []string{s1.Addr})
107
108 s2.Close()
109 check([]string{}, []string{s1.Addr, s2.Addr})
110
111 s3 := newFakeServer()
112 defer s3.Close()
113
114 g.Servers = []*models.GroupServer{
115 &models.GroupServer{Addr: s3.Addr},
116 }
117 contextUpdateGroup(t, g)
118 check([]string{s3.Addr}, []string{})
119
120 contextRemoveGroup(t, g)
121 check([]string{}, []string{})
122}
123
124type fakeServer struct {

Callers

nothing calls this directly

Calls 8

openTopomFunction · 0.85
newFakeServerFunction · 0.85
contextCreateGroupFunction · 0.85
contextUpdateGroupFunction · 0.85
contextRemoveGroupFunction · 0.85
RefreshRedisStatsMethod · 0.80
CloseMethod · 0.65
WaitMethod · 0.45

Tested by

no test coverage detected