Overview
The file src/Platform/Microsoft.Testing.Platform/Extensions/AbortAtDeadlineExtension.cs has grown to 600 lines, making it harder to navigate and maintain. This task involves refactoring it into smaller, more focused files.
Current State
- File:
src/Platform/Microsoft.Testing.Platform/Extensions/AbortAtDeadlineExtension.cs
- Size: 600 lines
- Language: C#
Structural Analysis
The file defines a single internal sealed class AbortAtDeadlineExtension that implements IDataConsumer, ITestSessionLifetimeHandler, IOutputDeviceDataProducer, IDisposable (and IAsyncDisposable on .NET Core), plus a private RunState enum. It combines several distinct responsibilities in one type:
- Timer / deadline detection:
_timer, OnTimerElapsed, OnDeadlineReached — arming a Timer at construction and reacting when the CI-imposed hard-cancel deadline approaches.
- Graceful-stop orchestration:
HandleDeadlineAsync, RequestGracefulStopAsync, ReleaseDeadlineClaim — coordinating with IGracefulStopTestExecutionCapability and IStopPoliciesService to ask the test framework to stop scheduling new tests.
- Lifecycle/session hooks:
IsEnabledAsync, NotifyTestExecutionCompleted — implementing ITestSessionLifetimeHandler to detect when the run finished before the timer fires.
- Best-effort diagnostics/reporting:
TryReportAsync, TryLog — bounding diagnostic/report calls with a timeout and swallowing/logging failures.
- Disposal:
Dispose, DisposeAsync — tearing down the timer and releasing resources, guarded by a _lock to serialize against the timer callback.
- State enum:
RunState — tracks whether the deadline handling has not started, is in progress, or has completed.
Refactoring Strategy
Proposed File Splits
Since AbortAtDeadlineExtension is internal sealed, C# partial classes are the safest way to split it without touching its public surface or constructor signature:
-
AbortAtDeadlineExtension.cs (trimmed)
- Contents: class declaration, interface implementations list, fields, constructor,
IsEnabledAsync, NotifyTestExecutionCompleted.
- Responsibility: Core type definition, construction, and the
ITestSessionLifetimeHandler/IDataConsumer entry points.
-
AbortAtDeadlineExtension.DeadlineHandling.cs
- Contents:
OnTimerElapsed, OnDeadlineReached, HandleDeadlineAsync, RequestGracefulStopAsync, ReleaseDeadlineClaim, RunState enum.
- Responsibility: Timer-driven deadline detection and graceful-stop orchestration logic.
-
AbortAtDeadlineExtension.Diagnostics.cs
- Contents:
TryReportAsync, TryLog.
- Responsibility: Best-effort, timeout-bounded diagnostic reporting and logging helpers.
-
AbortAtDeadlineExtension.Dispose.cs
- Contents:
Dispose, DisposeAsync.
- Responsibility: Synchronous and asynchronous teardown, coordinated with the
_lock against the timer callback.
Implementation Guidelines
- Preserve Behavior: All existing functionality must work identically after the split
- Maintain Public API: Keep exported/public symbols accessible with the same names
- Update Imports: Fix all import paths throughout the codebase
- Test After Each Split: Run the test suite after each incremental change
- One File at a Time: Split one module at a time to make review easier
Acceptance Criteria
Priority: Medium
Effort: Small
Expected Impact: Improved code navigability, easier testing, reduced merge conflicts
🤖 Automated content by GitHub Copilot. Generated by the Daily File Diet workflow. · copilot · auto · 32.9 AIC · ⌖ 6.18 AIC · ⊞ 10.5K · [◷]( · ◷)
Overview
The file
src/Platform/Microsoft.Testing.Platform/Extensions/AbortAtDeadlineExtension.cshas grown to 600 lines, making it harder to navigate and maintain. This task involves refactoring it into smaller, more focused files.Current State
src/Platform/Microsoft.Testing.Platform/Extensions/AbortAtDeadlineExtension.csStructural Analysis
The file defines a single
internal sealed class AbortAtDeadlineExtensionthat implementsIDataConsumer,ITestSessionLifetimeHandler,IOutputDeviceDataProducer,IDisposable(andIAsyncDisposableon .NET Core), plus a privateRunStateenum. It combines several distinct responsibilities in one type:_timer,OnTimerElapsed,OnDeadlineReached— arming aTimerat construction and reacting when the CI-imposed hard-cancel deadline approaches.HandleDeadlineAsync,RequestGracefulStopAsync,ReleaseDeadlineClaim— coordinating withIGracefulStopTestExecutionCapabilityandIStopPoliciesServiceto ask the test framework to stop scheduling new tests.IsEnabledAsync,NotifyTestExecutionCompleted— implementingITestSessionLifetimeHandlerto detect when the run finished before the timer fires.TryReportAsync,TryLog— bounding diagnostic/report calls with a timeout and swallowing/logging failures.Dispose,DisposeAsync— tearing down the timer and releasing resources, guarded by a_lockto serialize against the timer callback.RunState— tracks whether the deadline handling has not started, is in progress, or has completed.Refactoring Strategy
Proposed File Splits
Since
AbortAtDeadlineExtensionisinternal sealed, C# partial classes are the safest way to split it without touching its public surface or constructor signature:AbortAtDeadlineExtension.cs(trimmed)IsEnabledAsync,NotifyTestExecutionCompleted.ITestSessionLifetimeHandler/IDataConsumerentry points.AbortAtDeadlineExtension.DeadlineHandling.csOnTimerElapsed,OnDeadlineReached,HandleDeadlineAsync,RequestGracefulStopAsync,ReleaseDeadlineClaim,RunStateenum.AbortAtDeadlineExtension.Diagnostics.csTryReportAsync,TryLog.AbortAtDeadlineExtension.Dispose.csDispose,DisposeAsync._lockagainst the timer callback.Implementation Guidelines
Acceptance Criteria
Priority: Medium
Effort: Small
Expected Impact: Improved code navigability, easier testing, reduced merge conflicts