Skip to content

fix: record the cancellation time before the wait continues - #1034

Merged
vbreuss merged 1 commit into
mainfrom
fix/eventually-cancellation-race
Sep 6, 2026
Merged

vbreuss merged 1 commit into
mainfrom
fix/eventually-cancellation-race

Conversation

@vbreuss

@vbreuss vbreuss commented Sep 6, 2026

Copy link
Copy Markdown
Member

WhenCancelledDuringTheWaitThatConsumesTheTimeout_ShouldBeInconclusive still failed on the Windows agent after the cancellation was timed in a registration callback, because Task.Delay(wait, cancellationToken) registers a callback on the same token. Cancellation callbacks run in reverse registration order, so the delay is released first and its continuation can read cancelledAt before the callback that records it has run. It then falls back to the time the cancellation was observed, which is exactly the value that made a cancelled expectation look like an expired one.

The wait no longer takes the token. It completes either by its own timer or by a task that the recording callback itself completes, so the recorded time is always visible to the attempt that continues.

`WhenCancelledDuringTheWaitThatConsumesTheTimeout_ShouldBeInconclusive`
still failed on the Windows agent after the cancellation was timed in a
registration callback, because `Task.Delay(wait, cancellationToken)`
registers a callback on the same token. Cancellation callbacks run in
reverse registration order, so the delay is released first and its
continuation can read `cancelledAt` before the callback that records it
has run. It then falls back to the time the cancellation was observed,
which is exactly the value that made a cancelled expectation look like an
expired one.

The wait no longer takes the token. It completes either by its own timer
or by a task that the recording callback itself completes, so the recorded
time is always visible to the attempt that continues.
@vbreuss vbreuss self-assigned this Sep 6, 2026
Copilot AI lite review requested due to automatic review settings September 6, 2026 18:26
@vbreuss vbreuss added the bug Something isn't working label Sep 6, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@sonarqubecloud

sonarqubecloud Bot commented Sep 6, 2026

Copy link
Copy Markdown

@github-actions

github-actions Bot commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

Test Results

     23 files   -  27       23 suites   - 27   9m 19s ⏱️ +28s
 20 094 tests  -  38   20 092 ✅  -  38  2 💤 ±0  0 ❌ ±0 
103 787 runs   - 108  103 785 ✅  - 108  2 💤 ±0  0 ❌ ±0 

Results for commit e4477a8. ± Comparison against base commit affdbc3.

This pull request removes 3230 and adds 3192 tests. Note that renamed tests count towards both.
aweXpect.Core.Tests.Core.Exceptions.FailExceptionTests ‑ InnerException_ShouldBeSet(message: "message1c2cf07a-e48e-4fc9-9e9e-0596c8d4b8d3")
aweXpect.Core.Tests.Core.Exceptions.FailExceptionTests ‑ InnerException_ShouldBeSet(message: "message26fa1c64-51bf-46f6-a7df-8b5d6ea90524")
aweXpect.Core.Tests.Core.Exceptions.FailExceptionTests ‑ InnerException_ShouldBeSet(message: "message3f0a8108-ad0c-48c4-a337-341f7d3b071b")
aweXpect.Core.Tests.Core.Exceptions.FailExceptionTests ‑ InnerException_ShouldBeSet(message: "message3fbfb7c2-f378-40d1-88da-b0a835ea6963")
aweXpect.Core.Tests.Core.Exceptions.FailExceptionTests ‑ InnerException_ShouldBeSet(message: "message48c4dd89-f23c-4c5c-8a73-d59de53b1a54")
aweXpect.Core.Tests.Core.Exceptions.FailExceptionTests ‑ InnerException_ShouldBeSet(message: "message5a3d0513-2bba-4c67-9eb6-1ef4c612c382")
aweXpect.Core.Tests.Core.Exceptions.FailExceptionTests ‑ Message_ShouldBeSet(message: "message1c65d956-ecce-4f45-8dac-223fbe568c7d")
aweXpect.Core.Tests.Core.Exceptions.FailExceptionTests ‑ Message_ShouldBeSet(message: "message45d5cabd-a561-4844-abe3-2523d40c5e40")
aweXpect.Core.Tests.Core.Exceptions.FailExceptionTests ‑ Message_ShouldBeSet(message: "messagea0e87003-238f-4eb8-80df-7bd9427e4944")
aweXpect.Core.Tests.Core.Exceptions.FailExceptionTests ‑ Message_ShouldBeSet(message: "messageb72c3314-d395-4fc2-aa58-6532ff71b75e")
…
aweXpect.Core.Tests.Core.Exceptions.FailExceptionTests ‑ InnerException_ShouldBeSet(message: "message03f4229f-d2e9-407f-9670-e96a84dfb501")
aweXpect.Core.Tests.Core.Exceptions.FailExceptionTests ‑ InnerException_ShouldBeSet(message: "message1f07ed7e-ef2e-4480-89f5-95a66dead0ab")
aweXpect.Core.Tests.Core.Exceptions.FailExceptionTests ‑ InnerException_ShouldBeSet(message: "message7416ed60-5cbd-4262-967a-2e4b71e16d7a")
aweXpect.Core.Tests.Core.Exceptions.FailExceptionTests ‑ InnerException_ShouldBeSet(message: "messagea40c68ed-6db6-4ac1-a73a-646b7dc2a44a")
aweXpect.Core.Tests.Core.Exceptions.FailExceptionTests ‑ InnerException_ShouldBeSet(message: "messageb4959dd7-fb91-4b82-a3f6-f3be756d4cc3")
aweXpect.Core.Tests.Core.Exceptions.FailExceptionTests ‑ InnerException_ShouldBeSet(message: "messaged53cc36d-dd55-4f36-9d26-73d0a5ed5fd4")
aweXpect.Core.Tests.Core.Exceptions.FailExceptionTests ‑ Message_ShouldBeSet(message: "message23a1288a-c5f5-4017-9ef7-78b11fd5061d")
aweXpect.Core.Tests.Core.Exceptions.FailExceptionTests ‑ Message_ShouldBeSet(message: "message4cd10e7a-7d82-4209-a16f-17f7d2bac8e4")
aweXpect.Core.Tests.Core.Exceptions.FailExceptionTests ‑ Message_ShouldBeSet(message: "message6c69f250-3786-41c9-8bc6-9c5b7ad75256")
aweXpect.Core.Tests.Core.Exceptions.FailExceptionTests ‑ Message_ShouldBeSet(message: "message76e68b46-65c0-45cc-86c7-70b190c85694")
…

