Skip to content

Commit

Permalink
test: add more logs for network-test (#1335)
Browse files Browse the repository at this point in the history
Co-authored-by: Javad Rajabzadeh <[email protected]>
  • Loading branch information
b00f and Ja7ad authored Jun 11, 2024
1 parent 5f97c1c commit 4beeda5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion network/gossip.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func newGossipService(ctx context.Context, host lp2phost.Host, eventCh chan Even

// Broadcast broadcasts a message with the specified topic ID to the network.
func (g *gossipService) Broadcast(msg []byte, topicID TopicID) error {
g.logger.Trace("publishing new message", "topic", topicID)
g.logger.Debug("publishing new message", "topic", topicID)

switch topicID {
case TopicIDBlock:
Expand Down
22 changes: 22 additions & 0 deletions network/network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@ func TestNetwork(t *testing.T) {
time.Sleep(2 * time.Second)

t.Run("Supported Protocols", func(t *testing.T) {
t.Log(t.Name())

require.EventuallyWithT(t, func(_ *assert.CollectT) {
protos := networkM.Protocols()
assert.Contains(t, protos, lp2pproto.ProtoIDv2Stop)
Expand All @@ -230,6 +232,8 @@ func TestNetwork(t *testing.T) {
})

t.Run("all nodes have at least one connection to the bootstrap node B", func(t *testing.T) {
t.Log(t.Name())

assert.EventuallyWithT(t, func(c *assert.CollectT) {
assert.GreaterOrEqual(c, networkP.NumConnectedPeers(), 1) // Connected to B, M, N, X
}, 5*time.Second, 100*time.Millisecond)
Expand All @@ -252,6 +256,8 @@ func TestNetwork(t *testing.T) {
})

t.Run("Gossip: all nodes receive gossip messages", func(t *testing.T) {
t.Log(t.Name())

msg := ts.RandBytes(64)

require.NoError(t, networkP.Broadcast(msg, TopicIDBlock))
Expand All @@ -268,6 +274,8 @@ func TestNetwork(t *testing.T) {
})

t.Run("only nodes subscribed to the consensus topic receive consensus gossip messages", func(t *testing.T) {
t.Log(t.Name())

msg := ts.RandBytes(64)

require.NoError(t, networkP.Broadcast(msg, TopicIDConsensus))
Expand All @@ -283,6 +291,8 @@ func TestNetwork(t *testing.T) {
})

t.Run("node P (public) is directly accessible by nodes M and N (private behind NAT)", func(t *testing.T) {
t.Log(t.Name())

require.NoError(t, networkM.host.Connect(networkM.ctx, *publicAddrInfo))

msgM := ts.RandBytes(64)
Expand All @@ -293,6 +303,8 @@ func TestNetwork(t *testing.T) {
})

t.Run("node P (public) is directly accessible by node X (private behind NAT, without relay)", func(t *testing.T) {
t.Log(t.Name())

require.NoError(t, networkX.host.Connect(networkX.ctx, *publicAddrInfo))

msgX := ts.RandBytes(64)
Expand All @@ -303,6 +315,8 @@ func TestNetwork(t *testing.T) {
})

t.Run("node P (public) is directly accessible by node B (bootstrap)", func(t *testing.T) {
t.Log(t.Name())

msgB := ts.RandBytes(64)

require.NoError(t, networkB.SendTo(msgB, networkP.SelfID()))
Expand All @@ -312,6 +326,8 @@ func TestNetwork(t *testing.T) {
})

t.Run("Ignore broadcasting identical messages", func(t *testing.T) {
t.Log(t.Name())

msg := ts.RandBytes(64)

require.NoError(t, networkM.Broadcast(msg, TopicIDBlock))
Expand All @@ -327,6 +343,8 @@ func TestNetwork(t *testing.T) {
})

t.Run("node X (private, not connected via relay) is not accessible by node M", func(t *testing.T) {
t.Log(t.Name())

msgM := ts.RandBytes(64)
require.Error(t, networkM.SendTo(msgM, networkX.SelfID()))
})
Expand All @@ -340,6 +358,8 @@ func TestNetwork(t *testing.T) {
// })

t.Run("closing connection", func(t *testing.T) {
t.Log(t.Name())

msgB := ts.RandBytes(64)

networkP.Stop()
Expand All @@ -350,6 +370,8 @@ func TestNetwork(t *testing.T) {
})

t.Run("Reachability Status", func(t *testing.T) {
t.Log(t.Name())

assert.Equal(t, networkP.ReachabilityStatus(), "Public")
assert.Equal(t, networkB.ReachabilityStatus(), "Public")
assert.Equal(t, networkM.ReachabilityStatus(), "Private")
Expand Down

0 comments on commit 4beeda5

Please sign in to comment.