mirror of https://github.com/go-redis/redis.git
Merge pull request #820 from go-redis/fix/stable-tests
Check cluster state before running the tests
This commit is contained in:
commit
f7e97f0a16
|
@ -49,21 +49,51 @@ func (s *clusterScenario) addrs() []string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *clusterScenario) clusterClient(opt *redis.ClusterOptions) *redis.ClusterClient {
|
func (s *clusterScenario) clusterClient(opt *redis.ClusterOptions) *redis.ClusterClient {
|
||||||
|
var errBadState = fmt.Errorf("cluster state is not consistent")
|
||||||
|
|
||||||
opt.Addrs = s.addrs()
|
opt.Addrs = s.addrs()
|
||||||
client := redis.NewClusterClient(opt)
|
client := redis.NewClusterClient(opt)
|
||||||
|
|
||||||
err := eventually(func() error {
|
err := eventually(func() error {
|
||||||
state, err := client.GetState()
|
if opt.ClusterSlots != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
state, err := client.LoadState()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if !state.IsConsistent() {
|
if !state.IsConsistent() {
|
||||||
return fmt.Errorf("cluster state is not conistent")
|
return errBadState
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(state.Masters) < 3 {
|
||||||
|
return errBadState
|
||||||
|
}
|
||||||
|
for _, master := range state.Masters {
|
||||||
|
s := master.Client.Info("replication").Val()
|
||||||
|
if !strings.Contains(s, "role:master") {
|
||||||
|
return errBadState
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(state.Slaves) < 3 {
|
||||||
|
return errBadState
|
||||||
|
}
|
||||||
|
for _, slave := range state.Slaves {
|
||||||
|
s := slave.Client.Info("replication").Val()
|
||||||
|
if !strings.Contains(s, "role:slave") {
|
||||||
|
return errBadState
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}, 30*time.Second)
|
}, 30*time.Second)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return client
|
return client
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -703,7 +733,7 @@ var _ = Describe("ClusterClient", func() {
|
||||||
})
|
})
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
|
||||||
state, err := client.GetState()
|
state, err := client.LoadState()
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
Expect(state.IsConsistent()).To(BeTrue())
|
Expect(state.IsConsistent()).To(BeTrue())
|
||||||
|
|
||||||
|
|
|
@ -21,10 +21,6 @@ func (c *PubSub) ReceiveMessageTimeout(timeout time.Duration) (*Message, error)
|
||||||
return c.receiveMessage(timeout)
|
return c.receiveMessage(timeout)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *ClusterClient) GetState() (*clusterState, error) {
|
|
||||||
return c.state.Get()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *ClusterClient) LoadState() (*clusterState, error) {
|
func (c *ClusterClient) LoadState() (*clusterState, error) {
|
||||||
return c.loadState()
|
return c.loadState()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue