Skip to content

[Feature] Peformance Testing#3971

Open
iancooper wants to merge 8 commits intomasterfrom
performance_testing
Open

[Feature] Peformance Testing#3971
iancooper wants to merge 8 commits intomasterfrom
performance_testing

Conversation

@iancooper
Copy link
Copy Markdown
Member

We have reports of memory leaks, issues with DbContext, etc. So we need some tests that we can run, either when work completes on a PR, or on an intermittent basis (such as pre-release).

This work uses our samples as the application to run and check for leaks.

It uses in-memory Sqlite and RMQ for test reliability.

codescene-delta-analysis[bot]

This comment was marked as outdated.

@claude
Copy link
Copy Markdown

claude Bot commented Jan 12, 2026

PR Review: Performance Testing Specification - This is an excellent specification. Recommendation: Approve with minor suggestions. Key Issues (all minor): 1) Missing MIT license headers (documentation.md:63-98) - Add checklist items to Phase 1 for all new source files. 2) Missing XML documentation (documentation.md:1-47) - Add task for XML docs on public members. 3) Test timeout clarity - Document 60-min timeout rationale. 4) Missing Arrange/Act/Assert reminder (testing.md:32). 5) README.md:62 references troubleshooting.md before it exists. Strengths: Excellent planning with 4-phase approach, follows xUnit and BDD naming, uses developer test philosophy correctly (in-memory SQLite, real RabbitMQ, WebApplicationFactory), smart CI/CD integration. Security: No concerns. Performance: Well managed. Test Coverage: Excellent. Conclusion: Excellent specification with thorough planning. All issues are minor. Core design is sound. Action: Approve and proceed with implementation. Reviewed by Claude Sonnet 4.5, 2026-01-12

@claude
Copy link
Copy Markdown

claude Bot commented Jan 12, 2026

Detailed Review - Part 1: Alignment with Brighter Conventions

Testing Philosophy

The spec correctly implements the developer test philosophy from testing.md:55-69:

  • Uses in-memory SQLite instead of mocking DbContext
  • Uses real RabbitMQ service instead of mocking message broker
  • Uses WebApplicationFactory instead of mocking ASP.NET pipeline

This is excellent - you avoid test isolation via mocks and instead test real behavior.

Test Naming

Follows the required When_condition_should_behavior format from testing.md:5. Examples look good:

  • When_processing_commands_handlers_should_be_disposed
  • When_api_runs_under_sustained_load_memory_remains_stable

Test Structure

Should add explicit mention of Arrange/Act/Assert comments required by testing.md:32. Add this to Phase 1 checklist items.

@claude
Copy link
Copy Markdown

claude Bot commented Jan 12, 2026

Detailed Review - Part 2: Required Additions

1. MIT License Headers (Required)

Per documentation.md:63-98, every source file needs an MIT license header at the top, before using statements, in a region block.

Add checklist items to Phase 1 for:

  • Task 1.3: Add license to MemoryLeakTestBase.cs
  • Task 1.4: Add license to WebApiTestServer.cs
  • Task 1.5: Add license to LoadGenerator.cs
  • Task 1.6: Add license to ApiHandlerLifecycleTests.cs
  • Task 1.7: Add license to DbContextLifecycleTests.cs
  • And all subsequent test files in later phases

2. XML Documentation (Required)

Per documentation.md:1-47, all public members need XML documentation comments.

Add a task to Phase 1 or Phase 4:

  • Document MemoryLeakTestBase protected methods (AssertNoLeakedHandlers, AssertDbContextsDisposed, AssertMemoryGrowthWithinBounds)
  • Document WebApiTestServer public methods (SendGreetingAsync, CreatePersonAsync)
  • Document LoadGenerator class and LoadTestResult properties

These docs show up in IntelliSense and help future contributors understand the testing infrastructure.

@claude
Copy link
Copy Markdown

claude Bot commented Jan 12, 2026

Detailed Review - Part 3: Other Recommendations

Test Timeout Rationale

Soak tests specify 60-minute timeouts for 30-minute tests (plan.md lines 207, 224, 237). This is reasonable (30 min buffer for GC/cleanup) but should be documented. Suggest adding a comment explaining the 2x multiplier.

README.md Reference Issue

