@@ -44,16 +44,16 @@ import (
44
44
)
45
45
46
46
var (
47
- portPrefix = 28000
48
- )
47
+ portStartRange = 28000
49
48
50
- var orgID = []byte ("ORG1" )
49
+ orgID = []byte ("ORG1" )
51
50
52
- type peerIdentityAcceptor func (identity api.PeerIdentityType ) error
51
+ noopPeerIdentityAcceptor = func (identity api.PeerIdentityType ) error {
52
+ return nil
53
+ }
54
+ )
53
55
54
- var noopPeerIdentityAcceptor = func (identity api.PeerIdentityType ) error {
55
- return nil
56
- }
56
+ type peerIdentityAcceptor func (identity api.PeerIdentityType ) error
57
57
58
58
type joinChanMsg struct {
59
59
}
@@ -144,7 +144,7 @@ func (*cryptoServiceMock) ValidateIdentity(peerIdentity api.PeerIdentityType) er
144
144
return nil
145
145
}
146
146
147
- func bootPeers (ids ... int ) []string {
147
+ func bootPeers (portPrefix int , ids ... int ) []string {
148
148
peers := []string {}
149
149
for _ , id := range ids {
150
150
peers = append (peers , fmt .Sprintf ("localhost:%d" , id + portPrefix ))
@@ -290,11 +290,11 @@ func (mock *ramLedger) Close() {
290
290
}
291
291
292
292
// Default configuration to be used for gossip and communication modules
293
- func newGossipConfig (id int , boot ... int ) * gossip.Config {
293
+ func newGossipConfig (portPrefix , id int , boot ... int ) * gossip.Config {
294
294
port := id + portPrefix
295
295
return & gossip.Config {
296
296
BindPort : port ,
297
- BootstrapPeers : bootPeers (boot ... ),
297
+ BootstrapPeers : bootPeers (portPrefix , boot ... ),
298
298
ID : fmt .Sprintf ("p%d" , id ),
299
299
MaxBlockCountToStore : 0 ,
300
300
MaxPropagationBurstLatency : time .Duration (10 ) * time .Millisecond ,
@@ -373,12 +373,14 @@ func newPeerNode(config *gossip.Config, committer committer.Committer, acceptor
373
373
}
374
374
375
375
func TestNilDirectMsg (t * testing.T ) {
376
+ t .Parallel ()
376
377
mc := & mockCommitter {}
377
378
mc .On ("LedgerHeight" , mock .Anything ).Return (uint64 (1 ), nil )
378
379
g := & mocks.GossipMock {}
379
380
g .On ("Accept" , mock .Anything , false ).Return (make (<- chan * proto.GossipMessage ), nil )
380
381
g .On ("Accept" , mock .Anything , true ).Return (nil , make (chan proto.ReceivedMessage ))
381
- p := newPeerNodeWithGossip (newGossipConfig (0 ), mc , noopPeerIdentityAcceptor , g )
382
+ portPrefix := portStartRange + 50
383
+ p := newPeerNodeWithGossip (newGossipConfig (portPrefix , 0 ), mc , noopPeerIdentityAcceptor , g )
382
384
defer p .shutdown ()
383
385
p .s .handleStateRequest (nil )
384
386
p .s .directMessage (nil )
@@ -390,25 +392,29 @@ func TestNilDirectMsg(t *testing.T) {
390
392
}
391
393
392
394
func TestNilAddPayload (t * testing.T ) {
395
+ t .Parallel ()
393
396
mc := & mockCommitter {}
394
397
mc .On ("LedgerHeight" , mock .Anything ).Return (uint64 (1 ), nil )
395
398
g := & mocks.GossipMock {}
396
399
g .On ("Accept" , mock .Anything , false ).Return (make (<- chan * proto.GossipMessage ), nil )
397
400
g .On ("Accept" , mock .Anything , true ).Return (nil , make (chan proto.ReceivedMessage ))
398
- p := newPeerNodeWithGossip (newGossipConfig (0 ), mc , noopPeerIdentityAcceptor , g )
401
+ portPrefix := portStartRange + 100
402
+ p := newPeerNodeWithGossip (newGossipConfig (portPrefix , 0 ), mc , noopPeerIdentityAcceptor , g )
399
403
defer p .shutdown ()
400
404
err := p .s .AddPayload (nil )
401
405
assert .Error (t , err )
402
406
assert .Contains (t , err .Error (), "nil" )
403
407
}
404
408
405
409
func TestAddPayloadLedgerUnavailable (t * testing.T ) {
410
+ t .Parallel ()
406
411
mc := & mockCommitter {}
407
412
mc .On ("LedgerHeight" , mock .Anything ).Return (uint64 (1 ), nil )
408
413
g := & mocks.GossipMock {}
409
414
g .On ("Accept" , mock .Anything , false ).Return (make (<- chan * proto.GossipMessage ), nil )
410
415
g .On ("Accept" , mock .Anything , true ).Return (nil , make (chan proto.ReceivedMessage ))
411
- p := newPeerNodeWithGossip (newGossipConfig (0 ), mc , noopPeerIdentityAcceptor , g )
416
+ portPrefix := portStartRange + 150
417
+ p := newPeerNodeWithGossip (newGossipConfig (portPrefix , 0 ), mc , noopPeerIdentityAcceptor , g )
412
418
defer p .shutdown ()
413
419
// Simulate a problem in the ledger
414
420
failedLedger := mock.Mock {}
@@ -433,7 +439,7 @@ func TestLargeBlockGap(t *testing.T) {
433
439
// than itself (500 blocks higher).
434
440
// The peer needs to ask blocks in a way such that the size of the payload buffer
435
441
// never rises above a certain threshold.
436
-
442
+ t . Parallel ()
437
443
mc := & mockCommitter {}
438
444
blocksPassedToLedger := make (chan uint64 , 200 )
439
445
mc .On ("CommitWithPvtData" , mock .Anything ).Run (func (arg mock.Arguments ) {
@@ -481,7 +487,8 @@ func TestLargeBlockGap(t *testing.T) {
481
487
SignedGossipMessage : sMsg ,
482
488
}
483
489
})
484
- p := newPeerNodeWithGossip (newGossipConfig (0 ), mc , noopPeerIdentityAcceptor , g )
490
+ portPrefix := portStartRange + 200
491
+ p := newPeerNodeWithGossip (newGossipConfig (portPrefix , 0 ), mc , noopPeerIdentityAcceptor , g )
485
492
defer p .shutdown ()
486
493
487
494
// Process blocks at a speed of 20 Millisecond for each block.
@@ -504,7 +511,7 @@ func TestOverPopulation(t *testing.T) {
504
511
// with a gap in between, and ensure that the payload buffer
505
512
// rejects blocks starting if the distance between the ledger height to the latest
506
513
// block it contains is bigger than defMaxBlockDistance.
507
-
514
+ t . Parallel ()
508
515
mc := & mockCommitter {}
509
516
blocksPassedToLedger := make (chan uint64 , 10 )
510
517
mc .On ("CommitWithPvtData" , mock .Anything ).Run (func (arg mock.Arguments ) {
@@ -514,7 +521,8 @@ func TestOverPopulation(t *testing.T) {
514
521
g := & mocks.GossipMock {}
515
522
g .On ("Accept" , mock .Anything , false ).Return (make (<- chan * proto.GossipMessage ), nil )
516
523
g .On ("Accept" , mock .Anything , true ).Return (nil , make (chan proto.ReceivedMessage ))
517
- p := newPeerNode (newGossipConfig (0 ), mc , noopPeerIdentityAcceptor )
524
+ portPrefix := portStartRange + 250
525
+ p := newPeerNode (newGossipConfig (portPrefix , 0 ), mc , noopPeerIdentityAcceptor )
518
526
defer p .shutdown ()
519
527
520
528
// Add some blocks in a sequential manner and make sure it works
@@ -567,6 +575,7 @@ func TestBlockingEnqueue(t *testing.T) {
567
575
// Scenario: In parallel, get blocks from gossip and from the orderer.
568
576
// The blocks from the orderer we get are X2 times the amount of blocks from gossip.
569
577
// The blocks we get from gossip are random indices, to maximize disruption.
578
+ t .Parallel ()
570
579
mc := & mockCommitter {}
571
580
blocksPassedToLedger := make (chan uint64 , 10 )
572
581
mc .On ("CommitWithPvtData" , mock .Anything ).Run (func (arg mock.Arguments ) {
@@ -576,7 +585,8 @@ func TestBlockingEnqueue(t *testing.T) {
576
585
g := & mocks.GossipMock {}
577
586
g .On ("Accept" , mock .Anything , false ).Return (make (<- chan * proto.GossipMessage ), nil )
578
587
g .On ("Accept" , mock .Anything , true ).Return (nil , make (chan proto.ReceivedMessage ))
579
- p := newPeerNode (newGossipConfig (0 ), mc , noopPeerIdentityAcceptor )
588
+ portPrefix := portStartRange + 300
589
+ p := newPeerNode (newGossipConfig (portPrefix , 0 ), mc , noopPeerIdentityAcceptor )
580
590
defer p .shutdown ()
581
591
582
592
numBlocksReceived := 500
@@ -631,6 +641,7 @@ func TestBlockingEnqueue(t *testing.T) {
631
641
}
632
642
633
643
func TestHaltChainProcessing (t * testing.T ) {
644
+ t .Parallel ()
634
645
gossipChannel := func (c chan * proto.GossipMessage ) <- chan * proto.GossipMessage {
635
646
return c
636
647
}
@@ -687,29 +698,33 @@ func TestHaltChainProcessing(t *testing.T) {
687
698
v .On ("Validate" ).Return (& errors2.VSCCExecutionFailureError {
688
699
Reason : "foobar" ,
689
700
}).Once ()
690
- newPeerNodeWithGossipWithValidator (newGossipConfig (0 ), mc , noopPeerIdentityAcceptor , g , v )
701
+ portPrefix := portStartRange + 350
702
+ newPeerNodeWithGossipWithValidator (newGossipConfig (portPrefix , 0 ), mc , noopPeerIdentityAcceptor , g , v )
691
703
gossipMsgs <- newBlockMsg (1 )
692
704
logAsserter .assertLastLogContains (t , "Got error while committing" )
693
705
logAsserter .assertLastLogContains (t , "foobar" , "Aborting chain processing" )
694
706
}
695
707
696
708
func TestFailures (t * testing.T ) {
709
+ t .Parallel ()
710
+ portPrefix := portStartRange + 400
697
711
mc := & mockCommitter {}
698
712
mc .On ("LedgerHeight" , mock .Anything ).Return (uint64 (0 ), nil )
699
713
g := & mocks.GossipMock {}
700
714
g .On ("Accept" , mock .Anything , false ).Return (make (<- chan * proto.GossipMessage ), nil )
701
715
g .On ("Accept" , mock .Anything , true ).Return (nil , make (chan proto.ReceivedMessage ))
702
716
g .On ("PeersOfChannel" , mock .Anything ).Return ([]discovery.NetworkMember {})
703
717
assert .Panics (t , func () {
704
- newPeerNodeWithGossip (newGossipConfig (0 ), mc , noopPeerIdentityAcceptor , g )
718
+ newPeerNodeWithGossip (newGossipConfig (portPrefix , 0 ), mc , noopPeerIdentityAcceptor , g )
705
719
})
706
720
// Reprogram mock
707
721
mc .Mock = mock.Mock {}
708
722
mc .On ("LedgerHeight" , mock .Anything ).Return (uint64 (1 ), errors .New ("Failed accessing ledger" ))
709
- assert .Nil (t , newPeerNodeWithGossip (newGossipConfig (0 ), mc , noopPeerIdentityAcceptor , g ))
723
+ assert .Nil (t , newPeerNodeWithGossip (newGossipConfig (portPrefix , 0 ), mc , noopPeerIdentityAcceptor , g ))
710
724
}
711
725
712
726
func TestGossipReception (t * testing.T ) {
727
+ t .Parallel ()
713
728
signalChan := make (chan struct {})
714
729
rawblock := & pcomm.Block {
715
730
Header : & pcomm.BlockHeader {
@@ -766,7 +781,8 @@ func TestGossipReception(t *testing.T) {
766
781
receivedChan <- struct {}{}
767
782
})
768
783
mc .On ("LedgerHeight" , mock .Anything ).Return (uint64 (1 ), nil )
769
- p := newPeerNodeWithGossip (newGossipConfig (0 ), mc , noopPeerIdentityAcceptor , g )
784
+ portPrefix := portStartRange + 450
785
+ p := newPeerNodeWithGossip (newGossipConfig (portPrefix , 0 ), mc , noopPeerIdentityAcceptor , g )
770
786
defer p .shutdown ()
771
787
select {
772
788
case <- receivedChan :
@@ -781,6 +797,7 @@ func TestLedgerHeightFromProperties(t *testing.T) {
781
797
// either set both metadata properly, or only the properties, or none, or both.
782
798
// Ensure the logic handles all of the 4 possible cases as needed
783
799
800
+ t .Parallel ()
784
801
// Returns whether the given networkMember was selected or not
785
802
wasNetworkMemberSelected := func (t * testing.T , networkMember discovery.NetworkMember , wg * sync.WaitGroup ) bool {
786
803
var wasGivenNetworkMemberSelected int32
@@ -811,7 +828,8 @@ func TestLedgerHeightFromProperties(t *testing.T) {
811
828
})
812
829
mc := & mockCommitter {}
813
830
mc .On ("LedgerHeight" , mock .Anything ).Return (uint64 (1 ), nil )
814
- p := newPeerNodeWithGossip (newGossipConfig (0 ), mc , noopPeerIdentityAcceptor , g )
831
+ portPrefix := portStartRange + 500
832
+ p := newPeerNodeWithGossip (newGossipConfig (portPrefix , 0 ), mc , noopPeerIdentityAcceptor , g )
815
833
defer p .shutdown ()
816
834
select {
817
835
case <- time .After (time .Second * 20 ):
@@ -853,6 +871,7 @@ func TestLedgerHeightFromProperties(t *testing.T) {
853
871
}
854
872
855
873
func TestAccessControl (t * testing.T ) {
874
+ t .Parallel ()
856
875
bootstrapSetSize := 5
857
876
bootstrapSet := make ([]* peerNode , 0 )
858
877
@@ -862,17 +881,17 @@ func TestAccessControl(t *testing.T) {
862
881
"localhost:5618" : {},
863
882
"localhost:5621" : {},
864
883
}
884
+ portPrefix := portStartRange + 600
865
885
866
886
blockPullPolicy := func (identity api.PeerIdentityType ) error {
867
887
if _ , isAuthorized := authorizedPeers [string (identity )]; isAuthorized {
868
888
return nil
869
889
}
870
890
return errors .New ("Not authorized" )
871
891
}
872
-
873
892
for i := 0 ; i < bootstrapSetSize ; i ++ {
874
893
commit := newCommitter ()
875
- bootstrapSet = append (bootstrapSet , newPeerNode (newGossipConfig (i ), commit , blockPullPolicy ))
894
+ bootstrapSet = append (bootstrapSet , newPeerNode (newGossipConfig (portPrefix , i ), commit , blockPullPolicy ))
876
895
}
877
896
878
897
defer func () {
@@ -901,7 +920,7 @@ func TestAccessControl(t *testing.T) {
901
920
902
921
for i := 0 ; i < standardPeerSetSize ; i ++ {
903
922
commit := newCommitter ()
904
- peersSet = append (peersSet , newPeerNode (newGossipConfig (bootstrapSetSize + i , 0 , 1 , 2 , 3 , 4 ), commit , blockPullPolicy ))
923
+ peersSet = append (peersSet , newPeerNode (newGossipConfig (portPrefix , bootstrapSetSize + i , 0 , 1 , 2 , 3 , 4 ), commit , blockPullPolicy ))
905
924
}
906
925
907
926
defer func () {
@@ -943,12 +962,14 @@ func TestAccessControl(t *testing.T) {
943
962
}
944
963
945
964
func TestNewGossipStateProvider_SendingManyMessages (t * testing.T ) {
965
+ t .Parallel ()
946
966
bootstrapSetSize := 5
947
967
bootstrapSet := make ([]* peerNode , 0 )
968
+ portPrefix := portStartRange + 650
948
969
949
970
for i := 0 ; i < bootstrapSetSize ; i ++ {
950
971
commit := newCommitter ()
951
- bootstrapSet = append (bootstrapSet , newPeerNode (newGossipConfig (i ), commit , noopPeerIdentityAcceptor ))
972
+ bootstrapSet = append (bootstrapSet , newPeerNode (newGossipConfig (portPrefix , i ), commit , noopPeerIdentityAcceptor ))
952
973
}
953
974
954
975
defer func () {
@@ -977,7 +998,7 @@ func TestNewGossipStateProvider_SendingManyMessages(t *testing.T) {
977
998
978
999
for i := 0 ; i < standartPeersSize ; i ++ {
979
1000
commit := newCommitter ()
980
- peersSet = append (peersSet , newPeerNode (newGossipConfig (bootstrapSetSize + i , 0 , 1 , 2 , 3 , 4 ), commit , noopPeerIdentityAcceptor ))
1001
+ peersSet = append (peersSet , newPeerNode (newGossipConfig (portPrefix , bootstrapSetSize + i , 0 , 1 , 2 , 3 , 4 ), commit , noopPeerIdentityAcceptor ))
981
1002
}
982
1003
983
1004
defer func () {
@@ -1012,10 +1033,12 @@ func TestNewGossipStateProvider_SendingManyMessages(t *testing.T) {
1012
1033
}
1013
1034
1014
1035
func TestGossipStateProvider_TestStateMessages (t * testing.T ) {
1015
- bootPeer := newPeerNode (newGossipConfig (0 ), newCommitter (), noopPeerIdentityAcceptor )
1036
+ t .Parallel ()
1037
+ portPrefix := portStartRange + 700
1038
+ bootPeer := newPeerNode (newGossipConfig (portPrefix , 0 ), newCommitter (), noopPeerIdentityAcceptor )
1016
1039
defer bootPeer .shutdown ()
1017
1040
1018
- peer := newPeerNode (newGossipConfig (1 , 0 ), newCommitter (), noopPeerIdentityAcceptor )
1041
+ peer := newPeerNode (newGossipConfig (portPrefix , 1 , 0 ), newCommitter (), noopPeerIdentityAcceptor )
1019
1042
defer peer .shutdown ()
1020
1043
1021
1044
naiveStateMsgPredicate := func (message interface {}) bool {
@@ -1080,7 +1103,9 @@ func TestGossipStateProvider_TestStateMessages(t *testing.T) {
1080
1103
// complete missing blocks. Since state transfer messages now batched, it is expected
1081
1104
// to see _exactly_ two messages with state transfer response.
1082
1105
func TestNewGossipStateProvider_BatchingOfStateRequest (t * testing.T ) {
1083
- bootPeer := newPeerNode (newGossipConfig (0 ), newCommitter (), noopPeerIdentityAcceptor )
1106
+ t .Parallel ()
1107
+ portPrefix := portStartRange + 750
1108
+ bootPeer := newPeerNode (newGossipConfig (portPrefix , 0 ), newCommitter (), noopPeerIdentityAcceptor )
1084
1109
defer bootPeer .shutdown ()
1085
1110
1086
1111
msgCount := defAntiEntropyBatchSize + 5
@@ -1099,7 +1124,7 @@ func TestNewGossipStateProvider_BatchingOfStateRequest(t *testing.T) {
1099
1124
}
1100
1125
}
1101
1126
1102
- peer := newPeerNode (newGossipConfig (1 , 0 ), newCommitter (), noopPeerIdentityAcceptor )
1127
+ peer := newPeerNode (newGossipConfig (portPrefix , 1 , 0 ), newCommitter (), noopPeerIdentityAcceptor )
1103
1128
defer peer .shutdown ()
1104
1129
1105
1130
naiveStateMsgPredicate := func (message interface {}) bool {
@@ -1238,6 +1263,7 @@ type testData struct {
1238
1263
}
1239
1264
1240
1265
func TestTransferOfPrivateRWSet (t * testing.T ) {
1266
+ t .Parallel ()
1241
1267
chainID := "testChainID"
1242
1268
1243
1269
// First gossip instance
@@ -1462,7 +1488,7 @@ func TestTransferOfPvtDataBetweenPeers(t *testing.T) {
1462
1488
Test going to check that block from one peer will be replicated into second one and
1463
1489
have identical content.
1464
1490
*/
1465
-
1491
+ t . Parallel ()
1466
1492
chainID := "testChainID"
1467
1493
1468
1494
// Initialize peer
0 commit comments