diff --git a/src/mono/wasm/Wasm.Build.Tests/Blazor/AssetCachingTests.cs b/src/mono/wasm/Wasm.Build.Tests/Blazor/AssetCachingTests.cs index c6c4988dca8768..22ee79b8d3b764 100644 --- a/src/mono/wasm/Wasm.Build.Tests/Blazor/AssetCachingTests.cs +++ b/src/mono/wasm/Wasm.Build.Tests/Blazor/AssetCachingTests.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.IO; using System.Text.RegularExpressions; +using System.Threading; using System.Threading.Tasks; using Microsoft.Playwright; using Xunit; @@ -22,7 +23,6 @@ public AssetCachingTests(ITestOutputHelper output, SharedBuildPerTestClassFixtur } [Fact, TestCategory("no-fingerprinting")] - [ActiveIssue("https://github.com/dotnet/runtime/issues/122338")] // add it back to eng\testing\scenarios\BuildWasmAppsJobsList.txt public async Task BlazorApp_BasedOnFingerprinting_LoadsWasmAssetsFromCache() { var project = CopyTestAsset( @@ -35,7 +35,9 @@ public async Task BlazorApp_BasedOnFingerprinting_LoadsWasmAssetsFromCache() (string projectDir, string output) = BlazorPublish(project, Configuration.Release, new PublishOptions(AssertAppBundle: false)); - var counterLoaded = new TaskCompletionSource(); + var firstCounterLoaded = new TaskCompletionSource(); + var secondCounterLoaded = new TaskCompletionSource(); + var loadCount = 0; var wasmRequestRecorder = new WasmRequestRecorder(); var runOptions = new BlazorRunOptions(Configuration.Release) @@ -45,23 +47,28 @@ public async Task BlazorApp_BasedOnFingerprinting_LoadsWasmAssetsFromCache() OnConsoleMessage = (type, msg) => { if (msg.Contains("Counter.OnAfterRender")) - counterLoaded.SetResult(); + { + var count = Interlocked.Increment(ref loadCount); + if (count == 1) + firstCounterLoaded.SetResult(); + else if (count == 2) + secondCounterLoaded.SetResult(); + } }, Test = async (page) => { - await counterLoaded.Task; + await firstCounterLoaded.Task; // Check server request logs after the first load. Assert.NotEmpty(wasmRequestRecorder.ResponseCodes); Assert.All(wasmRequestRecorder.ResponseCodes, r => Assert.Equal(200, r.ResponseCode)); wasmRequestRecorder.ResponseCodes.Clear(); - counterLoaded = new(); // Perform browser navigation to cause resource reload. // We use the initial base URL because the test server is not configured for SPA routing. await page.ReloadAsync(); - await counterLoaded.Task; + await secondCounterLoaded.Task; // Check server logs after the second load. if (EnvironmentVariables.UseFingerprinting)