Skip to content

feat: expose persistent execution counters on timer mocks#1011

Merged
vbreuss merged 1 commit into
mainfrom
feat/timer-execution-counters
May 17, 2026
Merged

feat: expose persistent execution counters on timer mocks#1011
vbreuss merged 1 commit into
mainfrom
feat/timer-execution-counters

Conversation

@vbreuss
Copy link
Copy Markdown
Member

@vbreuss vbreuss commented May 17, 2026

Add ITimerMock.ExecutionCount and a new IPeriodicTimerMock interface with WaitForNextTickCount so tests can observe how often a timer callback fired or WaitForNextTickAsync was entered, including activity that happened before the assertion subscribed. Counters use Interlocked.Increment and Volatile.Read, persist across Change(...) / Period mutations, and freeze on dispose. IPeriodicTimer itself is left untouched; the new IPeriodicTimerMock lives in the testing project.

Add `ITimerMock.ExecutionCount` and a new `IPeriodicTimerMock` interface with `WaitForNextTickCount` so tests can observe how often a timer callback fired or `WaitForNextTickAsync` was entered, including activity that happened before the assertion subscribed. Counters use `Interlocked.Increment` and `Volatile.Read`, persist across `Change(...)` / `Period` mutations, and freeze on dispose. `IPeriodicTimer` itself is left untouched; the new `IPeriodicTimerMock` lives in the testing project.
@vbreuss vbreuss self-assigned this May 17, 2026
Copilot AI review requested due to automatic review settings May 17, 2026 07:51
@vbreuss vbreuss added the enhancement New feature or request label May 17, 2026
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Exposes persistent execution counters on the testing time-system mocks: adds ExecutionCount to the existing ITimerMock and introduces a new IPeriodicTimerMock (gated by FEATURE_PERIODIC_TIMER) with WaitForNextTickCount. Both counters use Interlocked.Increment/Volatile.Read, survive Change/Period mutations, and freeze on dispose because the increment sites are unreachable after disposal.

Changes:

  • Added ExecutionCount to ITimerMock and incremented it in TimerMock.RunTimer after each callback invocation (including swallowed-exception cases).
  • Added new IPeriodicTimerMock interface, made PeriodicTimerMock implement it, and incremented WaitForNextTickCount in WaitForNextTickAsync after the pre-notification disposal/cancellation checks.
  • Updated API baseline snapshots for all target frameworks and added unit tests covering initial value, increment, cancellation-before-entry, and post-dispose freeze behaviors.

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated no comments.

Show a summary per file
File Description
Source/Testably.Abstractions.Testing/TimeSystem/ITimerMock.cs Adds ExecutionCount property with XML docs.
Source/Testably.Abstractions.Testing/TimeSystem/TimerMock.cs Backs the counter with an Interlocked.Increment in RunTimer.
Source/Testably.Abstractions.Testing/TimeSystem/IPeriodicTimerMock.cs New interface extending IPeriodicTimer with WaitForNextTickCount.
Source/Testably.Abstractions.Testing/TimeSystem/PeriodicTimerMock.cs Implements the new interface and increments the counter on each entry.
Tests/Api/.../Expected/*.txt Updated public-API baselines for net6/8/9/10 and netstandard2.0/2.1.
Tests/Testably.Abstractions.Testing.Tests/TimeSystem/TimerMockTests.cs Tests for initial zero, persistence across waits, dispose freeze.
Tests/Testably.Abstractions.Testing.Tests/TimeSystem/PeriodicTimerMockTests.cs Tests for cast, increment, pre-entry cancellation, dispose freeze.

@vbreuss vbreuss enabled auto-merge (squash) May 17, 2026 07:54
@sonarqubecloud
Copy link
Copy Markdown

@vbreuss vbreuss merged commit 8cceb3e into main May 17, 2026
17 checks passed
@vbreuss vbreuss deleted the feat/timer-execution-counters branch May 17, 2026 08:26
@github-actions
Copy link
Copy Markdown

This is addressed in release v6.4.0.

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

Labels

enhancement New feature or request state: released

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants