Skip to content

coverage: add tests for interaction edge cases#730

Merged
vbreuss merged 1 commit into
mainfrom
topic/add-interaction-coverage
Apr 30, 2026
Merged

coverage: add tests for interaction edge cases#730
vbreuss merged 1 commit into
mainfrom
topic/add-interaction-coverage

Conversation

@vbreuss
Copy link
Copy Markdown
Member

@vbreuss vbreuss commented Apr 30, 2026

This pull request significantly expands the unit test coverage for the FastBuffer and related classes, focusing on verifying the correct behavior of record boxing, caching, publishing, and event raising logic. The new tests ensure that internal optimizations (such as caching boxed interaction records) and event notification mechanisms are robust and not accidentally broken by future changes. Additionally, the tests pin correct behavior for consuming method buffers when empty, guarding against regressions.

The most important changes are:

Caching and Boxing Behavior Tests

  • Added tests to verify that AppendBoxed and AppendBoxedUnverified methods on event and method buffers correctly cache and reuse boxed interaction records, preventing unnecessary allocations. These tests cover both event subscription/unsubscription and method invocation buffers of various arities.
  • Added a test to ensure that AppendBoxedUnverified on an unsubscribe buffer boxes records as EventUnsubscription, not EventSubscription, pinning the correct conditional logic.

Event Publishing and Raising Tests

  • Introduced a reusable helper and new tests to verify that AppendWithAccess on all indexer getter/setter buffer types publishes the interaction and raises the InteractionAdded event as expected, ensuring coverage for all indexer arities.

Buffer Consumption Edge Cases

  • Added tests to verify that calling ConsumeAll on empty method buffers (for arities 1 through 4) returns zero and does not throw, pinning correct loop bounds and guarding against null reference exceptions.

@vbreuss vbreuss self-assigned this Apr 30, 2026
@vbreuss vbreuss added the coverage Additional tests for edge cases or improvement of test coverage label Apr 30, 2026
@vbreuss vbreuss enabled auto-merge (squash) April 30, 2026 19:03
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented Apr 30, 2026

Quality Gate Passed Quality Gate passed

Issues
0 New issues
2 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarQube Cloud

@github-actions
Copy link
Copy Markdown

Test Results

    21 files  ±  0      21 suites  ±0   9m 33s ⏱️ +38s
 3 928 tests + 45   3 926 ✅ + 45  2 💤 ±0  0 ❌ ±0 
25 514 runs  +315  25 510 ✅ +315  4 💤 ±0  0 ❌ ±0 

Results for commit 00490d1. ± Comparison against base commit ffa9d1c.

@vbreuss vbreuss merged commit 18e6beb into main Apr 30, 2026
16 checks passed
@vbreuss vbreuss deleted the topic/add-interaction-coverage branch April 30, 2026 19:07
@github-actions
Copy link
Copy Markdown

🚀 Benchmark Results

Details

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

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

Method Mean Error StdDev Ratio RatioSD Gen0 Gen1 Allocated Alloc Ratio
Event_Mockolate 372.7 ns 7.00 ns 6.54 ns 1.00 0.02 0.1254 0.0005 2.05 KB 1.00
Event_Moq 16,355.9 ns 76.78 ns 64.11 ns 43.90 0.76 0.7324 - 12.51 KB 6.09
Event_NSubstitute 5,942.4 ns 27.38 ns 22.87 ns 15.95 0.28 0.5493 0.0076 9.05 KB 4.40
Event_FakeItEasy 210,944.3 ns 671.02 ns 627.67 ns 566.20 9.68 0.7324 0.4883 15.39 KB 7.49
Event_Imposter 1,469.1 ns 24.48 ns 22.90 ns 3.94 0.09 0.5379 0.0153 8.8 KB 4.29
Event_TUnitMocks 203.0 ns 4.16 ns 3.89 ns 0.54 0.01 0.0837 0.0002 1.37 KB 0.67
Details

