Repository navigation
Give the failing-renewals lease test room for late timers - #1064
Merged
Merged
Conversation
The run stops one renewal interval before its lease runs out. With a 200 ms interval, four late Task.Delay calls on a busy CI runner were enough to push the cancellation past the lease, and the test failed. A 500 ms interval with a 2 s lease leaves the same check 500 ms of slack.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Type: bugfix
Issue
BackgroundServiceTaskTests.ExecuteAsync_RenewalsKeepFailing_CancelsTheRunBeforeTheLeaseRunsOutfails now and then on CI. It failed on #1063, while the second CI workflow on the same commit passed:The test used a 200 ms renewal interval and a 1 s lease. When renewals keep failing,
RenewLeasestops the run once the next renewal would come too late, which is one interval before the lease runs out. That leaves 200 ms of slack, shared by fourTask.Delay(200 ms)calls. On a busy runner those calls ran over 200 ms late in total, and the cancellation landed 0.3 ms after the lease ended.Production uses a 1 min interval and a 5 min lease, so this is a test timing problem, not a scheduler bug.
Solution
The test now uses a 500 ms interval and a 2 s lease. The run is still expected to stop before the lease ends, but the check now has 500 ms of slack over three delays. The test takes about 1.5 s instead of about 0.8 s.
WaitForallows about 3 s, which is enough. The scheduler code is unchanged.Breaking changes
None.
Testing
dotnet test src/Tests/Grand.Web.Common.Tests --filter "FullyQualifiedName~BackgroundServiceTaskTests": 11/11, run five times in a row locally.cancelledUtc < leasedUntilUtcis unchanged.