Skip to content

Conversation

thomhurst
Copy link
Owner

Fixes #2755

Copy link
Contributor

claude bot commented Aug 5, 2025

Claude finished @thomhurst's task —— View job


Code Review Complete ✅

I've completed a thorough review of PR #2766: "feat: enhance test filtering to handle explicit tests". Here's my comprehensive feedback:

Todo List:

  • Read repository guidelines (CLAUDE.md)
  • Analyze TestFilterService.cs changes
  • Review ExplicitTests.cs (new test file)
  • Review ExplicitAttributeTests.cs (new test file)
  • Check F# project file changes
  • Assess code quality and best practices
  • Identify potential bugs or issues
  • Evaluate performance considerations
  • Check for security concerns
  • Assess test coverage
  • Provide comprehensive feedback

Overall Assessment: ✅ Excellent Implementation

This PR implements a well-thought-out solution for handling explicit tests in the TUnit framework with sophisticated filtering logic and comprehensive test coverage.

🎯 Strengths

Code Quality & Design

  • Clean Architecture: The filtering logic in TestFilterService.cs:27-62 is well-structured with clear separation of concerns
  • Smart Algorithm: The single-pass filtering approach (TestFilterService.cs:31-44) efficiently categorizes tests while applying filters
  • Intuitive Behavior: The logic correctly implements the documented behavior: "explicit tests are excluded unless ALL filtered tests are explicit"

Robust Logic Implementation

  • Mixed Test Handling: Lines 46-52 properly exclude explicit tests when both explicit and non-explicit tests match the filter
  • Explicit-Only Scenarios: Lines 54-59 correctly include explicit tests when the filter only matches explicit tests
  • Edge Case Coverage: Handles no-filter scenarios by excluding all explicit tests (TestFilterService.cs:21-22)

Comprehensive Test Suite

The new test files provide excellent coverage:

  • Integration Tests: ExplicitTests.cs tests real filtering scenarios with multiple test modes
  • Realistic Test Data: ExplicitAttributeTests.cs provides varied test scenarios (class-level, method-level, mixed)
  • Edge Cases: Tests cover wildcards, specific filters, mixed explicit/non-explicit scenarios

📋 Code Quality Observations

Performance

  • Efficient Algorithm: Single-pass filtering with O(n) complexity is optimal
  • Memory Conscious: Uses separate lists only when necessary to avoid unnecessary allocations
  • Logging Balance: Appropriate trace logging that won't impact performance in production

Security 🔒

  • Safe Implementation: No security concerns identified
  • Input Validation: Proper null checking and defensive programming practices
  • No External Dependencies: Changes don't introduce security risks

Maintainability 🔧

  • Clear Intent: Method names like IsExplicitTest() and FilterOutExplicitTests() are self-documenting
  • Consistent Style: Follows existing codebase conventions
  • Good Separation: Helper methods are properly extracted and focused

🔍 Minor Suggestions

Documentation Enhancement

Consider adding XML documentation to the main filtering method:

/// <summary>
/// Filters tests based on the provided filter, with special handling for explicit tests.
/// When both explicit and non-explicit tests match a filter, explicit tests are excluded.
/// When only explicit tests match a filter, they are included.
/// </summary>
public IReadOnlyCollection<AbstractExecutableTest> FilterTests(...)

Code Robustness

The IsExplicitTest() method at line 182 is well-implemented, correctly checking test attributes for the ExplicitAttribute.

🧪 Test Coverage Assessment

Excellent Coverage

  • ✅ No filter scenarios (excluding explicit tests)
  • ✅ Wildcard filters matching both explicit and non-explicit
  • ✅ Specific filters targeting only explicit tests
  • ✅ Class-level explicit attributes
  • ✅ Method-level explicit attributes
  • ✅ Mixed scenarios with Skip attributes
  • ✅ Multiple test execution modes (SourceGenerated, Reflection, AOT)

Test Quality

  • Realistic Scenarios: Tests use actual test project structure mimicking real usage
  • Clear Assertions: Each test has well-defined expected outcomes with specific counters
  • Good Test Names: Descriptive names clearly indicate what behavior is being tested

📁 File Changes Review

F# Project File (TUnit.NugetTester.FSharp.fsproj)

  • Minor target framework updates (lines 4, 17, 18) are appropriate maintenance changes
  • No issues with these changes

🎖️ Recommendation: APPROVE

This PR demonstrates:

  • Solid Engineering: Well-thought-out algorithm with proper edge case handling
  • Quality Implementation: Clean, maintainable code following established patterns
  • Thorough Testing: Comprehensive test coverage across multiple scenarios
  • Documentation Alignment: Implementation matches the documented behavior in docs/test-authoring/explicit.md

