Skip to content

Commit a9d0652

Browse files
committed
Gossip comm test fix
Was notified that TestReconnections fails on ppc build with high probability. Fixed a timely assumption in TestReConnections in gossip/comm/comm_test.go Also changed the file name convention of the private and public keys to be randomly generated. Signed-off-by: Yacov Manevich <[email protected]> Change-Id: I9143efa5b7082ea1023fb1331386d5dcd01f2601
1 parent 384e294 commit a9d0652

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

gossip/comm/comm_impl.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -525,8 +525,9 @@ func createGRPCLayer(port int) (*grpc.Server, net.Listener, grpc.DialOption) {
525525
var serverOpts []grpc.ServerOption
526526
var dialOpts grpc.DialOption
527527

528-
keyFileName := fmt.Sprintf("key.%d.pem", time.Now().UnixNano())
529-
certFileName := fmt.Sprintf("cert.%d.pem", time.Now().UnixNano())
528+
529+
keyFileName := fmt.Sprintf("key.%d.pem", rand.Int63())
530+
certFileName := fmt.Sprintf("cert.%d.pem", rand.Int63())
530531

531532
defer os.Remove(keyFileName)
532533
defer os.Remove(certFileName)

gossip/comm/comm_test.go

+7-9
Original file line numberDiff line numberDiff line change
@@ -420,21 +420,19 @@ func TestReConnections(t *testing.T) {
420420

421421
// comm1 connects to comm2
422422
comm1.Send(createGossipMsg(), remotePeer(3612))
423-
time.Sleep(100 * time.Millisecond)
423+
waitForMessages(t, out2 , 1, "Comm2 didn't receive a message from comm1 in a timely manner")
424+
time.Sleep(time.Second)
424425
// comm2 sends to comm1
425426
comm2.Send(createGossipMsg(), remotePeer(3611))
426-
time.Sleep(100 * time.Millisecond)
427-
428-
assert.Equal(t, 1, len(out2))
429-
assert.Equal(t, 1, len(out1))
427+
waitForMessages(t, out1 , 1, "Comm1 didn't receive a message from comm2 in a timely manner")
430428

431429
comm1.Stop()
432430
comm1, _ = newCommInstance(3611, naiveSec)
431+
time.Sleep(time.Second)
432+
out1 = make(chan uint64, 1)
433433
go reader(out1, comm1.Accept(acceptAll))
434-
time.Sleep(300 * time.Millisecond)
435434
comm2.Send(createGossipMsg(), remotePeer(3611))
436-
time.Sleep(100 * time.Millisecond)
437-
assert.Equal(t, 2, len(out1))
435+
waitForMessages(t, out1 , 1, "Comm1 didn't receive a message from comm2 in a timely manner")
438436
}
439437

440438
func TestProbe(t *testing.T) {
@@ -498,7 +496,7 @@ func remotePeer(port int) *RemotePeer {
498496
func waitForMessages(t *testing.T, msgChan chan uint64, count int, errMsg string) {
499497
c := 0
500498
waiting := true
501-
ticker := time.NewTicker(time.Duration(5) * time.Second)
499+
ticker := time.NewTicker(time.Duration(10) * time.Second)
502500
for waiting {
503501
select {
504502
case <-msgChan:

0 commit comments

Comments
 (0)