GetLeaderNode returns the leader node, if there is no leader or reach consensus return raft.None. excludeNodeID is the node ID that will be excluded from the leader check, it's useful when we want to check if the leader is changed.
(excludeNodeID uint64)
| 123 | // excludeNodeID is the node ID that will be excluded from the leader check, it's useful when we want to |
| 124 | // check if the leader is changed. |
| 125 | func (c *TestCluster) GetLeaderID(excludeNodeID uint64) uint64 { |
| 126 | leaderID := raft.None |
| 127 | for _, n := range c.nodes { |
| 128 | if n.config.ID == excludeNodeID { |
| 129 | continue |
| 130 | } |
| 131 | // If the leader is not the same means nodes are not reach consensus. |
| 132 | if leaderID != raft.None && leaderID != n.GetRaftLead() { |
| 133 | return raft.None |
| 134 | } |
| 135 | leaderID = n.GetRaftLead() |
| 136 | } |
| 137 | return leaderID |
| 138 | } |
| 139 | |
| 140 | func (c *TestCluster) ListNodes() []*Node { |
| 141 | return c.nodes |
no test coverage detected