Skip to content

[file-diet] Refactor AbortAtDeadlineExtension.cs (600 lines) into focused partial-class files #11424

Description

@github-actions

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:

  1. AbortAtDeadlineExtension.cs (trimmed)

    • Contents: class declaration, interface implementations list, fields, constructor, IsEnabledAsync, NotifyTestExecutionCompleted.
    • Responsibility: Core type definition, construction, and the ITestSessionLifetimeHandler/IDataConsumer entry points.
  2. AbortAtDeadlineExtension.DeadlineHandling.cs

    • Contents: OnTimerElapsed, OnDeadlineReached, HandleDeadlineAsync, RequestGracefulStopAsync, ReleaseDeadlineClaim, RunState enum.
    • Responsibility: Timer-driven deadline detection and graceful-stop orchestration logic.
  3. AbortAtDeadlineExtension.Diagnostics.cs

    • Contents: TryReportAsync, TryLog.
    • Responsibility: Best-effort, timeout-bounded diagnostic reporting and logging helpers.
  4. AbortAtDeadlineExtension.Dispose.cs

    • Contents: Dispose, DisposeAsync.
    • Responsibility: Synchronous and asynchronous teardown, coordinated with the _lock against the timer callback.

Implementation Guidelines

  1. Preserve Behavior: All existing functionality must work identically after the split
  2. Maintain Public API: Keep exported/public symbols accessible with the same names
  3. Update Imports: Fix all import paths throughout the codebase
  4. Test After Each Split: Run the test suite after each incremental change
  5. One File at a Time: Split one module at a time to make review easier

Acceptance Criteria

  • Original file is split into focused modules
  • Each new file is under 300 lines
  • All tests pass after refactoring
  • No breaking changes to public API
  • All import paths updated correctly

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 · [◷]( · )

  • expires on Sep 23, 2026, 6:57 PM UTC

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

type/automationCreated or maintained by an agentic workflow.type/tech-debtCode health, refactoring, simplification.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions