Skip to content
Draft
Show file tree
Hide file tree
Changes from 46 commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
3a9eae4
Add browser-wasm dotnet test launcher package
Evangelink Sep 13, 2026
066ab8d
Secure browser launcher transport
Evangelink Sep 13, 2026
086b063
Harden browser launcher packaging and cleanup
Evangelink Sep 14, 2026
083be6d
Support framework-owned browser host pages
Evangelink Sep 14, 2026
ab878a3
Wrap computed browser hosts and version page API
Evangelink Sep 14, 2026
651b5c3
Harden browser host and launch-info contracts
Evangelink Sep 14, 2026
50932dc
Report fatal browser page integration errors
Evangelink Sep 14, 2026
760ee9e
Fix browser launcher wrapping edge cases
Evangelink Sep 14, 2026
89beb27
Gate browser launcher preview contract
Evangelink Sep 15, 2026
fc15c64
Isolate browser test invocations and cancellation
Evangelink Sep 15, 2026
6d81426
Make pure managed browser apps canonical
Evangelink Sep 16, 2026
62f9561
Simplify browser launcher experiment
Evangelink Sep 16, 2026
d0eefc0
Fix browser host static asset ownership
Evangelink Sep 16, 2026
e6d8e4e
Remove redundant browser fixture property
Evangelink Sep 16, 2026
220f675
Address browser package review feedback
Evangelink Sep 17, 2026
d3d54c3
Harden minimal browser launcher boundaries
Evangelink Sep 17, 2026
8fe7d67
Merge remote-tracking branch 'origin/main' into dev/amauryleve/mtp-br…
Evangelink Oct 11, 2026
cf60055
Stabilize browser launcher package validation
Evangelink Oct 11, 2026
a4d5814
Stabilize browser package CI assertions
Evangelink Oct 11, 2026
0a1f96f
Disable ANSI in browser acceptance assets
Evangelink Oct 11, 2026
a552074
Normalize browser acceptance terminal output
Evangelink Oct 11, 2026
ad45692
Ignore telemetry banners in MSBuild property checks
Evangelink Oct 11, 2026
93513d7
Productize browser dotnet test integration
Evangelink Oct 11, 2026
e541426
Require immutable inputs for browser acceptance
Evangelink Oct 11, 2026
ae2808b
Run desktop browser checks with aligned inputs
Evangelink Oct 11, 2026
febca12
Restore browser launcher target activation
Evangelink Oct 11, 2026
d1592cd
Validate aligned browser product lifecycle
Evangelink Oct 11, 2026
b6c7cac
Fail browser runs when artifact export fails
Evangelink Oct 11, 2026
b41d763
Document browser package release gates
Evangelink Oct 11, 2026
ffffd0d
Require composed browser acceptance inputs
Evangelink Oct 12, 2026
4a6036b
Run composed browser validation in CI
Evangelink Oct 12, 2026
9fad971
Expand browser validation matrix in aggregate
Evangelink Oct 12, 2026
344ab39
Propagate build driver failures
Evangelink Oct 12, 2026
da3f8d6
Use short browser SDK checkout in CI
Evangelink Oct 12, 2026
edfee2d
Select source-matched SDK in browser tests
Evangelink Oct 12, 2026
eed7135
Pin browser runner with SDK identity propagation
Evangelink Oct 12, 2026
a70d238
Verify restored browser package identities
Evangelink Oct 12, 2026
e92dc79
Use minimal Windows SDK checkout path
Evangelink Oct 12, 2026
0b38356
Enable long paths for browser SDK checkout
Evangelink Oct 12, 2026
ccccc8b
Use short isolated browser package cache
Evangelink Oct 12, 2026
ad741a2
Update browser testing SDK runner pin
Evangelink Oct 12, 2026
beda164
Add browser testing package filter
Evangelink Oct 12, 2026
102082f
Expose MSBuild threading switch
Evangelink Oct 12, 2026
7094ae3
Update browser runner for package filter
Evangelink Oct 12, 2026
b3c543a
Use VS2026 browser Windows agent
Evangelink Oct 12, 2026
bbbbfd2
Include analyzer package build dependency
Evangelink Oct 12, 2026
303a5d8
Resolve acceptance package versions lazily
Evangelink Oct 12, 2026
580258b
Reclaim SDK intermediates in browser CI
Evangelink Oct 12, 2026
c81b63a
Use capacity-backed Linux browser CI
Evangelink Oct 12, 2026
4a728fc
Address browser package review feedback
Evangelink Oct 12, 2026
3f63c69
Document experimental browser protocol capabilities
Evangelink Nov 2, 2026
c22e5fd
Merge main and align browser protocol allocations
Evangelink Nov 2, 2026
5a29bc7
Expect protocol 1.5 in packed coverage checks
Evangelink Nov 2, 2026
dd63a33
Fix browser package localization and launcher reliability
Evangelink Nov 2, 2026
11b0d39
Normalize browser satellite package paths across platforms
Evangelink Nov 2, 2026
63d157f
Align browser acceptance with the validated SDK and verbose CLI output
Evangelink Nov 2, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions BrowserTestingPackages.slnf
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"solution": {
"path": "TestFx.slnx",
"projects": [
"src\\Adapter\\MSTest.TestAdapter\\MSTest.TestAdapter.csproj",
"src\\Analyzers\\MSTest.Analyzers.Package\\MSTest.Analyzers.Package.csproj",
"src\\Analyzers\\MSTest.GlobalConfigsGenerator\\MSTest.GlobalConfigsGenerator.csproj",
"src\\Platform\\Microsoft.Testing.Extensions.Telemetry\\Microsoft.Testing.Extensions.Telemetry.csproj",
"src\\Platform\\Microsoft.Testing.Extensions.TrxReport.Abstractions\\Microsoft.Testing.Extensions.TrxReport.Abstractions.csproj",
"src\\Platform\\Microsoft.Testing.Platform.Browser\\Microsoft.Testing.Platform.Browser.csproj",
"src\\Platform\\Microsoft.Testing.Platform.MSBuild\\Microsoft.Testing.Platform.MSBuild.csproj",
"src\\Platform\\Microsoft.Testing.Platform\\Microsoft.Testing.Platform.csproj",
"src\\TestFramework\\TestFramework.Extensions\\TestFramework.Extensions.csproj"
]
}
}
8 changes: 8 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@
This is an early preview package, keep 1.0.0-alpha or similar suffix even in official builds.
-->
<MicrosoftTestingExtensionsVideoRecorderVersionPrefix>1.0.0</MicrosoftTestingExtensionsVideoRecorderVersionPrefix>

