Skip to content

Fix BrowserPageSession: use TimeProvider for delay, document ReferenceEquals, add timeout test#17228

Merged
mitchdenny merged 2 commits into
mainfrom
mitchdenny/fix-browser-page-session
May 19, 2026
Merged

Fix BrowserPageSession: use TimeProvider for delay, document ReferenceEquals, add timeout test#17228
mitchdenny merged 2 commits into
mainfrom
mitchdenny/fix-browser-page-session

Conversation

@mitchdenny
Copy link
Copy Markdown
Member

Summary

Three fixes to BrowserPageSession and its tests:

  1. Use TimeProvider for reconnect delay — The reconnect loop used Task.Delay(TimeSpan, CancellationToken) which bypasses the _timeProvider field. Changed to Task.Delay(TimeSpan, TimeProvider, CancellationToken) so that FakeTimeProvider can control the inter-attempt delay in tests.

  2. Document the ReferenceEquals check in DisposeAsync — Added a comment explaining why the seemingly redundant check exists: it future-proofs against refactors that may read _connection earlier or release and re-acquire the lock before reaching that point.

  3. Add reconnect timeout exhaustion test — New test MonitorAsync_CompletesWithConnectionLostWhenReconnectTimesOut verifies that when all reconnect attempts fail within the 5-second recovery window, the session completes with BrowserPageSessionCompletionKind.ConnectionLost. Uses FakeTimeProvider.AutoAdvanceAmount to fast-forward past the deadline without requiring manual timer pumping.

…eEquals, add timeout test

- Replace Task.Delay with Task.Delay(TimeSpan, TimeProvider, CancellationToken) in the
  reconnect loop so that FakeTimeProvider can control the inter-attempt delay in tests.
- Add a comment explaining why the ReferenceEquals check in DisposeAsync exists
  (future-proofing against refactors that may read _connection earlier or re-acquire the lock).
- Add MonitorAsync_CompletesWithConnectionLostWhenReconnectTimesOut test that verifies
  the session completes with ConnectionLost when all reconnect attempts fail within
  the s_connectionRecoveryTimeout window.

Co-authored-by: Copilot <[email protected]>
Copilot AI review requested due to automatic review settings May 18, 2026 23:38
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 18, 2026

🚀 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 -- 17228

Or

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

Copy link
Copy Markdown
Contributor

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 updates BrowserPageSession’s reconnect logic to be properly controllable under fake time in tests, adds a clarifying disposal comment, and introduces a new reconnection-timeout test case.

Changes:

  • Switch reconnect backoff delay to Task.Delay(..., TimeProvider, ...) so FakeTimeProvider can drive reconnect timing deterministically.
  • Add an explanatory comment for the ReferenceEquals check in DisposeAsync.
  • Add a test intended to validate that the session completes as ConnectionLost when reconnect recovery times out.
Show a summary per file
File Description
src/Aspire.Hosting.Browsers/BrowserPageSession.cs Use TimeProvider-based delay in reconnect loop; document ReferenceEquals disposal guard.
tests/Aspire.Hosting.Browsers.Tests/BrowserPageSessionTests.cs Add a new test for reconnect-timeout behavior using FakeTimeProvider.

Copilot's findings

  • Files reviewed: 2/2 changed files
  • Comments generated: 1

Comment thread tests/Aspire.Hosting.Browsers.Tests/BrowserPageSessionTests.cs Outdated
Use a concurrent task to advance the FakeTimeProvider clock so that
Task.Delay timers fire and the reconnect loop iterates multiple times
before the deadline is exceeded. Assert reconnectAttempts > 1 to verify
the loop actually retried.

Co-authored-by: Copilot <[email protected]>
@mitchdenny mitchdenny merged commit 76ae7e7 into main May 19, 2026
590 of 593 checks passed
@github-actions github-actions Bot added this to the 13.4 milestone May 19, 2026
@github-actions
Copy link
Copy Markdown
Contributor