The implementation correctly addresses issue #2755 by providing sophisticated test filtering that respects the explicit test semantics while maintaining intuitive behavior for end users.


Copy link
Contributor

claude bot commented Aug 5, 2025

Claude finished @thomhurst's task —— View job


PR Code Review - "feat: enhance test filtering to handle explicit tests"

Todo List:

  • Read repository guidelines (CLAUDE.md)
  • Analyze TestFilterService.cs changes
  • Review ExplicitTests.cs (new test file)
  • Review ExplicitAttributeTests.cs (new test file)
  • Check F# project file changes
  • Assess code quality and best practices
  • Identify potential bugs or issues
  • Evaluate performance considerations
  • Check for security concerns
  • Assess test coverage
  • Provide comprehensive feedback

Overall Assessment: ✅ Excellent Implementation

This PR implements a well-thought-out solution for handling explicit tests in the TUnit framework with sophisticated filtering logic and comprehensive test coverage.

🎯 Strengths

Code Quality & Design

  • Clean Architecture: The filtering logic in TestFilterService.cs:27-62 is well-structured with clear separation of concerns
  • Smart Algorithm: The single-pass filtering approach (TestFilterService.cs:31-44) efficiently categorizes tests while applying filters
  • Intuitive Behavior: The logic correctly implements the documented behavior: "explicit tests are excluded unless ALL filtered tests are explicit"

Robust Logic Implementation

  • Mixed Test Handling: Lines 46-52 properly exclude explicit tests when both explicit and non-explicit tests match the filter
  • Explicit-Only Scenarios: Lines 54-59 correctly include explicit tests when the filter only matches explicit tests
  • Edge Case Coverage: Handles no-filter scenarios by excluding all explicit tests (TestFilterService.cs:21-22)

Comprehensive Test Suite

The new test files provide excellent coverage:

  • Integration Tests: ExplicitTests.cs tests real filtering scenarios with multiple test modes
  • Realistic Test Data: ExplicitAttributeTests.cs provides varied test scenarios (class-level, method-level, mixed)
  • Edge Cases: Tests cover wildcards, specific filters, mixed explicit/non-explicit scenarios

📋 Code Quality Observations

Performance

  • Efficient Algorithm: Single-pass filtering with O(n) complexity is optimal
  • Memory Conscious: Uses separate lists only when necessary to avoid unnecessary allocations
  • Logging Balance: Appropriate trace logging that won't impact performance in production

Security 🔒

  • Safe Implementation: No security concerns identified
  • Input Validation: Proper null checking and defensive programming practices
  • No External Dependencies: Changes don't introduce security risks

Maintainability 🔧

  • Clear Intent: Method names like IsExplicitTest() and FilterOutExplicitTests() are self-documenting
  • Consistent Style: Follows existing codebase conventions
  • Good Separation: Helper methods are properly extracted and focused

🔍 Minor Suggestions

Documentation Enhancement

Consider adding XML documentation to the main filtering method:

/// <summary>
/// Filters tests based on the provided filter, with special handling for explicit tests.
/// When both explicit and non-explicit tests match a filter, explicit tests are excluded.
/// When only explicit tests match a filter, they are included.
/// </summary>
public IReadOnlyCollection<AbstractExecutableTest> FilterTests(...)

Code Robustness

The IsExplicitTest() method at line 182 is well-implemented, correctly checking test attributes for the ExplicitAttribute.

🧪 Test Coverage Assessment

Excellent Coverage

  • ✅ No filter scenarios (excluding explicit tests)
  • ✅ Wildcard filters matching both explicit and non-explicit
  • ✅ Specific filters targeting only explicit tests
  • ✅ Class-level explicit attributes
  • ✅ Method-level explicit attributes
  • ✅ Mixed scenarios with Skip attributes
  • ✅ Multiple test execution modes (SourceGenerated, Reflection, AOT)

Test Quality

  • Realistic Scenarios: Tests use actual test project structure mimicking real usage
  • Clear Assertions: Each test has well-defined expected outcomes with specific counters
  • Good Test Names: Descriptive names clearly indicate what behavior is being tested

📁 File Changes Review

F# Project File (TUnit.NugetTester.FSharp.fsproj)

  • Minor target framework updates (lines 4, 17, 18) are appropriate maintenance changes
  • No issues with these changes

🎖️ Recommendation: APPROVE

This PR demonstrates:

  • Solid Engineering: Well-thought-out algorithm with proper edge case handling
  • Quality Implementation: Clean, maintainable code following established patterns
  • Thorough Testing: Comprehensive test coverage across multiple scenarios
  • Documentation Alignment: Implementation matches the documented behavior in docs/test-authoring/explicit.md

