(t *testing.T)
| 496 | } |
| 497 | |
| 498 | func TestMemoryLeaks_DeleteStatementPool(t *testing.T) { |
| 499 | runtime.GC() |
| 500 | runtime.GC() |
| 501 | time.Sleep(10 * time.Millisecond) |
| 502 | |
| 503 | var m1 runtime.MemStats |
| 504 | runtime.ReadMemStats(&m1) |
| 505 | |
| 506 | const iterations = 10000 |
| 507 | |
| 508 | t.Logf("Running %d iterations of DeleteStatement pool operations...", iterations) |
| 509 | |
| 510 | for i := 0; i < iterations; i++ { |
| 511 | stmt := GetDeleteStatement() |
| 512 | |
| 513 | stmt.TableName = "users" |
| 514 | stmt.Where = &BinaryExpression{ |
| 515 | Left: &Identifier{Name: "id"}, |
| 516 | Operator: "=", |
| 517 | Right: &LiteralValue{Value: "999"}, |
| 518 | } |
| 519 | |
| 520 | PutDeleteStatement(stmt) |
| 521 | |
| 522 | if i%1000 == 0 && i > 0 { |
| 523 | runtime.GC() |
| 524 | } |
| 525 | } |
| 526 | |
| 527 | runtime.GC() |
| 528 | runtime.GC() |
| 529 | time.Sleep(10 * time.Millisecond) |
| 530 | |
| 531 | var m2 runtime.MemStats |
| 532 | runtime.ReadMemStats(&m2) |
| 533 | |
| 534 | allocDiff := int64(m2.Alloc) - int64(m1.Alloc) |
| 535 | totalAllocDiff := int64(m2.TotalAlloc) - int64(m1.TotalAlloc) |
| 536 | bytesPerOp := float64(totalAllocDiff) / float64(iterations) |
| 537 | |
| 538 | t.Logf("DeleteStatement pool memory stats:") |
| 539 | t.Logf(" Alloc diff: %d bytes", allocDiff) |
| 540 | t.Logf(" TotalAlloc diff: %d bytes", totalAllocDiff) |
| 541 | t.Logf(" Bytes per operation: %.2f", bytesPerOp) |
| 542 | |
| 543 | const maxAllocIncrease = 1024 * 1024 // 1MB |
| 544 | const maxBytesPerOp = 5000 // 5KB |
| 545 | |
| 546 | if allocDiff > maxAllocIncrease { |
| 547 | t.Errorf("Memory leak in DeleteStatement pool: %d bytes (threshold: %d)", allocDiff, maxAllocIncrease) |
| 548 | } |
| 549 | |
| 550 | if bytesPerOp > maxBytesPerOp { |
| 551 | t.Errorf("High memory usage in DeleteStatement pool: %.2f bytes/op (threshold: %d)", bytesPerOp, maxBytesPerOp) |
| 552 | } |
| 553 | |
| 554 | if allocDiff <= maxAllocIncrease && bytesPerOp <= maxBytesPerOp { |
| 555 | t.Logf("✅ DeleteStatement pool memory leak test PASSED") |
nothing calls this directly
no test coverage detected