Add basic monitor test

This commit is contained in:
aya 2025-03-05 14:01:01 +02:00
parent c8e6f194e3
commit df19e2013c

View File

@ -2,6 +2,8 @@ package waku
import (
"fmt"
"log"
"os"
"runtime"
"testing"
"time"
@ -11,6 +13,64 @@ import (
"google.golang.org/protobuf/proto"
)
func TestMemoryUsageForThreeNodes(t *testing.T) {
logFile, err := os.OpenFile("test_logs.log", os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0666)
require.NoError(t, err, "Failed to open log file")
multiWriter := log.MultiWriter(os.Stdout, logFile)
log.SetOutput(multiWriter)
Debug("Starting memory usage test for three Waku nodes")
var memStats runtime.MemStats
runtime.ReadMemStats(&memStats)
initialHeapAlloc := memStats.HeapAlloc
Debug("Initial memory usage before creating nodes: %d MB", initialHeapAlloc/1024/1024)
node1, err := NewWakuNode(&DefaultWakuConfig, "node1")
require.NoError(t, err, "Failed to create Node1")
node2, err := NewWakuNode(&DefaultWakuConfig, "node2")
require.NoError(t, err, "Failed to create Node2")
node3, err := NewWakuNode(&DefaultWakuConfig, "node3")
require.NoError(t, err, "Failed to create Node3")
runtime.ReadMemStats(&memStats)
afterCreationHeapAlloc := memStats.HeapAlloc
Debug("Memory usage after creating nodes: %d MB", afterCreationHeapAlloc/1024/1024)
err = node1.Start()
require.NoError(t, err, "Failed to start Node1")
err = node2.Start()
require.NoError(t, err, "Failed to start Node2")
err = node3.Start()
require.NoError(t, err, "Failed to start Node3")
runtime.ReadMemStats(&memStats)
afterStartHeapAlloc := memStats.HeapAlloc
Debug("Memory usage after starting nodes: %d MB", afterStartHeapAlloc/1024/1024)
time.Sleep(2 * time.Second)
node1.Stop()
node2.Stop()
node3.Stop()
runtime.ReadMemStats(&memStats)
afterStopHeapAlloc := memStats.HeapAlloc
Debug("Memory usage after stopping nodes: %d MB", afterStopHeapAlloc/1024/1024)
require.LessOrEqual(t, afterStartHeapAlloc, initialHeapAlloc*3, "Unexpected memory growth after starting nodes")
Debug("Test completed successfully")
logFile.Close()
}
func TestStoreQuery5kMessagesWithPagination(t *testing.T) {
Debug("Starting test")