CLI E2E Tests failed — 89 passed, 1 failed, 1 unknown (commit 5d633ac)

Failed Tests

View all recordings
Status Test Recording
AddPackageInteractiveWhileAppHostRunningDetached ▶️ View recording
AddPackageWhileAppHostRunningDetached ▶️ View recording
AgentCommands_AllHelpOutputs_AreCorrect ▶️ View recording
AgentInitCommand_DefaultSelection_InstallsDefaultSkills ▶️ View recording
AgentInitCommand_MigratesDeprecatedConfig ▶️ View recording
AspireAddPackageVersionToDirectoryPackagesProps ▶️ View recording
AspireInitSingleFileAppHostRunsViaDotnetRunAppHost ▶️ View recording
AspireInitWithExistingAppHostDirRecreatesMissingNuGetConfigAndPreservesFiles ▶️ View recording
AspireInitWithSolutionFileGeneratesAppHostThatBuildsAgainstChannelHive ▶️ View recording
AspireUpdateRemovesAppHostPackageVersionFromDirectoryPackagesProps ▶️ View recording
AspireUpdateRemovesOrphanAppHostPackageVersionWhenSdkAlreadyCurrent ▶️ View recording
Banner_DisplayedOnFirstRun ▶️ View recording
Banner_DisplayedWithExplicitFlag ▶️ View recording
Banner_NotDisplayedWithNoLogoFlag ▶️ View recording
CertificatesClean_RemovesCertificates ▶️ View recording
CertificatesTrust_WithNoCert_CreatesAndTrustsCertificate ▶️ View recording
CertificatesTrust_WithUntrustedCert_TrustsCertificate ▶️ View recording
ConfigSetGet_CreatesNestedJsonFormat ▶️ View recording
CreateAndRunAspireStarterProject ▶️ View recording
CreateAndRunAspireStarterProjectWithBundle ▶️ View recording
CreateAndRunEmptyAppHostProject ▶️ View recording
CreateAndRunJavaEmptyAppHostProject ▶️ View recording
CreateAndRunJsReactProject ▶️ View recording
CreateAndRunPythonReactProject ▶️ View recording
CreateAndRunTypeScriptEmptyAppHostProject ▶️ View recording
CreateAndRunTypeScriptStarterProject ▶️ View recording
CreateJavaAppHostWithViteApp ▶️ View recording
CreateTypeScriptAppHostWithViteApp_UsesConfiguredToolchain ▶️ View recording
DashboardRunWithOtelTracesReturnsNoTraces ▶️ View recording
DeployK8sBasicApiService ▶️ View recording
DeployK8sWithExternalHelmChart ▶️ View recording
DeployK8sWithGarnet ▶️ View recording
DeployK8sWithMongoDB ▶️ View recording
DeployK8sWithMySql ▶️ View recording
DeployK8sWithPostgres ▶️ View recording
DeployK8sWithRabbitMQ ▶️ View recording
DeployK8sWithRedis ▶️ View recording
DeployK8sWithSqlServer ▶️ View recording
DeployK8sWithValkey ▶️ View recording
DeployTypeScriptAppToKubernetes ▶️ View failure recording
DescribeCommandResolvesReplicaNames ▶️ View recording
DescribeCommandShowsRunningResources ▶️ View recording
DetachFormatJsonProducesValidJson ▶️ View recording
DetachFormatJsonProducesValidJsonWhenRestartingExistingInstance ▶️ View recording
DoListStepsShowsPipelineSteps ▶️ View recording
DocsCommand_RendersInteractiveMarkdownFromLocalSource ▶️ View recording
DoctorCommand_DetectsDeprecatedAgentConfig ▶️ View recording
DoctorCommand_TypeScriptAppHostReportsMissingConfiguredToolchain ▶️ View recording
DoctorCommand_WithSslCertDir_ShowsTrusted ▶️ View recording
DoctorCommand_WithoutSslCertDir_ShowsPartiallyTrusted ▶️ View recording
GlobalMigration_HandlesCommentsAndTrailingCommas ▶️ View recording
GlobalMigration_HandlesMalformedLegacyJson ▶️ View recording
GlobalMigration_PreservesAllValueTypes ▶️ View recording
GlobalMigration_SkipsWhenNewConfigExists ▶️ View recording
GlobalSettings_MigratedFromLegacyFormat ▶️ View recording
InitTypeScriptAppHost_AugmentsExistingViteRepoAtRoot ▶️ View recording
InteractiveCSharpInitCreatesExpectedFiles ▶️ View recording
InvalidAppHostPathWithComments_IsHealedOnRun ▶️ View recording
LatestCliCanStartStableChannelAppHost ▶️ View recording
LatestCliCanStartStableChannelTypeScriptAppHost ▶️ View recording
LegacySettingsMigration_AdjustsRelativeAppHostPath ▶️ View recording
LogLevelTrace_ProducesTraceEntriesInCliLogFile ▶️ View recording
LogsCommandShowsResourceLogs ▶️ View recording
OtelLogsReturnsStructuredLogsFromStarterApp ▶️ View recording
OtelLogsReturnsStructuredLogsFromStarterAppIsolated ▶️ View recording
PsCommandListsRunningAppHost ▶️ View recording
PsFormatJsonOutputsOnlyJsonToStdout ▶️ View recording
PublishWithConfigureEnvFileUpdatesEnvOutput ▶️ View recording
PublishWithDockerComposeServiceCallbackSucceeds ▶️ View recording
PublishWithoutOutputPathUsesAppHostDirectoryDefault ▶️ View recording
ResourceCommand_FailedExecution_DisplaysAppHostLogPathAndLogContainsEntries ▶️ View recording
ResourceCommand_FailsWhenInteractionServiceIsRequired ▶️ View recording
ResourceCommand_SetAndDeleteParameterUpdatesDescribeOutput ▶️ View recording
RestoreGeneratesSdkFiles ▶️ View recording
RestoreGeneratesSdkFiles_WithConfiguredToolchain ▶️ View recording
RestoreRefreshesGeneratedSdkAfterAddingIntegration ▶️ View recording
RestoreSupportsConfigOnlyHelperPackageAndCrossPackageTypes ▶️ View recording
RunFromParentDirectory_UsesExistingConfigNearAppHost ▶️ View recording
RunReportsSyntaxErrorsForDotNetAppHost ▶️ View recording
RunReportsSyntaxErrorsForTypeScriptAppHost ▶️ View recording
SecretCrudOnDotNetAppHost ▶️ View recording
SecretCrudOnTypeScriptAppHost ▶️ View recording
StagingChannel_ConfigureAndVerifySettings_ThenSwitchChannels ▶️ View recording
StartAndWaitForTypeScriptSqlServerAppHostWithNativeAssets ▶️ View recording
StartReportsSyntaxErrorsForDotNetAppHost ▶️ View recording
StartReportsSyntaxErrorsForTypeScriptAppHost ▶️ View recording
StopAllAppHostsFromAppHostDirectory ▶️ View recording
StopNonInteractiveSingleAppHost ▶️ View recording
StopWithNoRunningAppHostExitsSuccessfully ▶️ View recording
UnAwaitedChainsCompileWithAutoResolvePromises ▶️ View recording
UpdateProjectChannelToStable_TypeScript_PicksUpStablePackages ▶️ View recording

📹 Recordings uploaded automatically from CI run #26069082870

@aspire-repo-bot
Copy link
Copy Markdown
Contributor

✅ No documentation update needed.

docs_optional → internal_refactor: No signals triggered (signal_count = 0). The PR makes three internal changes to BrowserPageSession: (1) wires TimeProvider into the reconnect delay for testability, (2) adds a code comment explaining a ReferenceEquals guard, and (3) adds a new unit test. None of these changes affect public API surface, user-visible behavior, configuration, or any documented feature. All changed files are internal implementation and test files with no user-facing impact.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants