-
-
Notifications
You must be signed in to change notification settings - Fork 106
Fix disposal leak in skipped tests when constructor has run #2896
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…TestInternalAsync Co-authored-by: thomhurst <[email protected]>
|
Claude finished @Copilot's task —— View job PR Review Complete ✅I've conducted a comprehensive review of PR #2896 that fixes disposal leaks in skipped tests when constructor has run. Here's my detailed analysis: Todo List:
✅ Overall Assessment: EXCELLENTThis is a well-implemented, surgical fix that addresses a legitimate resource leak issue while maintaining consistency with existing patterns. Code Quality & Best Practices✅ Strengths:
✅ Implementation Details:
Security Concerns✅ No security issues identified
Performance Considerations✅ Minimal performance impact
Test Coverage✅ Excellent validation approach:
💡 Minor Enhancement Suggestion:Consider adding a test case that validates the public class SyncDisposableSkippedTest : IDisposable
{
public static bool SyncDisposeCalled { get; set; }
public void Dispose()
{
SyncDisposeCalled = true;
}
[Test]
[Skip("Test should be skipped")]
public void SkippedTest() { }
}Bug Analysis✅ No bugs found. The implementation correctly:
Architecture & Design✅ Well-architected solution:
Code Readability✅ Excellent documentation:
Final Recommendation✅ APPROVE - This is a high-quality fix that:
The implementation demonstrates strong understanding of the codebase and follows established conventions perfectly. |
When a test is skipped but its constructor has already been called, the corresponding
DisposeAsync/Disposemethod was not being invoked, leading to potential resource leaks.This issue occurs because skipped tests are handled by
HandleSkippedTestInternalAsync()which doesn't perform any disposal logic, unlike normal test execution which properly disposes test instances in thefinallyblock ofExecuteTestWithHooksAsync().Example of the Issue
Solution
Modified
HandleSkippedTestInternalAsync()inSingleTestExecutor.csto:SkippedTestInstanceorPlaceholderInstanceIAsyncDisposableandIDisposableOnDisposeevents for injected properties and constructor argsValidation
Added a validation test in
SkipConstructorTestValidationthat ensures if a constructor is called for a skipped test, the corresponding disposal method must also be called, preventing future regressions.The fix is surgical (44 lines added, 0 deleted) and only affects the skipped test execution path, maintaining full backward compatibility while ensuring proper resource cleanup.
Fixes #2563.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.