mirror of
https://github.com/logos-messaging/logos-messaging-go-bindings.git
synced 2026-01-04 06:53:11 +00:00
75 lines
2.1 KiB
Go
75 lines
2.1 KiB
Go
|
|
package waku
|
||
|
|
|
||
|
|
import (
|
||
|
|
"fmt"
|
||
|
|
"runtime"
|
||
|
|
"testing"
|
||
|
|
"time"
|
||
|
|
|
||
|
|
"github.com/stretchr/testify/require"
|
||
|
|
"github.com/waku-org/waku-go-bindings/waku/common"
|
||
|
|
"google.golang.org/protobuf/proto"
|
||
|
|
)
|
||
|
|
|
||
|
|
func TestStoreQuery5kMessagesWithPagination(t *testing.T) {
|
||
|
|
Debug("Starting test")
|
||
|
|
|
||
|
|
nodeConfig := DefaultWakuConfig
|
||
|
|
nodeConfig.Relay = true
|
||
|
|
nodeConfig.Store = true
|
||
|
|
|
||
|
|
Debug("Creating 2 nodes")
|
||
|
|
wakuNode, err := StartWakuNode("node1", &nodeConfig)
|
||
|
|
require.NoError(t, err, "Failed to start Waku node")
|
||
|
|
|
||
|
|
node2, err := StartWakuNode("node2", &nodeConfig)
|
||
|
|
require.NoError(t, err, "Failed to start Waku node")
|
||
|
|
node2.ConnectPeer(wakuNode)
|
||
|
|
|
||
|
|
defer func() {
|
||
|
|
Debug("Stopping and destroying Waku node")
|
||
|
|
wakuNode.StopAndDestroy()
|
||
|
|
node2.StopAndDestroy()
|
||
|
|
}()
|
||
|
|
|
||
|
|
var memStats runtime.MemStats
|
||
|
|
iterations := 50
|
||
|
|
|
||
|
|
runtime.ReadMemStats(&memStats)
|
||
|
|
initialHeapAlloc := memStats.HeapAlloc
|
||
|
|
Debug("Initial memory usage check before publishing %d MB", initialHeapAlloc/1024/1024)
|
||
|
|
|
||
|
|
queryTimestamp := proto.Int64(time.Now().UnixNano())
|
||
|
|
|
||
|
|
for i := 0; i < iterations; i++ {
|
||
|
|
message := wakuNode.CreateMessage()
|
||
|
|
message.Payload = []byte(fmt.Sprintf("Test endurance message payload %d", i))
|
||
|
|
_, err := wakuNode.RelayPublishNoCTX(DefaultPubsubTopic, message)
|
||
|
|
require.NoError(t, err, "Failed to publish message")
|
||
|
|
|
||
|
|
if i%10 == 0 {
|
||
|
|
runtime.ReadMemStats(&memStats)
|
||
|
|
Debug("Memory usage at iteration %d: HeapAlloc=%v MB, NumGC=%v",
|
||
|
|
i, memStats.HeapAlloc/1024/1024, memStats.NumGC)
|
||
|
|
|
||
|
|
storeQueryRequest := &common.StoreQueryRequest{
|
||
|
|
TimeStart: queryTimestamp,
|
||
|
|
IncludeData: true,
|
||
|
|
PaginationLimit: proto.Uint64(50),
|
||
|
|
}
|
||
|
|
|
||
|
|
storedmsgs, err := wakuNode.GetStoredMessages(node2, storeQueryRequest)
|
||
|
|
require.NoError(t, err, "Failed to query store messages")
|
||
|
|
require.Greater(t, len(*storedmsgs.Messages), 0, "Expected at least one stored message")
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
runtime.ReadMemStats(&memStats)
|
||
|
|
finalHeapAlloc := memStats.HeapAlloc
|
||
|
|
Debug("Memory before test: %v KB, Memory after test: %v KB", initialHeapAlloc/1024, finalHeapAlloc/1024)
|
||
|
|
|
||
|
|
require.LessOrEqual(t, finalHeapAlloc, initialHeapAlloc*2, "Memory usage has grown too much")
|
||
|
|
|
||
|
|
Debug("Test completed successfully")
|
||
|
|
}
|