chore: create multiple nodes

This commit is contained in:
Richard Ramos 2023-07-14 12:54:58 -04:00
parent d86d0d6cd7
commit 7c67be206e
No known key found for this signature in database
GPG Key ID: 1CE87DB518195760
2 changed files with 39 additions and 28 deletions

View File

@ -6,26 +6,22 @@ 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
@ -33,33 +29,43 @@ func (s *StoreSuite) TestBasic() {
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)
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)

View File

@ -17,10 +17,11 @@ func TestStoreSuite(t *testing.T) {
type StoreSuite struct {
suite.Suite
node *node.WakuNode
nodes []*node.WakuNode
}
func (s *StoreSuite) SetupSuite() {
for i := 0; i < 5; i++ {
wakuNode, err := node.New(
node.WithNTP(),
node.WithWakuRelayAndMinPeers(1),
@ -31,9 +32,13 @@ func (s *StoreSuite) SetupSuite() {
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()
}
}