Skip to content

refactor: Consolidate NotInParallel and shell test patterns#1687

Merged
thomhurst merged 1 commit into
mainfrom
fix/test-dry-violations
Dec 30, 2025
Merged

refactor: Consolidate NotInParallel and shell test patterns#1687
thomhurst merged 1 commit into
mainfrom
fix/test-dry-violations

Conversation

@thomhurst

Copy link
Copy Markdown
Owner

Summary

  • Creates NotInParallelTestModule base class in TestHelpers for NotInParallel tests
  • Creates NotInParallelTracker using ConcurrentDictionary (avoids the ConcurrentBag.TryTake flaky issue)
  • Creates ModuleResultAssertions.AssertCommandOutput() for shell test assertions
  • Updates BashTests, CmdTests, PowershellTests to use shared assertion helper
  • Updates all NotInParallel test files to use shared base class and tracker

Fixes #1592, #1564

Test plan

  • Build passes
  • Tests pass

🤖 Generated with Claude Code

- Create NotInParallelTestModule base class for NotInParallel tests
- Create NotInParallelTracker using ConcurrentDictionary (avoids ConcurrentBag flaky issue)
- Create ModuleResultAssertions.AssertCommandOutput() for shell test assertions
- Update BashTests, CmdTests, PowershellTests to use shared assertions
- Update NotInParallel test files to use shared base class

Fixes #1592
Fixes #1564

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@thomhurst

Copy link
Copy Markdown
Owner Author

Summary

Refactors test code to reduce duplication by introducing assertion helpers and base classes for NotInParallel tests, while fixing a concurrency bug in the tracking mechanism.

Critical Issues

None found ✅

This PR actually fixes a bug in the original code where ConcurrentBag.TryTake() could remove an arbitrary item instead of the specific module being tracked. The fix correctly uses ConcurrentDictionary<string, bool> instead.

Suggestions

NotInParallelTestModule.cs:90 - Minor optimization opportunity

The Reset() method uses a while loop to clear violations:

while (_violations.TryTake(out _)) { }

Since ConcurrentBag<T> doesn't have a Clear() method until .NET 5+, this is the correct approach for compatibility. If the project targets .NET 5+, consider documenting this or using the built-in Clear() method for better readability.

General observation

The refactoring significantly improves code maintainability by:

  • Eliminating ~200 lines of duplicated assertion code
  • Providing reusable base classes for parallel execution testing
  • Making test intent clearer through helper methods

Verdict

APPROVE - No critical issues. The PR improves code quality and fixes a concurrency bug.

@thomhurst thomhurst merged commit 1072365 into main Dec 30, 2025
11 of 12 checks passed
@thomhurst thomhurst deleted the fix/test-dry-violations branch December 30, 2025 17:56
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.

Code smell: DRY violation in NotInParallel test classes

1 participant