Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ jobs:
github.com/ChainSafe/gossamer/dot/core,
github.com/ChainSafe/gossamer/dot/rpc/modules,
github.com/ChainSafe/gossamer/lib/babe,
github.com/ChainSafe/gossamer/dot/network
]
runs-on: ubuntu-latest
steps:
Expand Down
111 changes: 111 additions & 0 deletions dot/network/gossip_integration_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
// Copyright 2021 ChainSafe Systems (ON)
// SPDX-License-Identifier: LGPL-3.0-only

//go:build integration

package network

import (
"testing"
"time"

"github.com/ChainSafe/gossamer/dot/types"

"github.com/stretchr/testify/require"
)

// test gossip messages to connected peers
func TestGossip(t *testing.T) {
Comment thread
timwu20 marked this conversation as resolved.
Outdated
if testing.Short() {
t.Skip("skipping TestGossip; currently, nothing is gossiped")
}

Comment thread
timwu20 marked this conversation as resolved.
Outdated
t.Parallel()

configA := &Config{
BasePath: t.TempDir(),
Port: availablePort(t),
NoBootstrap: true,
NoMDNS: true,
}

nodeA := createTestService(t, configA)
handlerA := newTestStreamHandler(testBlockAnnounceMessageDecoder)
nodeA.host.registerStreamHandler(nodeA.host.protocolID, handlerA.handleStream)

configB := &Config{
BasePath: t.TempDir(),
Port: availablePort(t),
NoBootstrap: true,
NoMDNS: true,
}

nodeB := createTestService(t, configB)
handlerB := newTestStreamHandler(testBlockAnnounceMessageDecoder)
nodeB.host.registerStreamHandler(nodeB.host.protocolID, handlerB.handleStream)

addrInfoA := nodeA.host.addrInfo()
err := nodeB.host.connect(addrInfoA)
// retry connect if "failed to dial" error
if failedToDial(err) {
time.Sleep(TestBackoffTimeout)
err = nodeB.host.connect(addrInfoA)
}
require.NoError(t, err)

configC := &Config{
BasePath: t.TempDir(),
Port: availablePort(t),
NoBootstrap: true,
NoMDNS: true,
}

nodeC := createTestService(t, configC)
handlerC := newTestStreamHandler(testBlockAnnounceMessageDecoder)
nodeC.host.registerStreamHandler(nodeC.host.protocolID, handlerC.handleStream)

err = nodeC.host.connect(addrInfoA)
// retry connect if "failed to dial" error
if failedToDial(err) {
time.Sleep(TestBackoffTimeout)
err = nodeC.host.connect(addrInfoA)
}
require.NoError(t, err)
Comment thread
timwu20 marked this conversation as resolved.
Outdated

addrInfoB := nodeB.host.addrInfo()
err = nodeC.host.connect(addrInfoB)
// retry connect if "failed to dial" error
if failedToDial(err) {
time.Sleep(TestBackoffTimeout)
err = nodeC.host.connect(addrInfoB)
}
require.NoError(t, err)

announceMessage := &BlockAnnounceMessage{
Number: 128 * 7,
Digest: types.NewDigest(),
}

time.Sleep(10 * time.Second)

_, err = nodeA.host.send(addrInfoB.ID, "/gossamer/test/0/block-announces/1", announceMessage)
require.NoError(t, err)

time.Sleep(10 * time.Second)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess there is no way around those 10s sleeps right?


hash, err := announceMessage.Hash()
require.NoError(t, err)

t.Logf("B %+v\n", nodeB.gossip.seenMap)
t.Logf("C %+v\n", nodeC.gossip.seenMap)
t.Logf("A %+v\n", nodeA.gossip.seenMap)
Comment thread
timwu20 marked this conversation as resolved.
Outdated

_, ok := nodeB.gossip.seenMap[hash]
require.True(t, ok, "node B did not receive block request message from node A")

_, ok = nodeC.gossip.seenMap[hash]
require.True(t, ok, "node C did not receive block request message from node B")

_, ok = nodeA.gossip.seenMap[hash]
require.True(t, ok, "node A did not receive block request message from node C")
}