@github-actions

github-actions Bot commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

🚀 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.303
[Host] : .NET 8.0.30 (8.0.30, 8.0.3026.36720), X64 RyuJIT x86-64-v3

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

Method Mean Error StdDev Gen0 Gen1 Allocated
Bool_aweXpect 275.3 ns 1.37 ns 1.22 ns 0.0415 - 696 B
Bool_FluentAssertions 235.8 ns 1.06 ns 0.94 ns 0.0567 - 952 B
Equivalency_aweXpect 298,328.9 ns 1,091.97 ns 1,021.43 ns 20.0195 0.4883 335444 B
Equivalency_FluentAssertions 2,639,168.9 ns 12,854.58 ns 11,395.25 ns 289.0625 46.8750 4841651 B
Int_GreaterThan_aweXpect 255.3 ns 1.21 ns 1.13 ns 0.0515 - 864 B
Int_GreaterThan_FluentAssertions 242.7 ns 1.86 ns 1.74 ns 0.0730 - 1224 B
ItemsCount_AtLeast_aweXpect 476.2 ns 1.93 ns 1.71 ns 0.0811 - 1360 B
ItemsCount_AtLeast_FluentAssertions 456.5 ns 2.94 ns 2.61 ns 0.1197 - 2008 B
String_aweXpect 460.8 ns 1.57 ns 1.46 ns 0.0672 - 1128 B
String_FluentAssertions 1,193.2 ns 8.79 ns 7.79 ns 0.2346 - 3944 B
StringArray_aweXpect 1,864.8 ns 4.45 ns 3.95 ns 0.1564 - 2624 B
StringArray_FluentAssertions 1,289.2 ns 2.89 ns 2.70 ns 0.2480 - 4152 B
StringArrayInAnyOrder_aweXpect 2,503.9 ns 9.46 ns 8.38 ns 0.1678 - 2816 B
StringArrayInAnyOrder_FluentAssertions 26,512.4 ns 85.82 ns 71.66 ns 1.9836 0.0610 33471 B

@github-actions

github-actions Bot commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

👽 Mutation Results

Mutation testing badge

aweXpect

Details
File Score Killed Survived Timeout No Coverage Ignored Compile Errors Runtime Errors Total Detected Total Undetected Total Mutants

The final mutation score is NaN%

Coverage Thresholds: high:80 low:60 break:0

aweXpect.Core

Details
File Score Killed Survived Timeout No Coverage Ignored Compile Errors Runtime Errors Total Detected Total Undetected Total Mutants
Core/EventuallyExpectationBuilder.cs 72.06% 43 13 6 6 17 3 0 49 19 88

The final mutation score is 72.06%

Coverage Thresholds: high:80 low:60 break:0

@vbreuss
vbreuss merged commit eef3e6a into main Sep 6, 2026
14 checks passed
@vbreuss
vbreuss deleted the fix/eventually-cancellation-race branch September 6, 2026 18:46
github-actions Bot added a commit that referenced this pull request Sep 6, 2026
github-actions Bot added a commit that referenced this pull request Sep 6, 2026
vbreuss added a commit that referenced this pull request Sep 6, 2026
`DefaultCheckInterval_ShouldDetermineTheNumberOfEvaluations` asserted at
least two evaluations, which a build agent cannot guarantee: when the first
evaluation alone uses up the one second retry budget - a cold and busy agent
JITs the whole expectation pipeline on the way - the subject is evaluated
once and the assertion fails. The upper bound is what the test is about: a
200ms check interval within a one second budget allows at most six
evaluations, while an ignored interval would evaluate the subject far more
often. How many of the six a machine reaches is a property of that machine,
not of the check interval.

`WhenCancelledDuringTheWaitThatConsumesTheTimeout_ShouldBeInconclusive` was
skipped while the cancellation of a wait could be observed after the retry
budget had expired. That race is fixed (#1034), so it runs again.
vbreuss added a commit that referenced this pull request Sep 6, 2026
`DefaultCheckInterval_ShouldDetermineTheNumberOfEvaluations` asserted at least two evaluations, which a build agent cannot guarantee: when the first evaluation alone uses up the one second retry budget - a cold and busy agent JITs the whole expectation pipeline on the way - the subject is evaluated once and the assertion fails. The upper bound is what the test is about: a 200ms check interval within a one second budget allows at most six evaluations, while an ignored interval would evaluate the subject far more often. How many of the six a machine reaches is a property of that machine, not of the check interval.

`WhenCancelledDuringTheWaitThatConsumesTheTimeout_ShouldBeInconclusive` was skipped while the cancellation of a wait could be observed after the retry budget had expired. That race is fixed (#1034), so it runs again.
@github-actions

github-actions Bot commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

This is addressed in release v2.38.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