Skip to content

Commit

Permalink
Re-enable disabled gossipsub test (#566)
Browse files Browse the repository at this point in the history
And change it to take into account the fact that libp2p now trims
connections immediately (when no grace-period is specified) instead of
waiting for a timeout.
  • Loading branch information
Stebalien authored Aug 6, 2024
1 parent dc33a34 commit 19ffbb3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 17 deletions.
15 changes: 1 addition & 14 deletions gossipsub_connmgr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
)

func TestGossipsubConnTagMessageDeliveries(t *testing.T) {
t.Skip("Test disabled with go-libp2p v0.22.0") // TODO: reenable test when updating to v0.23.0
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

Expand Down Expand Up @@ -90,7 +89,7 @@ func TestGossipsubConnTagMessageDeliveries(t *testing.T) {
// sybil squatters to be connected later
sybilHosts := getDefaultHosts(t, nSquatter)
for _, h := range sybilHosts {
squatter := &sybilSquatter{h: h}
squatter := &sybilSquatter{h: h, ignoreErrors: true}
h.SetStreamHandler(GossipSubID_v10, squatter.handleStream)
}

Expand Down Expand Up @@ -144,18 +143,6 @@ func TestGossipsubConnTagMessageDeliveries(t *testing.T) {
allHosts := append(honestHosts, sybilHosts...)
connectAll(t, allHosts)

// verify that we have a bunch of connections
for _, h := range honestHosts {
if len(h.Network().Conns()) != nHonest+nSquatter-1 {
t.Errorf("expected to have conns to all peers, have %d", len(h.Network().Conns()))
}
}

// force the connection managers to trim, so we don't need to muck about with timing as much
for _, cm := range connmgrs {
cm.TrimOpenConns(ctx)
}

// we should still have conns to all the honest peers, but not the sybils
for _, h := range honestHosts {
nHonestConns := 0
Expand Down
13 changes: 10 additions & 3 deletions gossipsub_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2025,15 +2025,19 @@ func TestGossipSubJoinTopic(t *testing.T) {
}

type sybilSquatter struct {
h host.Host
h host.Host
ignoreErrors bool // set to false to ignore connection/stream errors.
}

func (sq *sybilSquatter) handleStream(s network.Stream) {
defer s.Close()

os, err := sq.h.NewStream(context.Background(), s.Conn().RemotePeer(), GossipSubID_v10)
if err != nil {
panic(err)
if !sq.ignoreErrors {
panic(err)
}
return
}

// send a subscription for test in the output stream to become candidate for GRAFT
Expand All @@ -2044,7 +2048,10 @@ func (sq *sybilSquatter) handleStream(s network.Stream) {
topic := "test"
err = w.WriteMsg(&pb.RPC{Subscriptions: []*pb.RPC_SubOpts{{Subscribe: &truth, Topicid: &topic}}})
if err != nil {
panic(err)
if !sq.ignoreErrors {
panic(err)
}
return
}

var rpc pb.RPC
Expand Down

0 comments on commit 19ffbb3

Please sign in to comment.