Commit 3aa8ddbf authored by Jay Guo's avatar Jay Guo
Browse files

FAB-15151 fix data race in Raft chain UT



Change-Id: Ie8e8d3aeb80f8b6bd19fde687ffe6201ccbbf5e8
Signed-off-by: default avatarJay Guo <guojiannan1101@gmail.com>
parent d468a176
......@@ -3890,14 +3890,22 @@ func (n *network) join(id uint64, expectLeaderChange bool) {
// elect deterministically elects a node as leader
func (n *network) elect(id uint64) {
c := n.chains[id]
n.RLock()
candidate := n.chains[id]
var followers []*chain
for _, c := range n.chains {
if c.id != id {
followers = append(followers, c)
}
}
n.RUnlock()
// Send node an artificial MsgTimeoutNow to emulate leadership transfer.
c.Consensus(&orderer.ConsensusRequest{Payload: protoutil.MarshalOrPanic(&raftpb.Message{Type: raftpb.MsgTimeoutNow})}, 0)
Eventually(c.observe, LongEventualTimeout).Should(Receive(StateEqual(id, raft.StateLeader)))
candidate.Consensus(&orderer.ConsensusRequest{Payload: protoutil.MarshalOrPanic(&raftpb.Message{Type: raftpb.MsgTimeoutNow})}, 0)
Eventually(candidate.observe, LongEventualTimeout).Should(Receive(StateEqual(id, raft.StateLeader)))
// now observe leader change on other nodes
for _, c := range n.chains {
for _, c := range followers {
if c.id == id {
continue
}
......@@ -3912,7 +3920,9 @@ func (n *network) elect(id uint64) {
}
}
n.Lock()
n.leader = id
n.Unlock()
}
// sets the configEnv var declared above
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment