Skip to content

Commit 4d39ecd

Browse files
committed
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 <[email protected]>
1 parent e3b2d3f commit 4d39ecd

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

gossip/gossip/certstore_test.go

+10-5
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package gossip
1818

1919
import (
2020
"sync"
21-
"sync/atomic"
2221
"testing"
2322
"time"
2423

@@ -132,15 +131,21 @@ func testCertificateUpdate(t *testing.T, updateFactory func(uint64) comm.Receive
132131

133132
wg := sync.WaitGroup{}
134133
wg.Add(1)
135-
sentHello := int32(0)
134+
sentHello := false
135+
sentDataReq := false
136+
l := sync.Mutex{}
136137
sender.On("Send", mock.Anything, mock.Anything).Run(func(arg mock.Arguments) {
137138
msg := arg.Get(0).(*proto.GossipMessage)
138-
if hello := msg.GetHello(); hello != nil && atomic.LoadInt32(&sentHello) == int32(0) {
139-
atomic.StoreInt32(&sentHello, int32(1))
139+
l.Lock()
140+
defer l.Unlock()
141+
142+
if hello := msg.GetHello(); hello != nil && !sentHello {
143+
sentHello = true
140144
go certStore.handleMessage(createDigest(hello.Nonce))
141145
}
142146

143-
if dataReq := msg.GetDataReq(); dataReq != nil {
147+
if dataReq := msg.GetDataReq(); dataReq != nil && !sentDataReq {
148+
sentDataReq = true
144149
certStore.handleMessage(updateFactory(dataReq.Nonce))
145150
wg.Done()
146151
}

0 commit comments

Comments
 (0)