Skip to content

Commit

Permalink
Gossip certStore test fix
Browse files Browse the repository at this point in the history
Test failed on z because scheduling.
Replaced atomic with locking to have better control

Change-Id: I33441151de341df9c031be6d9757f6cae60e1209
Signed-off-by: Yacov Manevich <yacovm@il.ibm.com>
  • Loading branch information
yacovm committed Dec 23, 2016
1 parent e3b2d3f commit 4d39ecd
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions gossip/gossip/certstore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package gossip

import (
"sync"
"sync/atomic"
"testing"
"time"

Expand Down Expand Up @@ -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()
}
Expand Down

0 comments on commit 4d39ecd

Please sign in to comment.