Skip to content

refactor(teardown): centralize cancellation and disposal race helpers - #249

Merged
glennawatson merged 1 commit into
mainfrom
fix/teardown-race-helpers-coverage
Nov 20, 2026
Merged

glennawatson merged 1 commit into
mainfrom
fix/teardown-race-helpers-coverage

Conversation

@glennawatson

Copy link
Copy Markdown
Contributor

Summary

This PR consolidates duplicated cancellation and disposal teardown try/catch wrappers into shared static helpers and adds unit tests covering every teardown branch.

  • ConcurrencyRaceHelpers adds IgnoreCanceledOrDisposedAsync and RunUnderGateIgnoringTeardownAsync to handle OperationCanceledException and ObjectDisposedException during gated unsubscription in ReplayLatestSignalAsyncStateObserverLease<T> and StatelessReplayLatestSignalAsyncStateObserverLease<T>.
  • CancellationRaceHelper centralizes synchronous CancellationTokenSource cancellation across AsyncSubscriptionLifetime, TaskSignal<T>, and Signal.FromTask, removing [ExcludeFromCodeCoverage] from AsyncSubscriptionLifetime.

Why

ReplayLatestSignalAsyncStateObserverLease<T> and StatelessReplayLatestSignalAsyncStateObserverLease<T> duplicated identical OperationCanceledException and ObjectDisposedException catch blocks whose ObjectDisposedException branches were unreachable through AsyncFlowGate, leaving uncovered lines in both lease classes. Synchronous task signals also duplicated ObjectDisposedException cancellation wrappers across three files.

Breaking changes

None

How this was verified

Added unit tests for ConcurrencyRaceHelpers and CancellationRaceHelper, verified 100% line and branch coverage across all touched files, and ran detect-duplicates against main.

Notes for the reviewer

  • Start with ConcurrencyRaceHelpers.cs and the two replay observer lease classes (ReplayLatestSignalAsyncStateObserverLease{T}.cs and StatelessReplayLatestSignalAsyncStateObserverLease{T}.cs). Both leases pass this into RunUnderGateIgnoringTeardownAsync with static callbacks to avoid extra allocations or per-lease async state machines.
  • CancellationRaceHelper.cs replaces the private ObjectDisposedException cancellation helpers in AsyncSubscriptionLifetime.cs, TaskSignal{T}.cs, and Signal{FromTask}.cs.

Checklist

  • I have read the Contribute guide
  • The PR title follows Conventional Commits
  • Tests cover this change, or the summary says why they do not
  • New or changed public API has XML documentation

- Extract IgnoreCanceledOrDisposedAsync and RunUnderGateIgnoringTeardownAsync into ConcurrencyRaceHelpers for replay observer lease unsubscription.
- Extract synchronous CancellationRaceHelper.TryCancel across AsyncSubscriptionLifetime, TaskSignal, and Signal.FromTask, removing the coverage exclusion on AsyncSubscriptionLifetime.
- Add unit tests covering active, cancelled, disposed, and unexpected exception paths across both helpers.
@codecov

codecov Bot commented Nov 20, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (f37a13c) to head (3f33efb).

Additional details and impacted files
@@             Coverage Diff             @@
##             main      #249      +/-   ##
===========================================
+ Coverage   99.98%   100.00%   +0.01%     
===========================================
  Files        1012      1013       +1     
  Lines       27207     27209       +2     
  Branches     3279      3278       -1     
===========================================
+ Hits        27203     27209       +6     
+ Misses          4         0       -4     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@sonarqubecloud

Copy link
Copy Markdown

@glennawatson
glennawatson merged commit 83f7c8d into main Nov 20, 2026
16 checks passed
@glennawatson
glennawatson deleted the fix/teardown-race-helpers-coverage branch November 20, 2026 23:22
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.

1 participant