(t *testing.T)
| 557 | } |
| 558 | |
| 559 | func TestMemoryLeaks_IdentifierPool(t *testing.T) { |
| 560 | runtime.GC() |
| 561 | runtime.GC() |
| 562 | time.Sleep(10 * time.Millisecond) |
| 563 | |
| 564 | var m1 runtime.MemStats |
| 565 | runtime.ReadMemStats(&m1) |
| 566 | |
| 567 | const iterations = 10000 |
| 568 | |
| 569 | t.Logf("Running %d iterations of Identifier pool operations...", iterations) |
| 570 | |
| 571 | for i := 0; i < iterations; i++ { |
| 572 | ident := GetIdentifier() |
| 573 | ident.Name = "test_column" |
| 574 | PutIdentifier(ident) |
| 575 | |
| 576 | if i%1000 == 0 && i > 0 { |
| 577 | runtime.GC() |
| 578 | } |
| 579 | } |
| 580 | |
| 581 | runtime.GC() |
| 582 | runtime.GC() |
| 583 | time.Sleep(10 * time.Millisecond) |
| 584 | |
| 585 | var m2 runtime.MemStats |
| 586 | runtime.ReadMemStats(&m2) |
| 587 | |
| 588 | allocDiff := int64(m2.Alloc) - int64(m1.Alloc) |
| 589 | totalAllocDiff := int64(m2.TotalAlloc) - int64(m1.TotalAlloc) |
| 590 | bytesPerOp := float64(totalAllocDiff) / float64(iterations) |
| 591 | |
| 592 | t.Logf("Identifier pool memory stats:") |
| 593 | t.Logf(" Alloc diff: %d bytes", allocDiff) |
| 594 | t.Logf(" TotalAlloc diff: %d bytes", totalAllocDiff) |
| 595 | t.Logf(" Bytes per operation: %.2f", bytesPerOp) |
| 596 | |
| 597 | const maxAllocIncrease = 512 * 1024 // 512KB |
| 598 | const maxBytesPerOp = 3000 // 3KB |
| 599 | |
| 600 | if allocDiff > maxAllocIncrease { |
| 601 | t.Errorf("Memory leak in Identifier pool: %d bytes (threshold: %d)", allocDiff, maxAllocIncrease) |
| 602 | } |
| 603 | |
| 604 | if bytesPerOp > maxBytesPerOp { |
| 605 | t.Errorf("High memory usage in Identifier pool: %.2f bytes/op (threshold: %d)", bytesPerOp, maxBytesPerOp) |
| 606 | } |
| 607 | |
| 608 | if allocDiff <= maxAllocIncrease && bytesPerOp <= maxBytesPerOp { |
| 609 | t.Logf("✅ Identifier pool memory leak test PASSED") |
| 610 | } |
| 611 | } |
| 612 | |
| 613 | func TestMemoryLeaks_BinaryExpressionPool(t *testing.T) { |
| 614 | runtime.GC() |
nothing calls this directly
no test coverage detected