Line 62 in specs/002-performance-testing/README.md references troubleshooting.md, but per plan.md Phase 4.5, this file is not created until Phase 4. Recommend updating README.md to say "(coming in Phase 4)" to avoid confusion.

Memory Thresholds

The specified thresholds appear reasonable:

  • Quick tests: 0 leaked handlers/contexts (strict), <5-10MB growth
  • Soak tests: <50MB total growth, <1KB per request average

These will need tuning based on real CI data (correctly noted in Phase 2.7 and Phase 4.1).

Evident Data Pattern

Consider explicitly mentioning the Evident Data pattern (testing.md:35-37) when setting up test data. This helps highlight what state impacts test outcomes.

@claude
Copy link
Copy Markdown

claude Bot commented Jan 12, 2026

Detailed Review - Part 4: Strengths Summary

Excellent Planning

  • 4-phase progressive implementation minimizes risk
  • Clear deliverables and verification criteria for each phase
  • Realistic timelines and scope management
  • Good use of .currenttask file for progress tracking

Smart Architecture Decisions

  • Two-tier testing strategy (quick + soak) is pragmatic
  • JetBrains dotMemory Unit is the right tool (graceful degradation without license)
  • WebApplicationFactory for in-process testing is efficient
  • Using real WebAPI samples provides realistic test scenarios

Strong CI/CD Integration

  • Quick tests run in parallel with existing test jobs (minimal PR delay)
  • Soak tests only run nightly (not blocking development)
  • Artifact retention strategy is appropriate (7 days quick, 30 days soak)
  • Proper timeout configurations prevent CI hangs

Test Coverage

Comprehensive coverage of the most critical leak scenarios that have been reported in production. The scope is well-defined with clear boundaries for future enhancements.

Overall, this is excellent work that will provide significant value to the project!

codescene-delta-analysis[bot]

This comment was marked as outdated.

@claude
Copy link
Copy Markdown

claude Bot commented Jan 12, 2026

PR Review: Performance Testing Specification

I've reviewed PR #3971 - this is a planning/specification PR with no implementation code yet.

Overall: ✅ APPROVE - Excellent Specification

Exceptionally well-planned with thorough understanding of requirements and project conventions.

Key Strengths

1. Excellent Alignment with Brighter Philosophy

  • Uses in-memory SQLite, real RabbitMQ, WebApplicationFactory (not mocks)
  • Tests real behavior per developer test philosophy

2. Smart Two-Tier Strategy

  • Quick tests (5-10 min) on PRs for fast feedback
  • Soak tests (30-60 min) nightly for gradual leaks
  • Balances detection with CI efficiency

3. Comprehensive Planning

  • 4 phases with clear goals and verification
  • Realistic scope with .currenttask tracking
  • Incremental implementation

4. Strong CI/CD Integration

  • Quick tests parallel with existing tests
  • Soak tests on schedule only
  • Proper timeouts and artifact retention

5. Excellent Test Coverage

  • Targets critical scenarios: handlers, DbContexts, connections, consumers
  • Uses realistic WebAPI samples
  • Clear measurable thresholds

Required Changes (During Implementation)

1. MIT License Headers (Required)
Per documentation.md:63-98, add license headers to all new source files. Add checklist items for Phases 1-4.

2. XML Documentation (Required)
Per documentation.md:1-47, document all public/protected members. Add task for MemoryLeakTestBase, WebApiTestServer, LoadGenerator.

3. Arrange/Act/Assert Comments (Recommended)
Per testing.md:32, add explicit comments in tests. Add to Phase 1.6+ checklist.

Recommendations

  1. Document 60-min timeout rationale for 30-min soak tests
  2. Update README.md line 62: add "(coming in Phase 4)" for troubleshooting.md
  3. Verify package versions when starting implementation

Reviews

Security: ✅ No concerns
Performance: ✅ Well-managed impact
Test Coverage: ✅ Excellent critical scenario coverage
Code Quality: ✅ Strong architecture, follows conventions

Minor Issues

  1. Verify CI always has dotMemory Unit (Phase 1.8)
  2. Threshold tuning may need iterations (Phases 2.7, 4.1 handle this)
  3. Potential flakiness mitigated by multiple GC passes and warmup

Recommendation: ✅ APPROVE