The implementation correctly addresses issue #2755 by providing sophisticated test filtering that respects the explicit test semantics while maintaining intuitive behavior for end users.


Copy link
Contributor

claude bot commented Aug 6, 2025

Claude finished @thomhurst's task —— View job


PR Code Review - "feat: enhance test filtering to handle explicit tests"

Todo List:

  • Read repository guidelines (CLAUDE.md)
  • Analyze TestFilterService.cs changes
  • Review ExplicitTests.cs (new test file)
  • Review ExplicitAttributeTests.cs (new test file)
  • Check F# project file changes
  • Assess code quality and best practices
  • Identify potential bugs or issues
  • Evaluate performance considerations
  • Check for security concerns
  • Assess test coverage
  • Provide comprehensive feedback

Overall Assessment: ✅ Excellent Implementation

This PR implements a well-thought-out solution for handling explicit tests in the TUnit framework with sophisticated filtering logic and comprehensive test coverage.

🎯 Strengths

Code Quality & Design

  • Clean Architecture: The filtering logic in TestFilterService.cs:27-62 is well-structured with clear separation of concerns
  • Smart Algorithm: The single-pass filtering approach (TestFilterService.cs:31-44) efficiently categorizes tests while applying filters
  • Intuitive Behavior: The logic correctly implements the documented behavior: "explicit tests are excluded unless ALL filtered tests are explicit"

Robust Logic Implementation

  • Mixed Test Handling: Lines 46-52 properly exclude explicit tests when both explicit and non-explicit tests match the filter
  • Explicit-Only Scenarios: Lines 54-59 correctly include explicit tests when the filter only matches explicit tests
  • Edge Case Coverage: Handles no-filter scenarios by excluding all explicit tests (TestFilterService.cs:21-22)

Comprehensive Test Suite

The new test files provide excellent coverage:

  • Integration Tests: ExplicitTests.cs tests real filtering scenarios with multiple test modes
  • Realistic Test Data: ExplicitAttributeTests.cs provides varied test scenarios (class-level, method-level, mixed)
  • Edge Cases: Tests cover wildcards, specific filters, mixed explicit/non-explicit scenarios

📋 Code Quality Observations

Performance

  • Efficient Algorithm: Single-pass filtering with O(n) complexity is optimal
  • Memory Conscious: Uses separate lists only when necessary to avoid unnecessary allocations
  • Logging Balance: Appropriate trace logging that won't impact performance in production

Security 🔒

  • Safe Implementation: No security concerns identified
  • Input Validation: Proper null checking and defensive programming practices
  • No External Dependencies: Changes don't introduce security risks

Maintainability 🔧

  • Clear Intent: Method names like IsExplicitTest() and FilterOutExplicitTests() are self-documenting
  • Consistent Style: Follows existing codebase conventions
  • Good Separation: Helper methods are properly extracted and focused

🔍 Minor Suggestions

Documentation Enhancement

Consider adding XML documentation to the main filtering method:

/// <summary>
/// Filters tests based on the provided filter, with special handling for explicit tests.
/// When both explicit and non-explicit tests match a filter, explicit tests are excluded.
/// When only explicit tests match a filter, they are included.
/// </summary>
public IReadOnlyCollection<AbstractExecutableTest> FilterTests(...)

Code Robustness

The IsExplicitTest() method at line 182 is well-implemented, correctly checking test attributes for the ExplicitAttribute.

🧪 Test Coverage Assessment

Excellent Coverage

  • ✅ No filter scenarios (excluding explicit tests)
  • ✅ Wildcard filters matching both explicit and non-explicit
  • ✅ Specific filters targeting only explicit tests
  • ✅ Class-level explicit attributes
  • ✅ Method-level explicit attributes
  • ✅ Mixed scenarios with Skip attributes
  • ✅ Multiple test execution modes (SourceGenerated, Reflection, AOT)

Test Quality

  • Realistic Scenarios: Tests use actual test project structure mimicking real usage
  • Clear Assertions: Each test has well-defined expected outcomes with specific counters
  • Good Test Names: Descriptive names clearly indicate what behavior is being tested

📁 File Changes Review

F# Project File (TUnit.NugetTester.FSharp.fsproj)

  • Minor target framework updates (lines 4, 17, 18) are appropriate maintenance changes
  • No issues with these changes

🎖️ Recommendation: APPROVE

This PR demonstrates:

  • Solid Engineering: Well-thought-out algorithm with proper edge case handling
  • Quality Implementation: Clean, maintainable code following established patterns
  • Thorough Testing: Comprehensive test coverage across multiple scenarios
  • Documentation Alignment: Implementation matches the documented behavior in docs/test-authoring/explicit.md