BenchmarkDotNet v0.15.8, Linux Ubuntu 24.04.4 LTS (Noble Numbat)
AMD EPYC 9V74 2.60GHz, 1 CPU, 4 logical and 2 physical cores
.NET SDK 10.0.203
[Host] : .NET 10.0.7 (10.0.7, 10.0.726.21808), X64 RyuJIT x86-64-v3

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

Method N Mean Error StdDev Ratio RatioSD Gen0 Gen1 Allocated Alloc Ratio
Indexer_Mockolate 1 1,060.6 ns 7.98 ns 6.66 ns 1.00 0.01 0.2460 0.0019 4.03 KB 1.00
Indexer_Moq 1 170,324.6 ns 945.21 ns 789.29 ns 160.59 1.21 0.9766 0.4883 20.45 KB 5.07
Indexer_NSubstitute 1 8,556.4 ns 99.23 ns 87.97 ns 8.07 0.09 0.7782 - 12.84 KB 3.18
Indexer_FakeItEasy 1 9,993.6 ns 162.44 ns 151.95 ns 9.42 0.15 0.8392 0.0305 13.88 KB 3.44
Indexer_Imposter 1 956.9 ns 14.95 ns 13.99 ns 0.90 0.01 0.3147 0.0038 5.16 KB 1.28
Indexer_Mockolate 10 2,628.1 ns 9.49 ns 8.41 ns 1.00 0.00 0.3090 - 5.09 KB 1.00
Indexer_Moq 10 184,606.5 ns 514.96 ns 481.69 ns 70.24 0.28 1.7090 1.4648 29.97 KB 5.89
Indexer_NSubstitute 10 20,797.9 ns 89.12 ns 69.58 ns 7.91 0.04 1.5564 0.0305 25.63 KB 5.04
Indexer_FakeItEasy 10 21,814.7 ns 279.61 ns 261.55 ns 8.30 0.10 2.1667 0.0610 35.47 KB 6.97
Indexer_Imposter 10 2,240.4 ns 24.52 ns 22.93 ns 0.85 0.01 0.4845 0.0076 7.97 KB 1.57
Details

BenchmarkDotNet v0.15.8, Linux Ubuntu 24.04.4 LTS (Noble Numbat)
AMD EPYC 9V74 2.87GHz, 1 CPU, 4 logical and 2 physical cores
.NET SDK 10.0.203
[Host] : .NET 10.0.7 (10.0.7, 10.0.726.21808), X64 RyuJIT x86-64-v3

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

Method N Mean Error StdDev Ratio RatioSD Gen0 Gen1 Allocated Alloc Ratio
Method_Mockolate 1 441.4 ns 2.42 ns 2.26 ns 1.00 0.01 0.1416 0.0010 2.32 KB 1.00
Method_Moq 1 126,548.8 ns 458.99 ns 383.28 ns 286.71 1.65 0.4883 - 14.58 KB 6.28
Method_NSubstitute 1 5,228.5 ns 14.56 ns 12.91 ns 11.85 0.07 0.5569 0.0076 9.12 KB 3.93
Method_FakeItEasy 1 5,275.8 ns 24.25 ns 22.69 ns 11.95 0.08 0.4959 - 8.11 KB 3.50
Method_Imposter 1 538.2 ns 2.13 ns 1.78 ns 1.22 0.01 0.2470 0.0029 4.04 KB 1.74
Method_TUnitMocks 1 692.6 ns 3.08 ns 2.40 ns 1.57 0.01 0.1774 0.0010 2.9 KB 1.25
Method_Mockolate 10 713.5 ns 2.84 ns 2.37 ns 1.00 0.00 0.1545 0.0010 2.53 KB 1.00
Method_Moq 10 132,042.3 ns 547.02 ns 511.69 ns 185.08 0.91 0.9766 0.7324 18.48 KB 7.30
Method_NSubstitute 10 7,797.9 ns 25.11 ns 23.49 ns 10.93 0.05 0.7324 0.0153 12.07 KB 4.77
Method_FakeItEasy 10 8,259.3 ns 30.01 ns 26.60 ns 11.58 0.05 0.9766 0.0305 16.05 KB 6.34
Method_Imposter 10 1,133.5 ns 4.86 ns 4.54 ns 1.59 0.01 0.3376 0.0057 5.52 KB 2.18
Method_TUnitMocks 10 1,773.7 ns 3.57 ns 3.16 ns 2.49 0.01 0.2747 0.0019 4.49 KB 1.77
Details