Next Steps:

  1. Add checklist for MIT license headers
  2. Add task for XML documentation
  3. Add Arrange/Act/Assert reminder
  4. Proceed with Phase 1

Reviewed by Claude Sonnet 4.5 on 2026-01-12

…s.props; required to build with warnings becoming errors.
codescene-delta-analysis[bot]

This comment was marked as outdated.

@claude
Copy link
Copy Markdown

claude Bot commented Jan 13, 2026

PR Review: Performance Testing - Memory Leak Detection

SUMMARY
This PR introduces comprehensive memory leak testing infrastructure for Brighter. Overall, this is a high-quality contribution that addresses an important operational concern.

STRENGTHS

  • Architecture: Well-organized structure with clear separation, follows RDD principles, good abstractions
  • Code Quality: Follows C# conventions, proper test naming, XML documentation, correct Dispose pattern
  • Testing Strategy: Two-tier approach (quick/soak), realistic thresholds, graceful degradation

CRITICAL ISSUES - Must Fix Before Merge

  1. Target Framework Mismatch (Paramore.Brighter.MemoryLeak.Tests.csproj:4)
    Project only targets net9.0, should use BrighterTestTargetFrameworks variable
    Change: TargetFramework to TargetFrameworks with the BrighterTestTargetFrameworks variable
    Impact: Tests will not run on .NET 8.0 and 10.0

  2. Missing Nullable Enablement (Paramore.Brighter.MemoryLeak.Tests.csproj)
    Per code style guide, add Nullable enable to project file
    Impact: Missing null safety checks

HIGH PRIORITY ISSUES - Should Fix Soon

  1. AWS Package Version Constraint Removal (Directory.Packages.props:15-22)
    Removed upper-bound version constraints that prevent AWS SDK v4 breaking changes
    Concern: If AWS SDK v4 is released, packages may auto-update and break compatibility
    Recommendation: Keep upper bound constraint or document v4 compatibility decision

  2. Outbox Configuration Comment (WebApiTestServer.cs:44-47)
    Comment about avoiding outbox sweeper issues is vague and suggests workaround
    Clarify if temporary (Phase 1 only) or permanent
    Consider testing with outbox enabled in Phase 2/3

MEDIUM PRIORITY ISSUES

  1. Magic Numbers - Extract hardcoded values (900, 450, 10MB) to named constants
  2. Potential Race Condition (MemoryLeakTestBase.cs:82-91) - Loop does not await async operations
  3. Docker Compose Version Field (docker-compose.yml:16) - Deprecated in v2+

LOW PRIORITY ISSUES

  1. Console Output - Consider using ITestOutputHelper instead of Console.WriteLine
  2. XML Documentation - Verify all LoadGenerator public methods have proper docs

SECURITY & PERFORMANCE
No security concerns. Performance testing approach is sound with appropriate timing.

TEST COVERAGE
Covered: Handler lifecycle, DbContext lifecycle, memory growth, concurrent handling
Future Work: Consumer handlers, outbox sweeper, producer connections (acceptable for Phase 1)

DOCUMENTATION
Excellent documentation with comprehensive README, clear specs, and detailed implementation plan.

VERDICT
This is a valuable addition that will help catch memory leaks early. Code quality is high, architecture is sound, documentation is thorough.

With the critical issues fixed (target frameworks and nullable), this PR is ready to merge.

Great work!

codescene-delta-analysis[bot]

This comment was marked as outdated.

@claude
Copy link
Copy Markdown

claude Bot commented Jan 14, 2026

