(t *testing.T)
| 667 | } |
| 668 | |
| 669 | func 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 | } |
nothing calls this directly
no test coverage detected