@@ -21,6 +21,7 @@ import (
21
21
"testing"
22
22
"time"
23
23
24
+ protoG "github.com/golang/protobuf/proto"
24
25
"github.com/hyperledger/fabric/core/config/configtest"
25
26
"github.com/hyperledger/fabric/gossip/common"
26
27
"github.com/hyperledger/fabric/gossip/util"
@@ -35,7 +36,7 @@ var timeout = time.Second * time.Duration(15)
35
36
36
37
func init () {
37
38
util .SetupTestLogging ()
38
- aliveTimeInterval := time .Duration (time .Millisecond * 100 )
39
+ aliveTimeInterval := time .Duration (time .Millisecond * 300 )
39
40
SetAliveTimeInterval (aliveTimeInterval )
40
41
SetAliveExpirationTimeout (10 * aliveTimeInterval )
41
42
SetAliveExpirationCheckInterval (aliveTimeInterval )
@@ -298,9 +299,11 @@ func (g *gossipInstance) Stop() {
298
299
}
299
300
g .gRGCserv .Stop ()
300
301
g .lsnr .Close ()
302
+ g .comm .lock .Lock ()
301
303
for _ , stream := range g .comm .streams {
302
304
stream .CloseSend ()
303
305
}
306
+ g .comm .lock .Unlock ()
304
307
for _ , conn := range g .comm .conns {
305
308
conn .Close ()
306
309
}
@@ -361,8 +364,9 @@ func createDiscoveryInstanceThatGossips(port int, id string, bootstrapPeers []st
361
364
362
365
discSvc := NewDiscoveryService (self , comm , comm , pol )
363
366
for _ , bootPeer := range bootstrapPeers {
364
- discSvc .Connect (NetworkMember {Endpoint : bootPeer , InternalEndpoint : bootPeer }, func () (* PeerIdentification , error ) {
365
- return & PeerIdentification {SelfOrg : true , ID : common .PKIidType (bootPeer )}, nil
367
+ bp := bootPeer
368
+ discSvc .Connect (NetworkMember {Endpoint : bp , InternalEndpoint : bootPeer }, func () (* PeerIdentification , error ) {
369
+ return & PeerIdentification {SelfOrg : true , ID : common .PKIidType (bp )}, nil
366
370
})
367
371
}
368
372
@@ -463,7 +467,6 @@ func TestConnect(t *testing.T) {
463
467
})
464
468
inst .comm .mock .On ("Ping" , mock .Anything )
465
469
inst .comm .lock .Unlock ()
466
-
467
470
instances = append (instances , inst )
468
471
j := (i + 1 ) % 10
469
472
endpoint := fmt .Sprintf ("localhost:%d" , 7611 + j )
@@ -474,12 +477,6 @@ func TestConnect(t *testing.T) {
474
477
}
475
478
476
479
time .Sleep (time .Second * 3 )
477
- assert .Len (t , firstSentMemReqMsgs , 10 )
478
- close (firstSentMemReqMsgs )
479
- for firstSentSelfMsg := range firstSentMemReqMsgs {
480
- assert .Nil (t , firstSentSelfMsg .Envelope .SecretEnvelope )
481
- }
482
-
483
480
fullMembership := func () bool {
484
481
return nodeNum - 1 == len (instances [nodeNum - 1 ].GetMembership ())
485
482
}
@@ -493,6 +490,11 @@ func TestConnect(t *testing.T) {
493
490
am , _ = mr2 .GetMemReq ().SelfInformation .ToGossipMessage ()
494
491
assert .Nil (t , am .SecretEnvelope )
495
492
stopInstances (t , instances )
493
+ assert .Len (t , firstSentMemReqMsgs , 10 )
494
+ close (firstSentMemReqMsgs )
495
+ for firstSentSelfMsg := range firstSentMemReqMsgs {
496
+ assert .Nil (t , firstSentSelfMsg .Envelope .SecretEnvelope )
497
+ }
496
498
}
497
499
498
500
func TestUpdate (t * testing.T ) {
@@ -804,7 +806,7 @@ func TestDisclosurePolicyWithPull(t *testing.T) {
804
806
// Now, we shutdown instance 0 and ensure that peers that shouldn't know it,
805
807
// do not know it via membership requests
806
808
stopInstances (t , []* gossipInstance {instances1 [0 ]})
807
- time .Sleep (time .Second * 3 )
809
+ time .Sleep (time .Second * 6 )
808
810
for _ , inst := range append (instances1 [1 :], instances2 ... ) {
809
811
if peersThatShouldBeKnownToPeers [inst .port ][0 ] == 8610 {
810
812
assert .Equal (t , 1 , inst .Discovery .(* gossipDiscoveryImpl ).deadMembership .Size ())
@@ -856,15 +858,16 @@ func discPolForPeer(selfPort int) DisclosurePolicy {
856
858
// Else, expose peers with even ids to other peers with even ids
857
859
return portOfAliveMsg % 2 == 0 && targetPort % 2 == 0
858
860
}, func (msg * proto.SignedGossipMessage ) * proto.Envelope {
861
+ envelope := protoG .Clone (msg .Envelope ).(* proto.Envelope )
859
862
if selfPort < 8615 && targetPort >= 8615 {
860
- msg . Envelope .SecretEnvelope = nil
863
+ envelope .SecretEnvelope = nil
861
864
}
862
865
863
866
if selfPort >= 8615 && targetPort < 8615 {
864
- msg . Envelope .SecretEnvelope = nil
867
+ envelope .SecretEnvelope = nil
865
868
}
866
869
867
- return msg . Envelope
870
+ return envelope
868
871
}
869
872
}
870
873
}
0 commit comments