Pull Request Review: Performance Testing Infrastructure (PR #3971)

Overall Assessment

Recommendation: Approve with minor suggestions

This PR implements a well-designed memory leak testing infrastructure for Brighter. The implementation follows best practices and aligns well with the repository's conventions. The work represents Phase 1 of a 4-phase plan to add comprehensive memory leak detection to the CI/CD pipeline.


Strengths

1. Excellent Architecture & Design

  • Two-tier testing strategy is well thought out (quick tests for PRs, soak tests for nightly runs)
  • Uses WebApplicationFactory for in-process testing - fast and deterministic
  • JetBrains dotMemory Unit integration is appropriate for memory profiling
  • Graceful degradation with FailIfRunWithoutSupport = false ensures tests work even without dotMemory

2. Follows Brighter Testing Philosophy

The implementation correctly follows the "developer tests" philosophy from docs/agent_instructions/testing.md:

  • ✅ Uses in-memory SQLite instead of mocking DbContext
  • ✅ Uses real RabbitMQ instead of mocking the message broker
  • ✅ Uses WebApplicationFactory instead of mocking ASP.NET pipeline
  • ✅ Tests actual behavior, not isolated units with mocks

3. Good Code Quality

  • Clean, well-structured test infrastructure classes
  • Appropriate use of GC.Collect() patterns for reliable memory measurements
  • Helpful base class (MemoryLeakTestBase) that will be reusable across future tests
  • Good separation of concerns (LoadGenerator, WebApiTestServer, test base)

4. Comprehensive Documentation

  • Excellent ADR (0036) documenting the decision rationale
  • Detailed implementation plan with clear phases
  • README with quick start guide
  • Clear memory thresholds documented

5. Test Naming & Structure

  • ✅ Follows required When_[condition]_should_[expected_behavior] format
  • ✅ Uses xUnit traits for filtering: [Trait("Category", "MemoryLeak")] and [Trait("Speed", "Quick")]
  • ✅ One test per file for clarity (except where shared setup justifies multiple tests)

Issues Found

Critical: None ✅

High Priority: None ✅

Medium Priority

1. Missing MIT License Headers

Location: All new source files in tests/Paramore.Brighter.MemoryLeak.Tests/

Issue: Per docs/agent_instructions/documentation.md:63-98, all source files require MIT license headers at the top, before using statements, in a region block.

Files missing headers:

  • Infrastructure/MemoryLeakTestBase.cs
  • Infrastructure/WebApiTestServer.cs
  • Infrastructure/LoadGenerator.cs
  • Infrastructure/AssemblyInfo.cs
  • Quick/ApiHandlerLifecycleTests.cs
  • Quick/DbContextLifecycleTests.cs

Recommendation: Add the standard MIT license header to all new source files. Example format:

#region Licence
/* The MIT License (MIT)
Copyright © 2024 Ian Cooper <ian_hammond_cooper@yahoo.co.uk>
...
*/
#endregion

2. Missing XML Documentation

Location: Public members in infrastructure classes

Issue: Per docs/agent_instructions/documentation.md:1-47, all public members should have XML documentation comments.

Missing documentation:

  • MemoryLeakTestBase protected methods already have XML docs ✅
  • WebApiTestServer public methods already have XML docs ✅
  • LoadGenerator class and methods already have XML docs ✅
  • LoadTestResult properties already have XML docs ✅

Status: Actually, upon review, the XML documentation is already present and well-written! ✅

Low Priority

3. Test Structure - Missing Arrange/Act/Assert Comments

Location: Test methods in ApiHandlerLifecycleTests.cs and DbContextLifecycleTests.cs

Issue: Per docs/agent_instructions/testing.md:32, tests should use explicit //Arrange //Act //Assert comments.

Current: Tests have implicit structure with comments like "// Arrange" and "// Act" but not consistently formatted.

Recommendation: Ensure all test methods have the standard three comments:

// Arrange
// Act  
// Assert

4. Typo in WebApiTestServer.cs:15

Location: tests/Paramore.Brighter.MemoryLeak.Tests/Infrastructure/WebApiTestServer.cs:15

Issue: Comment says "I uses" instead of "It uses"

Fix:

// Current: I uses WebApplicationFactory to start the API
// Should be: It uses WebApplicationFactory to start the API

5. Constant Name Convention

Location: WebApiTestServer.cs:20

Issue: Per docs/agent_instructions/code_style.md:10, constants should use ALL_CAPS with underscores.

Current:

private const string ENVIRONMENT_NAME = "ASPNETCORE_ENVIRONMENT";

Status: Actually correct! The constant already follows the ALL_CAPS convention. ✅

6. Package Version Consistency

Location: Directory.Packages.props

Issue: PR changes AWS SDK versions from version ranges to fixed versions:

  • Changed from: [3.7.500.5, 4) (version range)
  • Changed to: 3.7.509.19 (fixed version)

Concern: This affects multiple AWS packages beyond just the memory leak tests. Was this intentional or should it be in a separate PR?

Recommendation: Clarify if the AWS SDK version changes are:

  1. Required for the memory leak tests to work
  2. A general dependency update that should be separate
  3. A deliberate change from version ranges to fixed versions

7. xUnit Version Change

Location: Directory.Packages.props

Issue: Changed from xunit 2.9.3 to xunit.v3.mtp-v2 3.2.1

Concern: This upgrades the entire test suite to xUnit v3, which affects all 265 changed test files. This seems like a separate change from adding memory leak tests.

Recommendation: Consider whether the xUnit v3 upgrade should be:

  1. In a separate PR to isolate the change
  2. Documented in the PR description as a deliberate upgrade
  3. Verified that all existing tests still work with v3

Security Concerns

Status: None identified

  • No sensitive data in test code
  • No security vulnerabilities introduced
  • RabbitMQ connection uses localhost in tests (appropriate)
  • SQLite in-memory database is appropriate for tests

Performance Considerations

Positive

  • ✅ In-memory SQLite is fast for tests
  • ✅ WebApplicationFactory avoids network overhead
  • ✅ Tests use reasonable concurrency (10 concurrent requests)
  • ✅ Warmup phase prevents false positives

Concerns

None - performance characteristics are appropriate for memory leak testing.


Test Coverage

Excellent

Phase 1 implements:

  • ✅ Handler lifecycle tests (1000 requests)
  • ✅ DbContext disposal tests (500 operations)
  • ✅ Memory growth bounds testing
  • ✅ Infrastructure for future tests

Phase 1 intentionally does NOT include:

  • ⏳ CommandProcessor tests (Phase 2)
  • ⏳ Message producer tests (Phase 2)
  • ⏳ Consumer tests (Phase 2)
  • ⏳ Soak tests (Phase 3)

This phased approach is sensible and well-documented.


Code Quality Issues

Potential Bug: Environment Variable Usage

Location: WebApiTestServer.cs:24

builder.UseEnvironment(ENVIRONMENT_NAME); // Uses "ASPNETCORE_ENVIRONMENT" as the environment name?

Issue: This sets the environment name to the literal string "ASPNETCORE_ENVIRONMENT" instead of reading the environment variable value.

Expected: Probably should be:

builder.UseEnvironment("Development"); // or "Test"

Recommendation: Verify this is intentional. It looks like it might be a bug where the constant name was used instead of the intended environment name.


Documentation Quality

Excellent

  • ✅ ADR-0036 is comprehensive and well-reasoned
  • ✅ Implementation plan (plan.md) is detailed with clear tasks
  • ✅ README provides good overview
  • ✅ Memory thresholds are documented
  • ✅ Code comments are clear and helpful

Minor Issues

  • README.md line 62 references ADR-0036 correctly ✅
  • Plan.md is thorough and well-structured ✅

Best Practices Compliance

Follows Brighter Conventions ✅

  • ✅ Nullable reference types enabled in project file
  • ✅ Proper disposal patterns with IDisposable
  • ✅ Expression-bodied members where appropriate (LoadTestResult properties)
  • ✅ Clear, expressive type names (not primitive obsessed)
  • ✅ Single responsibility principle
  • ✅ Methods are small and focused

Testing Best Practices ✅

  • ✅ Uses developer test philosophy (no mocking for isolation)
  • ✅ Tests behavior, not implementation details
  • ✅ Proper use of test doubles only for I/O (RabbitMQ, SQLite)
  • ✅ Clear Arrange/Act/Assert structure
  • ✅ Evident data pattern (highlighted test data)

Recommendations Summary

Must Fix Before Merge

  1. Add MIT license headers to all new source files

Should Fix

  1. Clarify AWS SDK version changes - Is this intentional or should it be separate?
  2. Document xUnit v3 upgrade - Verify all tests work and consider separating this change
  3. Fix environment variable usage in WebApiTestServer.cs:24 (possible bug)

Nice to Have

  1. Add explicit //Arrange //Act //Assert comments to all test methods
  2. Fix typo: "I uses" → "It uses" in WebApiTestServer.cs:15

Conclusion

This is excellent work that will significantly improve Brighter's quality and maintainability. The architecture is sound, the implementation is clean, and the phased approach is pragmatic.

The issues identified are all minor except for:

  1. Missing license headers (easy to add)
  2. Clarification needed on dependency changes
  3. Possible environment variable bug

Once these are addressed, this PR is ready to merge.

Estimated effort to address issues: 30-60 minutes


Additional Context

Phase 1 Completeness

According to the plan (plan.md), Phase 1 includes tasks 1.1-1.8. This PR appears to complete:

  • ✅ 1.1 Package Management Setup
  • ✅ 1.2 Create Test Project
  • ✅ 1.3 Infrastructure - Base Classes
  • ✅ 1.4 Infrastructure - WebAPI Test Server
  • ✅ 1.5 Infrastructure - Load Generator
  • ✅ 1.6 Quick Test - Handler Lifecycle
  • ✅ 1.7 Quick Test - DbContext Lifecycle
  • ⏳ 1.8 Phase 1 Verification (presumably tested locally)

Phase 1 goals are met.

Next Steps (Future PRs)

  • Phase 2: Additional quick tests + CI integration
  • Phase 3: Soak tests + nightly workflow
  • Phase 4: Threshold tuning + documentation

Reviewed by: Claude Sonnet 4.5
Review Date: 2026-01-14

Great work @iancooper! This is a solid foundation for memory leak testing. 🎉

codescene-delta-analysis[bot]

This comment was marked as outdated.

@claude
Copy link
Copy Markdown

claude Bot commented Jan 21, 2026

Pull Request Review: Performance Testing Infrastructure

Overall Assessment: This is a well-architected addition addressing critical memory leak detection needs. Excellent planning and code quality.

Key Strengths

  • Excellent architecture with clear separation of concerns
  • Well-documented ADR (0036) and phased implementation plan
  • Clean code with proper IDisposable usage and GC patterns
  • Pragmatic two-tier testing strategy (Quick + Soak)
  • Good use of WebApplicationFactory and dotMemory Unit

Critical Issues (Must Fix)

  1. Missing MIT License Headers - Several new files lack required license headers:

    • MemoryLeakTestBase.cs
    • WebApiTestServer.cs
    • LoadGenerator.cs
    • ApiHandlerLifecycleTests.cs
    • DbContextLifecycleTests.cs

    (See WebApiSmokeTest.cs for template)

Questions/Recommendations

  1. AWS SDK Version Changes - Directory.Packages.props changes from version ranges to pinned versions. Is this intentional? Please document rationale.

  2. Target Framework - Test project targets net9.0 only, but plan mentions using BrighterTestTargetFrameworks. Verify if multi-targeting needed or if single target is intentional.

  3. Minor: Remove unused Configuration folder reference from .csproj (lines 34-36)

Code Quality Assessment

  • Follows C# naming conventions ✓
  • Good XML documentation ✓
  • Proper test naming ✓
  • Excellent async/await usage ✓
  • No security concerns ✓
  • Good performance patterns ✓
  • Missing license headers (critical issue)

Test Coverage

Excellent Phase 1 coverage: handler lifecycle, DbContext disposal, memory bounds, smoke tests. Phases 2-3 appropriately deferred per plan.

Conclusion

Recommendation: Approve with required changes

High-quality implementation with strong engineering discipline. Add license headers before merge, clarify version pinning, and address minor items.

Excellent work - this systematic approach to memory leak testing will be very valuable!

Copy link
Copy Markdown

@codescene-delta-analysis codescene-delta-analysis Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No application code in the PR — skipped Code Health checks.

See analysis details in CodeScene

Quality Gate Profile: Clean Code Collective
Want more control? Customize Code Health rules or catch issues early with our IDE extension and CLI tool.

@claude
Copy link
Copy Markdown

claude Bot commented Jan 22, 2026

Pull Request Review: Performance Testing Infrastructure

Overview

This PR introduces memory leak testing infrastructure for Brighter, implementing Phase 1 of the plan outlined in ADR-0036. The implementation includes a new test project with JetBrains dotMemory Unit integration, test infrastructure, and initial quick tests for handler and DbContext lifecycle verification.

✅ Strengths

  1. Well-Structured Architecture

    • Clean separation of concerns with Infrastructure and Quick test directories
    • Good use of base classes (MemoryLeakTestBase) to provide reusable test helpers
    • WebApplicationFactory pattern is appropriate for in-process API testing
  2. Test Design Quality

    • Proper use of [Trait] attributes for test categorization (Category=MemoryLeak, Speed=Quick)
    • Good test naming following project conventions: When_..._should_...
    • Tests verify both memory leaks AND functional correctness (success counts)
    • Proper garbage collection patterns with multiple GC cycles
  3. Resource Management

    • Correct use of using statements for disposable resources in tests
    • Proper implementation of IDisposable on test infrastructure classes
    • GC.SuppressFinalize in WebApiTestServer.Dispose()
  4. Documentation

    • Excellent XML documentation on all public methods
    • Clear comments explaining test intent
    • Comprehensive README and plan.md files
    • WebApiSmokeTest includes helpful rationale comment
  5. Dependency Management

    • Proper use of Directory.Packages.props for centralized package management
    • AWS SDK version pinning is consistent across the board

⚠️ Issues & Concerns

Critical Issues

  1. Missing License Headers (Requirement Violation)

    • Per documentation.md, ALL source files must have MIT license headers at the top
    • Missing from:
      • Infrastructure/MemoryLeakTestBase.cs
      • Infrastructure/WebApiTestServer.cs
      • Infrastructure/LoadGenerator.cs
      • Quick/ApiHandlerLifecycleTests.cs
      • Quick/DbContextLifecycleTests.cs
    • Present in: Quick/WebApiSmokeTest.cs
    • All new files should include the license header in a #region License block
  2. AWS SDK Version Changes Lack Context

    • Directory.Packages.props changes AWS SDK versions from range-based ([3.7.500.5, 4)) to pinned versions (3.7.509.19)
    • Concern: This is a significant change affecting the entire codebase, not just performance tests
    • Missing: Explanation of why this change was necessary for memory leak testing
    • Recommendation: Either explain the rationale in the PR description or consider moving this to a separate PR

Code Quality Issues

  1. Inconsistent Async/Await Pattern

    • WebApiSmokeTest.cs:39 uses await using (correct for async disposal)
    • ApiHandlerLifecycleTests.cs:23 and DbContextLifecycleTests.cs:23 use using (sync disposal)
    • Issue: WebApiTestServer inherits from WebApplicationFactory which implements IAsyncDisposable
    • Recommendation: Use await using consistently across all test classes for proper async disposal
  2. Potential Race Condition in LoadGenerator

    • LoadGenerator.cs uses Interlocked.Increment correctly for thread safety
    • However, LoadTestResult exposes mutable internal fields directly
    • Recommendation: Make fields private and ensure all access goes through properties
  3. Test Thresholds May Be Too Lenient

    • ApiHandlerLifecycleTests:86 allows 10MB growth for 500 requests (20KB/request)
    • ApiHandlerLifecycleTests:43 accepts >900 success rate (allows 10% failures)
    • Concern: These thresholds might hide smaller leaks or reliability issues
    • Recommendation: Consider tightening after establishing baselines with real runs
  4. Missing Null Checks

    • MemoryLeakTestBase.AssertMemoryGrowthWithinBounds doesn't validate operation parameter
    • LoadGenerator constructor has null check (good) but could use ArgumentNullException.ThrowIfNull

Design Concerns

  1. WebApiTestServer Environment Configuration

    • Line 24: builder.UseEnvironment(ENVIRONMENT_NAME) where ENVIRONMENT_NAME = "ASPNETCORE_ENVIRONMENT"
    • This sets the environment name to literally "ASPNETCORE_ENVIRONMENT" instead of reading its value
    • Expected: Should probably be "Development", "Testing", or read from actual environment
    • Impact: May affect middleware, logging, and configuration loading
  2. Hardcoded Test Dependencies

    • Tests require RabbitMQ running on localhost:5672
    • No graceful handling if RabbitMQ is unavailable
    • Recommendation: Consider adding [Fact(Skip = "Requires RabbitMQ")] attribute or environment detection
  3. Incomplete Test Coverage for Phase 1

    • Per plan.md, Phase 1 should include:
      • ✅ 1.1-1.5: Infrastructure complete
      • ✅ 1.6: ApiHandlerLifecycleTests
      • ✅ 1.7: DbContextLifecycleTests
      • ❌ 1.8: Phase 1 Verification (no CI integration yet)
    • PR description mentions "memory leaks, issues with DbContext" but doesn't show CI results

Test Quality Issues

  1. Insufficient Warmup in Memory Tests

    • When_processing_commands_memory_should_not_grow_unbounded has 100-request warmup
    • First JIT compilation, type initialization, and cache population may need more
    • Recommendation: Consider 200-500 warmup requests for stable baseline
  2. Magic Numbers Without Constants

    • Request counts (1000, 500, 100), thresholds (10MB, 5MB), success rates (>900, >450) are hardcoded
    • Recommendation: Extract to constants with meaningful names
  3. Missing Test for Connection Pool Leaks

    • Plan mentions "Connection objects: < 50" but no test validates this
    • DbContext test only checks DbContext disposal, not underlying connection cleanup

📊 Test Coverage Assessment

Implemented:

  • ✅ Handler lifecycle (instances disposed after use)
  • ✅ DbContext lifecycle (contexts disposed after use)
  • ✅ Memory growth bounds checking
  • ✅ Basic smoke test for test infrastructure

Missing (per README.md goals):

  • ❌ CommandProcessor memory behavior tests
  • ❌ Message producer connection management tests
  • ❌ Consumer handler disposal tests
  • ❌ Outbox sweeper stability tests
  • ❌ Soak tests (30-60 min runs)
  • ❌ CI integration

🔒 Security Considerations

  • ✅ No credential exposure in configuration
  • ✅ Proper use of CancellationToken in LoadGenerator
  • ⚠️ SQLite in-memory DB is appropriate for tests, but ensure no production config leaks into test environment

🚀 Performance Considerations

  • ✅ Parallel request execution with SemaphoreSlim for controlled concurrency
  • ✅ Periodic GC during test execution to avoid false positives
  • ✅ Baseline measurements before assertions
  • ⚠️ WebApplicationFactory creates a new HttpClient per call - consider caching in LoadGenerator

📝 Documentation Quality

  • ✅ Excellent XML documentation on infrastructure classes
  • ✅ Clear README with usage examples
  • ✅ Comprehensive plan.md with task breakdown
  • ⚠️ Missing ADR-0036 file referenced in README.md (should this be included?)
  • ⚠️ .currenttask file seems like development artifact - should it be in source control?

🎯 Recommendations

Must Fix Before Merge:

  1. Add MIT license headers to all new source files (except AssemblyInfo.cs)
  2. Fix WebApiTestServer environment configuration bug (line 24)
  3. Use await using consistently for WebApiTestServer disposal
  4. Document or separate AWS SDK version pinning changes

Should Fix:

  1. Make LoadTestResult fields private
  2. Add null parameter validation
  3. Extract magic numbers to named constants
  4. Add connection pool leak test
  5. Tighten test thresholds after baseline runs

Consider:

  1. Add CI integration as indicated in plan
  2. Add more comprehensive warmup
  3. Add graceful degradation for missing dependencies
  4. Consider removing .currenttask from source control
  5. Cache HttpClient in LoadGenerator

🎉 Conclusion

This is a solid foundation for memory leak testing infrastructure. The architecture is clean, tests are well-designed, and the infrastructure is reusable. However, there are critical licensing violations that must be addressed before merge, and the AWS SDK version changes need clarification.

The implementation matches the plan for Phase 1 core infrastructure (tasks 1.1-1.7) but is missing Phase 1 completion (task 1.8 - CI integration). Consider whether this PR should be marked as partial Phase 1 or if CI integration should be added.

Overall Assessment: Approve with required changes. Fix licensing, environment config, and async disposal issues. Clarify AWS SDK changes. Everything else can be addressed in follow-up PRs.

Priority Summary:

  • 🔴 Blocking: License headers, environment config bug
  • 🟡 High Priority: Async disposal, AWS SDK explanation
  • 🟢 Nice to Have: Constants, connection tests, tighter thresholds

Great work on the test infrastructure! The dotMemory integration and load testing framework will be very valuable for catching memory leaks. 👍

@iancooper iancooper changed the title Peformance Testing [Feature] Peformance Testing Jan 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant