Skip to content

Use TimeProvider for SealedSecret sync-wait budget to fix SealedSecretApplyStepTests flake - #21530

Merged
Mitch Denny (mitchdenny) merged 1 commit into
microsoft:mainfrom
davidfowl:aspireagent/fix-19662-sealedsecret-fake-time
Nov 7, 2026
Merged

Mitch Denny (mitchdenny) merged 1 commit into
microsoft:mainfrom
davidfowl:aspireagent/fix-19662-sealedsecret-fake-time

Conversation

@davidfowl

Copy link
Copy Markdown
Collaborator

Description

Fixes #19662

SealedSecretApplyStepTests.WaitForSealedSecretSynced_StatusMatchesButSecretAbsent_KeepsWaitingThenTimesOut is flaky on CI.

Root cause

WaitForSealedSecretSyncedAsync and InvokeProbeWithRemainingBudgetAsync measured their budget against the wall clock (DateTimeOffset.UtcNow and CancelAfter). #19555 raised the test budget from 10ms to 250ms, but the test still failed on main on 10-12: under CI load, a slow first iteration (cold JIT, thread-pool starvation) can use up the whole budget before the second poll, so the loop times out after observing the absent Secret only once.

Fix

Inject a TimeProvider into the budget calculation, the probe timeout (CancellationTokenSource(remaining, timeProvider)) and the poll delay. Production passes TimeProvider.System, so runtime behavior is unchanged. The test now uses FakeTimeProvider: it waits until the second probe signals that it started, then calls Advance to exhaust the budget. The budget therefore only elapses after the loop has demonstrably kept waiting, regardless of runner speed. Microsoft.Extensions.TimeProvider.Testing is already centrally versioned in Directory.Packages.props; the test project only references it.

Evidence

  • Fail-before / pass-after: with a 300ms stall injected into the first iteration, the old code failed 3/3 with the CI signature and the fixed code passed 5/5.
  • Under load: the SealedSecretApplyStepTests class passed 30/30 under CPU load.
  • Full project: Aspire.Hosting.Radius.Tests passed 669 tests, 0 failed.

Checklist

  • Is this feature complete?
    • Yes. Ready to ship.
    • No. Follow-up changes expected.
  • Are you including unit tests for the changes and scenario tests if relevant?
    • Yes
    • No
  • Did you add public API?
    • Yes
    • No
  • Does the change make any security assumptions or guarantees?
    • Yes
    • No

🤖 Posted by AspireAgent (AI Agent)

WaitForSealedSecretSyncedAsync and InvokeProbeWithRemainingBudgetAsync
measured their remaining budget against DateTimeOffset.UtcNow and
CancelAfter, so the StatusMatchesButSecretAbsent test raced the wall
clock: a slow first iteration under CI load consumed the whole budget
before the second poll and the loop timed out after a single Secret
probe. Inject a TimeProvider (production uses TimeProvider.System) and
drive the test with FakeTimeProvider plus an explicit second-probe
signal, so the budget only elapses when the test advances it.

Fixes #19662

Co-authored-by: Copilot <[email protected]>
@github-actions

Copy link
Copy Markdown
Contributor

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 21530

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 21530"

@aspire-repo-bot
aspire-repo-bot Bot requested a balanced review from Copilot October 31, 2026 05:50
@github-actions github-actions Bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Oct 31, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues are reported for the change making SealedSecret sync-wait timeout progression deterministic.

No open issues 🎉

What changed in this PR

Addresses the flaky SealedSecret sync-wait test in #19662 by making timeout progression deterministic, while retaining TimeProvider.System for production behavior.

Changes:

  • Threads TimeProvider through remaining-budget calculations, probe cancellation, and polling delays.
  • Updates the regression test to advance fake time only after the second Secret probe starts, with bounded waits to guard against hangs.
  • Adds the test project’s Microsoft.Extensions.TimeProvider.Testing dependency.
File Description
tests/​Aspire.Hosting.Radius.Tests/​Secrets/​SealedSecretApplyStepTests.cs Uses fake time for the flaky scenario and supplies a time provider at existing call sites.
tests/​Aspire.Hosting.Radius.Tests/​Aspire.Hosting.Radius.Tests.csproj References the fake-time testing package.
src/​Aspire.Hosting.Radius/​Publishing/​SealedSecretApplyStep.cs Uses the supplied time provider consistently for budgets, cancellation, and delays.

Review effort: Balanced

@mitchdenny
Mitch Denny (mitchdenny) merged commit c37dfbe into microsoft:main Nov 7, 2026
161 checks passed
@microsoft-github-policy-service microsoft-github-policy-service Bot added this to the 17.1 milestone Nov 7, 2026
Mitch Denny (mitchdenny) pushed a commit that referenced this pull request Nov 10, 2026
…tApplyStepTests flake (#21530)

## Description

Fixes #19662

`SealedSecretApplyStepTests.WaitForSealedSecretSynced_StatusMatchesButSecretAbsent_KeepsWaitingThenTimesOut`
is flaky on CI.

### Root cause

`WaitForSealedSecretSyncedAsync` and
`InvokeProbeWithRemainingBudgetAsync` measured their budget against the
wall clock (`DateTimeOffset.UtcNow` and `CancelAfter`). #19555 raised
the test budget from 10ms to 250ms, but the test still failed on main on
10-12: under CI load, a slow first iteration (cold JIT, thread-pool
starvation) can use up the whole budget before the second poll, so the
loop times out after observing the absent Secret only once.

### Fix

Inject a `TimeProvider` into the budget calculation, the probe timeout
(`CancellationTokenSource(remaining, timeProvider)`) and the poll delay.
Production passes `TimeProvider.System`, so runtime behavior is
unchanged. The test now uses `FakeTimeProvider`: it waits until the
second probe signals that it started, then calls `Advance` to exhaust
the budget. The budget therefore only elapses after the loop has
demonstrably kept waiting, regardless of runner speed.
`Microsoft.Extensions.TimeProvider.Testing` is already centrally
versioned in `Directory.Packages.props`; the test project only
references it.

### Evidence

- **Fail-before / pass-after:** with a 300ms stall injected into the
first iteration, the old code failed 3/3 with the CI signature and the
fixed code passed 5/5.
- **Under load:** the `SealedSecretApplyStepTests` class passed 30/30
under CPU load.
- **Full project:** `Aspire.Hosting.Radius.Tests` passed 669 tests, 0
failed.

## Checklist

- Is this feature complete?
  - [x] Yes. Ready to ship.
  - [ ] No. Follow-up changes expected.
- Are you including unit tests for the changes and scenario tests if
relevant?
  - [x] Yes
  - [ ] No
- Did you add public API?
  - [ ] Yes
  - [x] No
- Does the change make any security assumptions or guarantees?
  - [ ] Yes
  - [x] No

**🤖 Posted by AspireAgent (AI Agent)**

Co-authored-by: davidfowl <[email protected]>
Co-authored-by: Copilot <[email protected]>
(cherry picked from commit c37dfbe)
Mitch Denny (mitchdenny) pushed a commit that referenced this pull request Nov 10, 2026
…tApplyStepTests flake (#21530)

## Description

Fixes #19662

`SealedSecretApplyStepTests.WaitForSealedSecretSynced_StatusMatchesButSecretAbsent_KeepsWaitingThenTimesOut`
is flaky on CI.

### Root cause

`WaitForSealedSecretSyncedAsync` and
`InvokeProbeWithRemainingBudgetAsync` measured their budget against the
wall clock (`DateTimeOffset.UtcNow` and `CancelAfter`). #19555 raised
the test budget from 10ms to 250ms, but the test still failed on main on
10-12: under CI load, a slow first iteration (cold JIT, thread-pool
starvation) can use up the whole budget before the second poll, so the
loop times out after observing the absent Secret only once.

### Fix

Inject a `TimeProvider` into the budget calculation, the probe timeout
(`CancellationTokenSource(remaining, timeProvider)`) and the poll delay.
Production passes `TimeProvider.System`, so runtime behavior is
unchanged. The test now uses `FakeTimeProvider`: it waits until the
second probe signals that it started, then calls `Advance` to exhaust
the budget. The budget therefore only elapses after the loop has
demonstrably kept waiting, regardless of runner speed.
`Microsoft.Extensions.TimeProvider.Testing` is already centrally
versioned in `Directory.Packages.props`; the test project only
references it.

### Evidence

- **Fail-before / pass-after:** with a 300ms stall injected into the
first iteration, the old code failed 3/3 with the CI signature and the
fixed code passed 5/5.
- **Under load:** the `SealedSecretApplyStepTests` class passed 30/30
under CPU load.
- **Full project:** `Aspire.Hosting.Radius.Tests` passed 669 tests, 0
failed.

## Checklist

- Is this feature complete?
  - [x] Yes. Ready to ship.
  - [ ] No. Follow-up changes expected.
- Are you including unit tests for the changes and scenario tests if
relevant?
  - [x] Yes
  - [ ] No
- Did you add public API?
  - [ ] Yes
  - [x] No
- Does the change make any security assumptions or guarantees?
  - [ ] Yes
  - [x] No

**🤖 Posted by AspireAgent (AI Agent)**

Co-authored-by: davidfowl <[email protected]>
Co-authored-by: Copilot <[email protected]>
(cherry picked from commit c37dfbe)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[CI Failure] Flaky: SealedSecretApplyStepTests wait/timeout test fails intermittently on Linux

3 participants