BenchmarkDotNet v0.15.8, Linux Ubuntu 24.04.4 LTS (Noble Numbat)
Intel Xeon Platinum 8370C CPU 2.80GHz, 1 CPU, 4 logical and 2 physical cores
.NET SDK 10.0.203
[Host] : .NET 10.0.7 (10.0.7, 10.0.726.21808), X64 RyuJIT x86-64-v4

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

Method N Mean Error StdDev Ratio RatioSD Gen0 Gen1 Allocated Alloc Ratio
Property_Mockolate 1 627.5 ns 22.49 ns 21.04 ns 1.00 0.05 0.1049 - 2.58 KB 1.00
Property_Moq 1 11,240.3 ns 25.15 ns 22.29 ns 17.93 0.59 0.3662 - 10.27 KB 3.98
Property_NSubstitute 1 7,521.3 ns 68.48 ns 64.06 ns 12.00 0.40 0.4654 0.0076 11.45 KB 4.44
Property_FakeItEasy 1 8,220.9 ns 83.84 ns 74.32 ns 13.11 0.44 0.4578 - 11.25 KB 4.36
Property_Imposter 1 489.3 ns 7.69 ns 7.19 ns 0.78 0.03 0.1268 0.0010 3.13 KB 1.21
Property_TUnitMocks 1 833.6 ns 7.97 ns 7.45 ns 1.33 0.04 0.1020 - 2.51 KB 0.97
Property_Mockolate 10 1,352.1 ns 13.77 ns 12.88 ns 1.00 0.01 0.1240 - 3.07 KB 1.00
Property_Moq 10 17,714.7 ns 68.21 ns 63.80 ns 13.10 0.13 0.6714 - 17.03 KB 5.55
Property_NSubstitute 10 16,843.0 ns 65.03 ns 60.83 ns 12.46 0.12 0.8545 - 21.08 KB 6.87
Property_FakeItEasy 10 18,895.3 ns 70.96 ns 62.90 ns 13.98 0.14 1.2512 0.0305 30.8 KB 10.03
Property_Imposter 10 1,393.9 ns 22.83 ns 21.35 ns 1.03 0.02 0.1888 0.0019 4.67 KB 1.52
Property_TUnitMocks 10 2,731.3 ns 5.01 ns 4.69 ns 2.02 0.02 0.1869 - 4.66 KB 1.52
Details

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

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

Method Mean Error StdDev Ratio RatioSD Gen0 Gen1 Allocated Alloc Ratio
Callback_Mockolate 394.9 ns 9.58 ns 8.49 ns 1.00 0.03 0.1197 - 1.96 KB 1.00
Callback_Moq 95,332.5 ns 350.27 ns 327.64 ns 241.50 4.96 0.4883 0.2441 8.88 KB 4.53
Callback_NSubstitute 4,379.3 ns 13.01 ns 12.17 ns 11.09 0.23 0.4730 0.0076 7.74 KB 3.95
Callback_FakeItEasy 4,689.1 ns 40.38 ns 37.77 ns 11.88 0.26 0.4120 0.0153 6.81 KB 3.47
Callback_Imposter 403.3 ns 1.51 ns 1.34 ns 1.02 0.02 0.1454 0.0010 2.38 KB 1.22
Callback_TUnitMocks 609.7 ns 3.13 ns 2.61 ns 1.54 0.03 0.1602 0.0010 2.63 KB 1.34

@github-actions github-actions Bot added the state: released The issue is released label Apr 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

coverage Additional tests for edge cases or improvement of test coverage state: released The issue is released

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant