From d96fe6f22f1c01fbd3d09ed9252a6454e20906fa Mon Sep 17 00:00:00 2001 From: yacovm Date: Sun, 30 Jul 2017 11:04:28 +0300 Subject: [PATCH] [FAB-5503] Fix TestLeaderYield CI failure This test sometimes fails because leaderElection[channelName] returns un-expected values. I think it has to do with the fact that these values are changed via different goroutines than the test goroutine. I added RLocks for memory coherency. Change-Id: I2d58f4b221bc18e8a9db5fae487eda071807d58a Signed-off-by: yacovm --- gossip/service/integration_test.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/gossip/service/integration_test.go b/gossip/service/integration_test.go index b0a5b6c058d..16bfd29a312 100644 --- a/gossip/service/integration_test.go +++ b/gossip/service/integration_test.go @@ -110,6 +110,11 @@ func TestLeaderYield(t *testing.T) { // Returns index of the leader or -1 if no leader elected getLeader := func() int { + p0.lock.RLock() + p1.lock.RLock() + defer p0.lock.RUnlock() + defer p1.lock.RUnlock() + if p0.leaderElection[channelName].IsLeader() { // Ensure p1 isn't a leader at the same time assert.False(t, p1.leaderElection[channelName].IsLeader())