Skip to content

Commit

Permalink
Merge branch 'GH-5471-test-only' into GH-5471-leak-1
Browse files Browse the repository at this point in the history
  • Loading branch information
levb committed Jun 20, 2024
2 parents 90dde67 + d1ed540 commit d4205d4
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions server/mqtt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import (
"reflect"
"runtime"
"runtime/pprof"
"strconv"
"strings"
"sync"
"testing"
Expand Down Expand Up @@ -3070,7 +3069,7 @@ func captureHeapProfile(filename string) {
func printHeapUsage(label string) runtime.MemStats {
var memStats runtime.MemStats
runtime.ReadMemStats(&memStats)
fmt.Printf("%s Heap: allocs=%v, objects=%v\n", label, memStats.HeapAlloc, memStats.HeapObjects)
fmt.Printf("%s Heap: inuse=%v, objects=%v\n", label, memStats.HeapInuse, memStats.HeapObjects)
return memStats
}
func TestMQTTClusterConnectDisconnectClean(t *testing.T) {
Expand Down Expand Up @@ -3100,20 +3099,21 @@ func TestMQTTClusterConnectSubDisconnectClean(t *testing.T) {
runtime.GC() // Force garbage collection to get a clear picture

memStats := printHeapUsage("BEFORE")
baseHeapAlloc := memStats.HeapAlloc
baseHeapInuse := memStats.HeapInuse
baseHeapObjects := memStats.HeapObjects

for i := 0; i < 10; i++ {
N := 1000000
for i := 0; i < N; i++ {
clientID := nuid.Next()
testMQTTConnectSubDisconnect(t, cl.opts[0], clientID, true, false, true, 2)
runtime.GC() // Force garbage collection to get a clear picture

memStats = printHeapUsage(fmt.Sprintf("AFTER %d", i))
if memStats.HeapAlloc > 2*baseHeapAlloc || memStats.HeapObjects > 2*baseHeapObjects {
if memStats.HeapInuse > 100*baseHeapInuse || memStats.HeapObjects > 100*baseHeapObjects {
captureHeapProfile("AFTERLEAK.pprof")
t.Fatalf("after %d iterations heap alloc has grown from %v to %v (%v%%), objects from %v to %v (%v%%)",
i,
sizeKB(baseHeapAlloc), sizeKB(memStats.HeapAlloc), memStats.HeapAlloc*100/baseHeapAlloc,
baseHeapInuse, memStats.HeapInuse, memStats.HeapInuse*100/baseHeapInuse,
baseHeapObjects, memStats.HeapObjects, memStats.HeapObjects*100/baseHeapObjects)
}
}
Expand Down

0 comments on commit d4205d4

Please sign in to comment.