MCPcopy Create free account
hub / github.com/ajitpratap0/GoSQLX / TestMemoryLeaks_LiteralValuePool

Function TestMemoryLeaks_LiteralValuePool

pkg/sql/ast/pool_test.go:669–722  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

667}
668
669func TestMemoryLeaks_LiteralValuePool(t *testing.T) {
670 runtime.GC()
671 runtime.GC()
672 time.Sleep(10 * time.Millisecond)
673
674 var m1 runtime.MemStats
675 runtime.ReadMemStats(&m1)
676
677 const iterations = 10000
678
679 t.Logf("Running %d iterations of LiteralValue pool operations...", iterations)
680
681 for i := 0; i < iterations; i++ {
682 lit := GetLiteralValue()
683 lit.Value = "test_value"
684 lit.Type = "STRING"
685 PutLiteralValue(lit)
686
687 if i%1000 == 0 && i > 0 {
688 runtime.GC()
689 }
690 }
691
692 runtime.GC()
693 runtime.GC()
694 time.Sleep(10 * time.Millisecond)
695
696 var m2 runtime.MemStats
697 runtime.ReadMemStats(&m2)
698
699 allocDiff := int64(m2.Alloc) - int64(m1.Alloc)
700 totalAllocDiff := int64(m2.TotalAlloc) - int64(m1.TotalAlloc)
701 bytesPerOp := float64(totalAllocDiff) / float64(iterations)
702
703 t.Logf("LiteralValue pool memory stats:")
704 t.Logf(" Alloc diff: %d bytes", allocDiff)
705 t.Logf(" TotalAlloc diff: %d bytes", totalAllocDiff)
706 t.Logf(" Bytes per operation: %.2f", bytesPerOp)
707
708 const maxAllocIncrease = 512 * 1024 // 512KB
709 const maxBytesPerOp = 3000 // 3KB
710
711 if allocDiff > maxAllocIncrease {
712 t.Errorf("Memory leak in LiteralValue pool: %d bytes (threshold: %d)", allocDiff, maxAllocIncrease)
713 }
714
715 if bytesPerOp > maxBytesPerOp {
716 t.Errorf("High memory usage in LiteralValue pool: %.2f bytes/op (threshold: %d)", bytesPerOp, maxBytesPerOp)
717 }
718
719 if allocDiff <= maxAllocIncrease && bytesPerOp <= maxBytesPerOp {
720 t.Logf("✅ LiteralValue pool memory leak test PASSED")
721 }
722}

Callers

nothing calls this directly

Calls 3

GetLiteralValueFunction · 0.85
PutLiteralValueFunction · 0.85
ErrorfMethod · 0.65

Tested by

no test coverage detected