chore: create multiple nodes
This commit is contained in:
parent
d86d0d6cd7
commit
7c67be206e
42
main_test.go
42
main_test.go
|
@ -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)
|
||||
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)
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue