From 4d39ecdff5b66a52ad749498b088f0659c2c76ab Mon Sep 17 00:00:00 2001 From: YACOVM Date: Fri, 23 Dec 2016 22:32:56 +0200 Subject: [PATCH] Gossip certStore test fix Test failed on z because scheduling. Replaced atomic with locking to have better control Change-Id: I33441151de341df9c031be6d9757f6cae60e1209 Signed-off-by: Yacov Manevich --- gossip/gossip/certstore_test.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/gossip/gossip/certstore_test.go b/gossip/gossip/certstore_test.go index 935c4e02857..fe953a85b1f 100644 --- a/gossip/gossip/certstore_test.go +++ b/gossip/gossip/certstore_test.go @@ -18,7 +18,6 @@ package gossip import ( "sync" - "sync/atomic" "testing" "time" @@ -132,15 +131,21 @@ func testCertificateUpdate(t *testing.T, updateFactory func(uint64) comm.Receive wg := sync.WaitGroup{} wg.Add(1) - sentHello := int32(0) + sentHello := false + sentDataReq := false + l := sync.Mutex{} sender.On("Send", mock.Anything, mock.Anything).Run(func(arg mock.Arguments) { msg := arg.Get(0).(*proto.GossipMessage) - if hello := msg.GetHello(); hello != nil && atomic.LoadInt32(&sentHello) == int32(0) { - atomic.StoreInt32(&sentHello, int32(1)) + l.Lock() + defer l.Unlock() + + if hello := msg.GetHello(); hello != nil && !sentHello { + sentHello = true go certStore.handleMessage(createDigest(hello.Nonce)) } - if dataReq := msg.GetDataReq(); dataReq != nil { + if dataReq := msg.GetDataReq(); dataReq != nil && !sentDataReq { + sentDataReq = true certStore.handleMessage(updateFactory(dataReq.Nonce)) wg.Done() }