Skip to content

Commit

Permalink
Merge pull request redis#820 from go-redis/fix/stable-tests
Browse files Browse the repository at this point in the history
Check cluster state before running the tests
  • Loading branch information
vmihailenco authored Jul 23, 2018
2 parents 3143c67 + 4ae24be commit f7e97f0
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 7 deletions.
36 changes: 33 additions & 3 deletions cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,51 @@ func (s *clusterScenario) addrs() []string {
}

func (s *clusterScenario) clusterClient(opt *redis.ClusterOptions) *redis.ClusterClient {
var errBadState = fmt.Errorf("cluster state is not consistent")

opt.Addrs = s.addrs()
client := redis.NewClusterClient(opt)

err := eventually(func() error {
state, err := client.GetState()
if opt.ClusterSlots != nil {
return nil
}

state, err := client.LoadState()
if err != nil {
return err
}

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
}, 30*time.Second)
if err != nil {
panic(err)
}

return client
}

Expand Down Expand Up @@ -703,7 +733,7 @@ var _ = Describe("ClusterClient", func() {
})
Expect(err).NotTo(HaveOccurred())

state, err := client.GetState()
state, err := client.LoadState()
Expect(err).NotTo(HaveOccurred())
Expect(state.IsConsistent()).To(BeTrue())

Expand Down
4 changes: 0 additions & 4 deletions export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ func (c *PubSub) ReceiveMessageTimeout(timeout time.Duration) (*Message, error)
return c.receiveMessage(timeout)
}

func (c *ClusterClient) GetState() (*clusterState, error) {
return c.state.Get()
}

func (c *ClusterClient) LoadState() (*clusterState, error) {
return c.loadState()
}
Expand Down

0 comments on commit f7e97f0

Please sign in to comment.