@@ -48,6 +48,15 @@ func getGossipsubs(ctx context.Context, hs []host.Host, opts ...Option) []*PubSu
4848 return psubs
4949}
5050
51+ func TestGossipSubParamsValidate (t * testing.T ) {
52+ params := DefaultGossipSubParams ()
53+ params .Dhi = 1
54+ params .Dscore = 10
55+ if params .Validate () == nil {
56+ t .Fatal ("Params should be invalid" )
57+ }
58+ }
59+
5160func TestSparseGossipsub (t * testing.T ) {
5261 ctx , cancel := context .WithCancel (context .Background ())
5362 defer cancel ()
@@ -1768,6 +1777,7 @@ func TestGossipsubMultipleGraftTopics(t *testing.T) {
17681777 firstPeer := hosts [0 ].ID ()
17691778 secondPeer := hosts [1 ].ID ()
17701779
1780+ p1Sub := psubs [0 ]
17711781 p2Sub := psubs [1 ]
17721782 p1Router := psubs [0 ].rt .(* GossipSubRouter )
17731783 p2Router := psubs [1 ].rt .(* GossipSubRouter )
@@ -1786,9 +1796,14 @@ func TestGossipsubMultipleGraftTopics(t *testing.T) {
17861796
17871797 // Send multiple GRAFT messages to second peer from
17881798 // 1st peer
1789- p1Router .sendGraftPrune (map [peer.ID ][]string {
1790- secondPeer : {firstTopic , secondTopic , thirdTopic },
1791- }, map [peer.ID ][]string {}, map [peer.ID ]bool {})
1799+ wait := make (chan struct {})
1800+ p1Sub .eval <- func () {
1801+ defer close (wait )
1802+ p1Router .sendGraftPrune (map [peer.ID ][]string {
1803+ secondPeer : {firstTopic , secondTopic , thirdTopic },
1804+ }, map [peer.ID ][]string {}, map [peer.ID ]bool {})
1805+ }
1806+ <- wait
17921807
17931808 time .Sleep (time .Second * 1 )
17941809
@@ -2748,11 +2763,14 @@ func TestGossipsubIdontwantSend(t *testing.T) {
27482763 }
27492764 }
27502765
2766+ var midsMu sync.Mutex
27512767 var expMids []string
27522768 var actMids []string
27532769
27542770 // Used to publish a message with random data
27552771 publishMsg := func () {
2772+ midsMu .Lock ()
2773+ defer midsMu .Unlock ()
27562774 data := make ([]byte , 16 )
27572775 crand .Read (data )
27582776 m := & pb.Message {Data : data }
@@ -2769,6 +2787,8 @@ func TestGossipsubIdontwantSend(t *testing.T) {
27692787
27702788 // Checks we received the right IDONTWANT messages
27712789 checkMsgs := func () {
2790+ midsMu .Lock ()
2791+ defer midsMu .Unlock ()
27722792 sort .Strings (actMids )
27732793 sort .Strings (expMids )
27742794
0 commit comments