The implementation correctly addresses issue #2755 by providing sophisticated test filtering that respects the explicit test semantics while maintaining intuitive behavior for end users.


Copilot AI and others added 9 commits August 11, 2025 18:18
Co-authored-by: thomhurst <30480171+thomhurst@users.noreply.github.com>
Co-authored-by: thomhurst <30480171+thomhurst@users.noreply.github.com>
These methods were never called and represent dead code. The timeout attribute is captured in the generated code but the 30-minute default is never overridden (that's a separate issue).

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Added 5-second timeout for each OnDispose event handler
- Prevents tests from hanging indefinitely if disposal logic deadlocks
- Logs warnings when disposal times out, errors are logged but don't fail the test
- This ensures robust cleanup even when disposal handlers misbehave

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-authored-by: thomhurst <30480171+thomhurst@users.noreply.github.com>
This resolves the hanging issue reported in #2867 by removing the
await ReleaseObject(obj) calls from OnDispose event handlers.

The root cause was that multiple disposal handlers could simultaneously
attempt to dispose the same shared object (like WebApplicationFactory
with SharedType.PerTestSession), causing deadlocks in complex disposable
objects.

Changes:
- OnDispose handlers now only decrement reference counts
- Shared objects are disposed by their natural lifecycle management
- Prevents hanging while maintaining proper reference tracking
- No resource leaks as objects are still properly disposed by their scopes

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-authored-by: Tom Longhurst <undefined@users.noreply.github.com>
- Restore ReleaseObject() calls in OnDispose handlers to actually dispose objects
- Objects are only disposed when reference count reaches zero (proper sharing)
- Add 5-second timeout protection to prevent hanging during disposal
- Separate DisposeObjectAsync() method for cleaner disposal logic
- Maintain duplicate handler prevention using _registeredHandlers
- Support both IAsyncDisposable and IDisposable objects
- Exception handling prevents disposal failures from hanging tests

This provides a generic and maintainable counting/tracking approach
that properly disposes shared objects while preventing race conditions.

Co-authored-by: Tom Longhurst <thomhurst@users.noreply.github.com>
@thomhurst
Copy link
Owner Author

@claude fix this

Copy link
Contributor

claude bot commented Aug 12, 2025

Claude finished @thomhurst's task —— View job


Fix Complete ✅

Todo List:

  • Read the image to understand the issue
  • Read repository guidelines (CLAUDE.md)
  • Examine the current PR changes and codebase
  • Identify the specific problem
  • Analyze the ExplicitAttribute detection logic
  • Fix the IsExplicitTest method to check class-level attributes more reliably
  • Build and test the changes
  • Commit and push the fix

Issue Identified:

The CI was failing because the TUnit.Engine.Tests were timing out (20 minutes) and hanging with exit code 7. The root cause was in the IsExplicitTest method in TestFilterService.cs - it wasn't reliably detecting class-level [Explicit] attributes, causing test filtering logic to malfunction.

Fix Applied:

Enhanced the IsExplicitTest method in TUnit.Engine/Services/TestFilterService.cs to:

  1. Primary Check: Use the aggregated TestDetails.Attributes collection (which should contain both method and class attributes)
  2. Fallback Check: Also check the class type directly using reflection to ensure class-level [Explicit] attributes are always detected

Changes Made:

  • Modified IsExplicitTest() method with robust attribute detection
  • Added fallback reflection check for class-level attributes
  • Improved error handling and reliability of explicit test filtering

The fix has been committed and pushed to the bug/2755 branch. This should resolve the hanging tests by ensuring that explicit test filtering works correctly according to the documented behavior.

Commit: 79e60a6 - fix: enhance ExplicitAttribute detection to include class-level attributes


claude bot and others added 2 commits August 12, 2025 07:56
Prevent ObjectTracker from disposing shared objects when individual test
contexts complete. Shared objects should only be disposed when their
respective lifecycle scope ends (PerClass, PerAssembly, PerTestSession).

This fixes the issue where DataClass objects were being disposed
prematurely, causing ObjectDisposedException when test classes tried to
access them during their disposal phase.

Co-authored-by: Tom Longhurst <thomhurst@users.noreply.github.com>
…butes

Improve the IsExplicitTest method in TestFilterService to more reliably
detect ExplicitAttribute at both method and class levels. This resolves
test filtering issues that were causing tests to hang during execution.

- First check the aggregated TestDetails.Attributes collection
- Add fallback reflection check on the class type directly
- Fixes timeout issues with Engine.Tests by ensuring proper explicit test filtering

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Tom Longhurst <thomhurst@users.noreply.github.com>
This was referenced Aug 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ExplicitAttribute no longer works in v0.50.0
2 participants