Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: create multiple nodes #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
42 changes: 24 additions & 18 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,60 +6,66 @@ import (
"time"

"github.com/stretchr/testify/require"
"github.com/waku-org/go-waku/waku/v2/node"
"github.com/waku-org/go-waku/waku/v2/protocol/relay"
)

var nodeList = []string{
"/dns4/node-01.ac-cn-hongkong-c.status.prod.statusim.net/tcp/30303/p2p/16Uiu2HAkvEZgh3KLwhLwXg95e5ojM8XykJ4Kxi2T7hk22rnA7pJC",
"/dns4/node-01.do-ams3.status.prod.statusim.net/tcp/30303/p2p/16Uiu2HAm6HZZr7aToTvEBPpiys4UxajCTU97zj5v7RNR2gbniy1D",
"/dns4/node-01.gc-us-central1-a.status.prod.statusim.net/tcp/30303/p2p/16Uiu2HAkwBp8T6G77kQXSNMnxgaMky1JeyML5yqoTHRM8dbeCBNb",
"/dns4/node-02.ac-cn-hongkong-c.status.prod.statusim.net/tcp/30303/p2p/16Uiu2HAmFy8BrJhCEmCYrUfBdSNkrPw6VHExtv4rRp1DSBnCPgx8",
"/dns4/node-02.do-ams3.status.prod.statusim.net/tcp/30303/p2p/16Uiu2HAmSve7tR5YZugpskMv2dmJAsMUKmfWYEKRXNUxRaTCnsXV",
"/dns4/node-02.gc-us-central1-a.status.prod.statusim.net/tcp/30303/p2p/16Uiu2HAmDQugwDHM3YeUp86iGjrUvbdw3JPRgikC7YoGBsT2ymMg",
"/dns4/metal-01.he-eu-hel1.vacdev.misc.statusim.net/tcp/60002/p2p/16Uiu2HAmVFXtAfSj4EiR7mL2KvL4EE2wztuQgUSBoj2Jx2KeXFLN",
}

// If using vscode, go to Preferences > Settings, and edit Go: Test Timeout to at least 60s

func (s *StoreSuite) TestBasic() {
numMsgToSend := 100
numMsgToSend := 2500
pubsubTopic := relay.DefaultWakuTopic
contentTopic := "test1"
contentTopic := "test22"

ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second) // Test shouldnt take more than 60s
ctx, cancel := context.WithTimeout(context.Background(), 300*time.Second) // Test shouldnt take more than 60s
defer cancel()

// Connecting to nodes
// ================================================================

log.Info("Connecting to nodes...")

connectToNodes(ctx, s.node)
for _, n := range s.nodes {
connectToNodes(ctx, n)
}

time.Sleep(2 * time.Second) // Required so Identify protocol is executed

s.NotZero(len(s.node.Relay().PubSub().ListPeers(relay.DefaultWakuTopic)), "no peers available")
for _, n := range s.nodes {
s.NotZero(len(n.Relay().PubSub().ListPeers(relay.DefaultWakuTopic)), "no peers available")
}

// Sending messages
// ================================================================
startTime := s.node.Timesource().Now()
startTime := s.nodes[0].Timesource().Now().Add(-2 * time.Second)

// err := sendMessages( to send the msgs sequentially
err := sendMessagesConcurrent(ctx, s.node, numMsgToSend, pubsubTopic, contentTopic)
require.NoError(s.T(), err)
wg := sync.WaitGroup{}
wg.Add(len(s.nodes))
for _, currN := range s.nodes {
go func(n *node.WakuNode) {
defer wg.Done()
err := sendMessagesConcurrent(ctx, n, numMsgToSend, pubsubTopic, contentTopic)
require.NoError(s.T(), err)
}(currN)
}
wg.Wait()

endTime := s.node.Timesource().Now()
endTime := s.nodes[0].Timesource().Now().Add(2 * time.Second)

// Store
// ================================================================

time.Sleep(5 * time.Second) // Adding a delay to guarantee that messages are inserted (needed with sqlite)

wg := sync.WaitGroup{}
for _, addr := range nodeList {
wg.Add(1)
func(addr string) {
defer wg.Done()
cnt, err := queryNode(ctx, s.node, addr, pubsubTopic, contentTopic, startTime, endTime)
cnt, err := queryNode(ctx, s.nodes[0], addr, pubsubTopic, contentTopic, startTime, endTime)
s.NoError(err)
s.Equal(numMsgToSend, cnt)
}(addr)
Expand Down
25 changes: 15 additions & 10 deletions setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,28 @@ func TestStoreSuite(t *testing.T) {

type StoreSuite struct {
suite.Suite
node *node.WakuNode
nodes []*node.WakuNode
}

func (s *StoreSuite) SetupSuite() {
wakuNode, err := node.New(
node.WithNTP(),
node.WithWakuRelayAndMinPeers(1),
)
for i := 0; i < 5; i++ {
wakuNode, err := node.New(
node.WithNTP(),
node.WithWakuRelayAndMinPeers(1),
)

s.NoError(err)
s.NoError(err)

err = wakuNode.Start(context.Background())
s.NoError(err)
err = wakuNode.Start(context.Background())
s.NoError(err)

s.node = wakuNode
s.nodes = append(s.nodes, wakuNode)
}
}

func (s *StoreSuite) TearDownSuite() {
s.node.Stop()
for _, x := range s.nodes {
x.Stop()
}

}