<MicrosoftTestingPlatformBrowserPreReleaseVersionLabel>alpha</MicrosoftTestingPlatformBrowserPreReleaseVersionLabel>

<!--
The browser launcher is independently versioned so its browser-host integration can service
Chromium cadence without coupling that cadence to Microsoft.Testing.Platform.
-->
<MicrosoftTestingPlatformBrowserVersionPrefix>0.1.0</MicrosoftTestingPlatformBrowserVersionPrefix>
</PropertyGroup>

<!-- Pack config -->
Expand Down
1 change: 1 addition & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
<PackageVersion Include="Microsoft.Testing.Extensions.AffectedTests" Version="$(MicrosoftTestingExtensionsAffectedTestsVersion)" />
<PackageVersion Include="Microsoft.Testing.Extensions.AffectedTests.Storage.AzureDevOps" Version="$(MicrosoftTestingExtensionsAffectedTestsVersion)" />
<PackageVersion Include="Microsoft.Testing.Extensions.CodeCoverage" Version="$(MicrosoftTestingExtensionsCodeCoverageVersion)" />
<PackageVersion Include="Microsoft.Playwright" Version="$(MicrosoftPlaywrightVersion)" />
<PackageVersion Include="Microsoft.TestPlatform.ObjectModel" Version="$(MicrosoftNETTestSdkVersion)" />
<PackageVersion Include="Microsoft.TestPlatform.TranslationLayer" Version="$(MicrosoftNETTestSdkVersion)" />
<PackageVersion Include="Microsoft.TestPlatform.Filter.Source" Version="$(MicrosoftTestPlatformFilterSourceVersion)" />
Expand Down
1 change: 1 addition & 0 deletions Microsoft.Testing.Platform.slnf
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"src\\Platform\\Microsoft.Testing.Extensions.VSTestBridge\\Microsoft.Testing.Extensions.VSTestBridge.csproj",
"src\\Platform\\Microsoft.Testing.Extensions.VideoRecorder\\Microsoft.Testing.Extensions.VideoRecorder.csproj",
"src\\Platform\\Microsoft.Testing.Platform.AI\\Microsoft.Testing.Platform.AI.csproj",
"src\\Platform\\Microsoft.Testing.Platform.Browser\\Microsoft.Testing.Platform.Browser.csproj",
"src\\Platform\\Microsoft.Testing.Platform.MSBuild\\Microsoft.Testing.Platform.MSBuild.csproj",
"src\\Platform\\Microsoft.Testing.Platform.ServerMode.Client.Sources\\Microsoft.Testing.Platform.ServerMode.Client.Sources.csproj",
"src\\Platform\\Microsoft.Testing.Platform\\Microsoft.Testing.Platform.csproj",
Expand Down
1 change: 1 addition & 0 deletions NonWindowsTests.slnf
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"src\\Platform\\Microsoft.Testing.Extensions.VSTestBridge\\Microsoft.Testing.Extensions.VSTestBridge.csproj",
"src\\Platform\\Microsoft.Testing.Extensions.VideoRecorder\\Microsoft.Testing.Extensions.VideoRecorder.csproj",
"src\\Platform\\Microsoft.Testing.Platform.AI\\Microsoft.Testing.Platform.AI.csproj",
"src\\Platform\\Microsoft.Testing.Platform.Browser\\Microsoft.Testing.Platform.Browser.csproj",
"src\\Platform\\Microsoft.Testing.Platform.MSBuild\\Microsoft.Testing.Platform.MSBuild.csproj",
"src\\Platform\\Microsoft.Testing.Platform.ServerMode.Client.Sources\\Microsoft.Testing.Platform.ServerMode.Client.Sources.csproj",
"src\\Platform\\Microsoft.Testing.Platform\\Microsoft.Testing.Platform.csproj",
Expand Down
1 change: 1 addition & 0 deletions TestFx.slnx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
<Project Path="src/Platform/Microsoft.Testing.Extensions.VSTestBridge/Microsoft.Testing.Extensions.VSTestBridge.csproj" />
<Project Path="src/Platform/Microsoft.Testing.Extensions.VideoRecorder/Microsoft.Testing.Extensions.VideoRecorder.csproj" />
<Project Path="src/Platform/Microsoft.Testing.Platform.AI/Microsoft.Testing.Platform.AI.csproj" />
<Project Path="src/Platform/Microsoft.Testing.Platform.Browser/Microsoft.Testing.Platform.Browser.csproj" />
<Project Path="src/Platform/Microsoft.Testing.Platform.MSBuild/Microsoft.Testing.Platform.MSBuild.csproj" />
<Project Path="src/Platform/Microsoft.Testing.Platform.ServerMode.Client.Sources/Microsoft.Testing.Platform.ServerMode.Client.Sources.csproj" />
<Project Path="src/Platform/Microsoft.Testing.Platform/Microsoft.Testing.Platform.csproj" />
Expand Down
42 changes: 42 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,48 @@ stages:
parameters:
osName: MacOS

- ${{ if eq(parameters.SkipTests, False) }}:
- job: BrowserWebAssemblyWindows
displayName: Browser WebAssembly integration Windows_x64
dependsOn: DetectChanges
condition: and(succeededOrFailed(), ne(dependencies.DetectChanges.outputs['detect.xmlDocsOnly'], 'true'), or(ne(dependencies.DetectChanges.outputs['detect.hasProductChanges'], 'false'), eq(dependencies.DetectChanges.outputs['detect.infrastructureOnly'], 'true')))
timeoutInMinutes: 120
pool:
name: NetCore-Public
demands: ImageOverride -equals windows.vs2026preview.scout.amd64.open
variables:
- template: /eng/pipelines/variables/test-env-vars.yml
- name: _BuildConfig
value: Release
- name: image
value: windows.vs2026preview.scout.amd64.open
- name: browserExecutable
value: 'C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe'
- name: BrowserResultsDirectory
value: '$(Agent.TempDirectory)/browser-ci-$(Build.BuildId)-$(System.JobName)-$(System.JobAttempt)'
steps:
- template: /eng/pipelines/steps/browser-testing.yml

- job: BrowserWebAssemblyLinux
displayName: Browser WebAssembly integration Linux_x64
dependsOn: DetectChanges
condition: and(succeededOrFailed(), ne(dependencies.DetectChanges.outputs['detect.xmlDocsOnly'], 'true'), or(ne(dependencies.DetectChanges.outputs['detect.hasProductChanges'], 'false'), eq(dependencies.DetectChanges.outputs['detect.infrastructureOnly'], 'true')))
timeoutInMinutes: 120
pool:
vmImage: ubuntu-24.04
variables:
- template: /eng/pipelines/variables/test-env-vars.yml
- name: _BuildConfig
value: Release
- name: image
value: ubuntu-24.04
- name: browserExecutable
value: '/usr/bin/google-chrome'
- name: BrowserResultsDirectory
value: '$(Agent.TempDirectory)/browser-ci-$(Build.BuildId)-$(System.JobName)-$(System.JobAttempt)'
steps:
- template: /eng/pipelines/steps/browser-testing.yml

- template: /eng/common/templates/jobs/jobs.yml
parameters:
enableMicrobuild: true
Expand Down
24 changes: 24 additions & 0 deletions eng/Signing.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,28 @@
<FileSignInfo Include="Mono.Cecil.Pdb.dll" CertificateName="3PartySHA2" />
<FileSignInfo Include="Mono.Cecil.Rocks.dll" CertificateName="3PartySHA2" />
</ItemGroup>
<ItemGroup Label="Unsigned browser runtime scripts">
<!-- Exact scripts in Microsoft.Testing.Platform.Browser's package-owned host and Playwright 1.63 driver. -->
<FileSignInfo Include="Microsoft.Testing.Platform.Browser.main.js" CertificateName="None" />
<FileSignInfo Include="bootstrap.js" CertificateName="None" />
<FileSignInfo Include="channelSessions.js" CertificateName="None" />
<FileSignInfo Include="cli.js" CertificateName="None" />
<FileSignInfo Include="cliDaemon.js" CertificateName="None" />
<FileSignInfo Include="coreBundle.js" CertificateName="None" />
<FileSignInfo Include="dashboardApp.js" CertificateName="None" />
<FileSignInfo Include="extension.js" CertificateName="None" />
<FileSignInfo Include="index.js" CertificateName="None" />
Comment thread
Copilot marked this conversation as resolved.
Resolved
<FileSignInfo Include="loader.js" CertificateName="None" />
<FileSignInfo Include="mcp.js" CertificateName="None" />
<FileSignInfo Include="minimist.js" CertificateName="None" />
<FileSignInfo Include="oopBrowserDownload.js" CertificateName="None" />
<FileSignInfo Include="output.js" CertificateName="None" />
<FileSignInfo Include="package.js" CertificateName="None" />
<FileSignInfo Include="program.js" CertificateName="None" />
<FileSignInfo Include="registry.js" CertificateName="None" />
<FileSignInfo Include="serverRegistry.js" CertificateName="None" />
<FileSignInfo Include="session.js" CertificateName="None" />
<FileSignInfo Include="socketConnection.js" CertificateName="None" />
<FileSignInfo Include="utilsBundle.js" CertificateName="None" />
</ItemGroup>
Comment thread
Copilot marked this conversation as resolved.
Resolved
</Project>
13 changes: 13 additions & 0 deletions eng/browser-testing/required-tests.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[
"BrowserPackage_DotnetTestRunsAndListsTestsThroughSdkHttpGateway",
"BrowserPackage_DefinesDedicatedBrowserRunArguments",
"BrowserPackage_SdkCancellationStopsManagedBrowserRun",
"BrowserPackage_ArtifactQuotaFailureFailsRun",
"BrowserPackage_HostAssetsAreBuildOnlyConsumerAssets",
"BrowserPackage_DesktopTestApplicationIsUnaffected",
"BrowserPackage_ContainsPrivateCrossPlatformPlaywrightRuntime",
"BrowserPackage_PackNoBuildPreservesRuntimePayload",
"BrowserPackage_PackWithoutBundledNodePreservesPrivateDriverAndLicenses",
"BrowserPackage_InvalidExplicitBrowserPathFails",
"BrowserPackage_EvaluatedPropertyIgnoresTelemetryBanner"
]
4 changes: 4 additions & 0 deletions eng/browser-testing/sdk.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"repository": "dotnet/sdk",
"commit": "df5a595b6fa32f65385bc40c8bf9506eed069f02"
}
3 changes: 3 additions & 0 deletions eng/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Param(
[string] $msbuildEngine = $null,
[bool] $warnAsError = $true,
[bool] $nodeReuse = $true,
[bool][Alias('mt')]$msbuildMultiThreaded = $true,
[switch][Alias('r')]$restore,
[switch] $deployDeps,
[switch][Alias('b')]$build,
Expand All @@ -20,6 +21,7 @@ Param(
[switch] $publish,
[switch] $clean,
[switch][Alias('bl')]$binaryLog,
[string][Alias('bln')]$binaryLogName = '',
[switch][Alias('nobl')]$excludeCIBinarylog,
[switch] $ci,
[switch] $prepareMachine,
Expand Down Expand Up @@ -83,3 +85,4 @@ $null = $PSBoundParameters.Remove("vs")
$null = $PSBoundParameters.Remove("installWindowsSdk")

& $PSScriptRoot\common\Build.ps1 @PSBoundParameters
exit $LASTEXITCODE
94 changes: 94 additions & 0 deletions eng/pipelines/steps/browser-testing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
steps:
- checkout: self
fetchDepth: 1
clean: true
persistCredentials: false

- task: PowerShell@2
displayName: Build and verify the composed browser product
inputs:
pwsh: true
targetType: inline
script: |
$ErrorActionPreference = 'Stop'
$pin = Get-Content -LiteralPath '$(Build.SourcesDirectory)/eng/browser-testing/sdk.json' -Raw | ConvertFrom-Json
if ($pin.repository -ne 'dotnet/sdk' -or $pin.commit -notmatch '^[0-9a-f]{40}$') {
throw 'The browser validation SDK counterpart must be pinned to a full dotnet/sdk SHA.'
}

$browser = '$(browserExecutable)'
if (-not (Test-Path -LiteralPath $browser -PathType Leaf)) {
throw "The required Chromium-family browser is not installed at '$browser'."
}

New-Item -ItemType Directory -Path '$(Build.SourcesDirectory)/artifacts/log' -Force | Out-Null
$sdkRoot = if ($IsWindows) {
$driveRoot = [IO.Path]::GetPathRoot('$(Build.SourcesDirectory)')
Join-Path $driveRoot 'bsi'
} else {
"/tmp/bsi-$(Build.BuildId)-$(System.JobAttempt)"
}
if (Test-Path -LiteralPath $sdkRoot) {
throw "The clean SDK checkout path already exists: '$sdkRoot'."
}

git init --quiet $sdkRoot
if ($LASTEXITCODE -ne 0) { throw 'Unable to initialize the SDK checkout.' }
git -C $sdkRoot config core.longpaths true
if ($LASTEXITCODE -ne 0) { throw 'Unable to enable long paths for the disposable SDK checkout.' }
git -C $sdkRoot remote add origin "https://github.com/$($pin.repository).git"
if ($LASTEXITCODE -ne 0) { throw 'Unable to configure the SDK checkout.' }
git -C $sdkRoot fetch --depth 1 origin $pin.commit
if ($LASTEXITCODE -ne 0) { throw 'Unable to fetch the pinned SDK commit.' }
git -C $sdkRoot checkout --quiet --detach FETCH_HEAD
if ($LASTEXITCODE -ne 0) { throw 'Unable to check out the pinned SDK commit.' }
$actualCommit = (git -C $sdkRoot rev-parse HEAD).Trim()
if ($LASTEXITCODE -ne 0 -or $actualCommit -ne $pin.commit) {
throw "The SDK checkout '$actualCommit' does not match the pin '$($pin.commit)'."
}

& (Join-Path $sdkRoot 'eng/browser-testing/TestResultValidation.ps1')
if ($LASTEXITCODE -ne 0) { throw 'The SDK browser-result validator self-tests failed.' }
& (Join-Path $sdkRoot 'eng/browser-testing/RunBrowserTests.ps1') `
-SdkRoot $sdkRoot `
-TestFxRoot '$(Build.SourcesDirectory)' `
-BrowserExecutable $browser `
-Configuration Release `
-ResultsDirectory '$(BrowserResultsDirectory)'
if ($LASTEXITCODE -ne 0) { throw 'The composed browser validation failed.' }

- task: PublishTestResults@2
displayName: Publish mandatory browser acceptance results
condition: always()
inputs:
testResultsFormat: VSTest
testResultsFiles: '$(BrowserResultsDirectory)/test-results/browser.trx'
testRunTitle: 'Browser WebAssembly ($(image))'
failTaskOnFailedTests: true
failTaskOnMissingResultsFile: true

- pwsh: |
$hasEvidence = Test-Path -LiteralPath '$(BrowserResultsDirectory)' -PathType Container
Write-Host "Browser evidence under '$(BrowserResultsDirectory)': $hasEvidence"
Write-Host "##vso[task.setvariable variable=HasBrowserEvidence]$($hasEvidence.ToString().ToLowerInvariant())"
displayName: Check for composed browser evidence
condition: always()

- task: CopyFiles@2
displayName: Collect composed browser diagnostics
condition: and(always(), eq(variables.HasBrowserEvidence, 'true'))
inputs:
SourceFolder: '$(BrowserResultsDirectory)'
Contents: |
**/*.log
**/*.json
**/*.trx
**/*.binlog
TargetFolder: '$(Build.ArtifactStagingDirectory)/browser-ci'

- task: PublishPipelineArtifact@1
displayName: Publish composed browser diagnostics
condition: and(always(), eq(variables.HasBrowserEvidence, 'true'))
inputs:
targetPath: '$(Build.ArtifactStagingDirectory)/browser-ci'
artifact: 'Browser_$(image)_Attempt$(System.JobAttempt)'
12 changes: 5 additions & 7 deletions eng/verify-nupkgs.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,11 @@ function Confirm-NugetPackages {
}
}

$isMSTestProductBuild = $false
foreach ($expectedPackageKey in $expectedNumOfFiles.Keys) {
if ($verifiedPackageKeys.Contains($expectedPackageKey)) {
$isMSTestProductBuild = $true
break
}
}
# Leaf packages can be packed independently through the supported -projects
# build option. The umbrella packages identify a complete MSTest product build.
$isMSTestProductBuild =
$verifiedPackageKeys.Contains("MSTest.Sdk") -or
$verifiedPackageKeys.Contains("MSTest")
Comment thread
Copilot marked this conversation as resolved.
Resolved

if ($isMSTestProductBuild) {
foreach ($expectedPackageKey in $expectedNumOfFiles.Keys) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

namespace Microsoft.Testing.Platform.Browser;

internal static class BoundedResourceCleanup
{
public static async Task<T?> ObserveCreationAsync<T>(
Task<T> creationTask,
TimeSpan timeout,
Action<T> dispose,
Action<string> report)
where T : class
{
try
{
return await creationTask.WaitAsync(timeout).ConfigureAwait(false);
}
catch (TimeoutException)
{
report("Resource creation did not finish during bounded cleanup; disposal will continue in the background.");
_ = DisposeWhenCreatedAsync(creationTask, timeout, dispose, report);
return null;
}
catch (Exception ex)
{
report($"Resource creation failed during cleanup: {ex.Message}");
return null;
}
}

public static async Task DisposeAsync(
Action dispose,
TimeSpan timeout,
Action<string> report)
{
try
{
await Task.Run(dispose).WaitAsync(timeout).ConfigureAwait(false);
}
catch (Exception ex)
{
report($"Resource disposal did not complete cleanly: {ex.Message}");
}
}

private static async Task DisposeWhenCreatedAsync<T>(
Task<T> creationTask,
TimeSpan timeout,
Action<T> dispose,
Action<string> report)
{
try
{
T resource = await creationTask.ConfigureAwait(false);
await DisposeAsync(() => dispose(resource), timeout, report).ConfigureAwait(false);
}
catch (Exception ex)
{
report($"Late resource creation could not be cleaned up: {ex.Message}");
}
}
}
Loading
Loading