Skip to content

Commit 4ae24be

Browse files
committed
Check cluster state before running the tests
1 parent 3143c67 commit 4ae24be

File tree

2 files changed

+33
-7
lines changed

2 files changed

+33
-7
lines changed

cluster_test.go

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,21 +49,51 @@ func (s *clusterScenario) addrs() []string {
4949
}
5050

5151
func (s *clusterScenario) clusterClient(opt *redis.ClusterOptions) *redis.ClusterClient {
52+
var errBadState = fmt.Errorf("cluster state is not consistent")
53+
5254
opt.Addrs = s.addrs()
5355
client := redis.NewClusterClient(opt)
56+
5457
err := eventually(func() error {
55-
state, err := client.GetState()
58+
if opt.ClusterSlots != nil {
59+
return nil
60+
}
61+
62+
state, err := client.LoadState()
5663
if err != nil {
5764
return err
5865
}
66+
5967
if !state.IsConsistent() {
60-
return fmt.Errorf("cluster state is not conistent")
68+
return errBadState
69+
}
70+
71+
if len(state.Masters) < 3 {
72+
return errBadState
6173
}
74+
for _, master := range state.Masters {
75+
s := master.Client.Info("replication").Val()
76+
if !strings.Contains(s, "role:master") {
77+
return errBadState
78+
}
79+
}
80+
81+
if len(state.Slaves) < 3 {
82+
return errBadState
83+
}
84+
for _, slave := range state.Slaves {
85+
s := slave.Client.Info("replication").Val()
86+
if !strings.Contains(s, "role:slave") {
87+
return errBadState
88+
}
89+
}
90+
6291
return nil
6392
}, 30*time.Second)
6493
if err != nil {
6594
panic(err)
6695
}
96+
6797
return client
6898
}
6999

@@ -703,7 +733,7 @@ var _ = Describe("ClusterClient", func() {
703733
})
704734
Expect(err).NotTo(HaveOccurred())
705735

706-
state, err := client.GetState()
736+
state, err := client.LoadState()
707737
Expect(err).NotTo(HaveOccurred())
708738
Expect(state.IsConsistent()).To(BeTrue())
709739

export_test.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@ func (c *PubSub) ReceiveMessageTimeout(timeout time.Duration) (*Message, error)
2121
return c.receiveMessage(timeout)
2222
}
2323

24-
func (c *ClusterClient) GetState() (*clusterState, error) {
25-
return c.state.Get()
26-
}
27-
2824
func (c *ClusterClient) LoadState() (*clusterState, error) {
2925
return c.loadState()
3026
}

0 commit comments

Comments
 (0)