Skip to content

fix: execution order of OnlyOnce callbacks#335

Merged
vbreuss merged 1 commit intomainfrom
topic/fix-execution-order-with-onlyonce
Jan 2, 2026
Merged

fix: execution order of OnlyOnce callbacks#335
vbreuss merged 1 commit intomainfrom
topic/fix-execution-order-with-onlyonce

Conversation

@vbreuss
Copy link
Contributor

@vbreuss vbreuss commented Jan 2, 2026

This PR fixes the execution order of OnlyOnce callbacks in the Mockolate mocking library. The issue was that callbacks configured with OnlyOnce() were being executed in reverse order due to an incorrect index increment operation.

Key changes

  • Removed premature index increment in Callback.Invoke method that was causing callbacks to execute in reverse order
  • Added comprehensive test to verify sequential execution of multiple OnlyOnce callbacks

@vbreuss vbreuss self-assigned this Jan 2, 2026
Copilot AI review requested due to automatic review settings January 2, 2026 07:53
@vbreuss vbreuss added the bug Something isn't working label Jan 2, 2026
Copy link

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

This PR fixes the execution order of OnlyOnce callbacks in the Mockolate mocking library. The issue was that callbacks configured with OnlyOnce() were being executed in reverse order due to an incorrect index increment operation.

  • Removed premature index increment in Callback.Invoke method that was causing callbacks to execute in reverse order
  • Added comprehensive test to verify sequential execution of multiple OnlyOnce callbacks

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
Source/Mockolate/Setup/Callback.cs Removed Interlocked.Increment(ref index) call that was causing callbacks to execute in reverse order
Tests/Mockolate.Tests/MockMethods/SetupMethodTests.cs Added test MultipleOnlyOnceCallbacks_ShouldExecuteInOrder to verify correct sequential execution of multiple OnlyOnce callbacks

@sonarqubecloud
Copy link

sonarqubecloud bot commented Jan 2, 2026

@vbreuss vbreuss enabled auto-merge (squash) January 2, 2026 07:57
@github-actions
Copy link

github-actions bot commented Jan 2, 2026

Test Results

    14 files  ±0      14 suites  ±0   5m 14s ⏱️ - 1m 3s
 1 792 tests +1   1 791 ✅ +1  1 💤 ±0  0 ❌ ±0 
11 973 runs  +7  11 972 ✅ +7  1 💤 ±0  0 ❌ ±0 

Results for commit 3956073. ± Comparison against base commit 5069c06.

@vbreuss vbreuss merged commit 978a09c into main Jan 2, 2026
12 checks passed
@vbreuss vbreuss deleted the topic/fix-execution-order-with-onlyonce branch January 2, 2026 07:59
@github-actions
Copy link

github-actions bot commented Jan 2, 2026

🚀 Benchmark Results

Details

BenchmarkDotNet v0.15.8, Linux Ubuntu 24.04.3 LTS (Noble Numbat)
AMD EPYC 7763 2.45GHz, 1 CPU, 4 logical and 2 physical cores
.NET SDK 10.0.101
[Host] : .NET 10.0.1 (10.0.1, 10.0.125.57005), X64 RyuJIT x86-64-v3

Job=InProcess Toolchain=InProcessEmitToolchain IterationCount=15
LaunchCount=1 WarmupCount=10

Method Mean Error StdDev Gen0 Gen1 Allocated
Simple_Mockolate 1.433 μs 0.0072 μs 0.0064 μs 0.2232 - 3.66 KB
Simple_Moq 181.568 μs 0.5532 μs 0.4620 μs 0.4883 - 14.55 KB
Simple_NSubstitute 5.733 μs 0.0193 μs 0.0161 μs 0.5569 0.0076 9.14 KB
Simple_FakeItEasy 6.193 μs 0.0101 μs 0.0084 μs 0.4959 - 8.11 KB

@github-actions
Copy link

github-actions bot commented Jan 2, 2026

This is addressed in release v0.47.0.

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

Labels

bug Something isn't working state: released The issue is released

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants