From 919fc99aba775997f2341483be7a43b3ca8a9218 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Fri, 14 Jul 2023 15:20:26 +0200 Subject: [PATCH 01/17] Download retry for blazor case --- src/mono/wasm/runtime/loader/blazor/_Integration.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/mono/wasm/runtime/loader/blazor/_Integration.ts b/src/mono/wasm/runtime/loader/blazor/_Integration.ts index 8e5879770618b9..2cfdaac4e4f75c 100644 --- a/src/mono/wasm/runtime/loader/blazor/_Integration.ts +++ b/src/mono/wasm/runtime/loader/blazor/_Integration.ts @@ -30,7 +30,7 @@ export async function initializeBootConfig(bootConfigResult: BootConfigResult, m } let resourcesLoaded = 0; -let totalResources = 0; +const totalResources = new Set(); const behaviorByName = (name: string): AssetBehaviours | "other" => { return name === "dotnet.native.wasm" ? "dotnetwasm" @@ -61,13 +61,12 @@ export function setupModuleForBlazor(module: DotnetModuleInternal) { const type = monoToBlazorAssetTypeMap[asset.behavior]; if (type !== undefined) { const res = resourceLoader.loadResource(asset.name, asset.resolvedUrl!, asset.hash!, type); - asset.pendingDownload = res; - totalResources++; + totalResources.add(asset.name!); res.response.then(() => { resourcesLoaded++; if (module.onDownloadResourceProgress) - module.onDownloadResourceProgress(resourcesLoaded, totalResources); + module.onDownloadResourceProgress(resourcesLoaded, totalResources.size); }); return res; From f7c2976c4cfc17d61d3a51ddc7df7fb18db9854f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Fri, 14 Jul 2023 15:20:51 +0200 Subject: [PATCH 02/17] WBT for checking download progress --- .../DownloadResourceProgressTests.cs | 39 +++++++++++++++++++ .../WasmBasicTestApp/wwwroot/main.js | 14 +++++++ 2 files changed, 53 insertions(+) create mode 100644 src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/DownloadResourceProgressTests.cs diff --git a/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/DownloadResourceProgressTests.cs b/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/DownloadResourceProgressTests.cs new file mode 100644 index 00000000000000..1ea0cabdfa99af --- /dev/null +++ b/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/DownloadResourceProgressTests.cs @@ -0,0 +1,39 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Threading.Tasks; +using Xunit; +using Xunit.Abstractions; + +#nullable enable + +namespace Wasm.Build.Tests.TestAppScenarios; + +public class DownloadResourceProgressTests : AppTestBase +{ + public AppSettingsTests(ITestOutputHelper output, SharedBuildPerTestClassFixture buildContext) + : base(output, buildContext) + { + } + + [Fact] + public async Task DownloadProgressFinishes() + { + CopyTestAsset("WasmBasicTestApp", "DownloadResourceProgressTests"); + PublishProject("Debug"); + + var result = await RunSdkStyleApp(new( + Configuration: "Debug", + ForPublish: true, + TestScenario: "DownloadResourceProgressTest" + )); + Assert.Collection( + result.TestOutput, + m => Assert.Equal("DownloadResourceProgress: Finished", m), + ); + } +} diff --git a/src/mono/wasm/testassets/WasmBasicTestApp/wwwroot/main.js b/src/mono/wasm/testassets/WasmBasicTestApp/wwwroot/main.js index 127d506e3c9a6d..233701606693f2 100644 --- a/src/mono/wasm/testassets/WasmBasicTestApp/wwwroot/main.js +++ b/src/mono/wasm/testassets/WasmBasicTestApp/wwwroot/main.js @@ -10,6 +10,10 @@ if (testCase == null) { exit(2, new Error("Missing test scenario. Supply query argument 'test'.")); } +function testOutput(msg) { + console.log(`TestOutput -> ${msg}}`); +} + // Prepare base runtime parameters dotnet .withElementOnExit() @@ -21,6 +25,16 @@ switch (testCase) { case "AppSettingsTest": dotnet.withApplicationEnvironment(params.get("applicationEnvironment")); break; + case "DownloadResourceProgressTest": + dotnet.witModuleConfig({ + onDownloadResourceProgress: (loaded, total) => { + console.log(`DownloadResourceProgress: ${loaded} / ${total}`); + if (loaded === total && loaded !== 0) { + testOutput("DownloadResourceProgress: Finished"); + } + } + }); + break; } const { getAssemblyExports, getConfig, INTERNAL } = await dotnet.create(); From 1dc2aad5bd8e418e93100bfee4e5b38cb81a6acf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Fri, 14 Jul 2023 15:24:13 +0200 Subject: [PATCH 03/17] Simulate fetch failure --- src/mono/wasm/testassets/WasmBasicTestApp/wwwroot/main.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/mono/wasm/testassets/WasmBasicTestApp/wwwroot/main.js b/src/mono/wasm/testassets/WasmBasicTestApp/wwwroot/main.js index 233701606693f2..e1461dc9635c25 100644 --- a/src/mono/wasm/testassets/WasmBasicTestApp/wwwroot/main.js +++ b/src/mono/wasm/testassets/WasmBasicTestApp/wwwroot/main.js @@ -26,6 +26,14 @@ switch (testCase) { dotnet.withApplicationEnvironment(params.get("applicationEnvironment")); break; case "DownloadResourceProgressTest": + let hasFetchFailed = false; + dotnet.withLoadBootResource((type, name, defaultUri, integrity) => { + if (hasFetchFailed || type !== "assembly") + return fetch(defaultUri, { integrity: integrity, cache: 'no-cache' }); + + hasFetchFailed = true; + throw new Error("Simulating a failed fetch"); + }); dotnet.witModuleConfig({ onDownloadResourceProgress: (loaded, total) => { console.log(`DownloadResourceProgress: ${loaded} / ${total}`); From 570272df4bfa1f49c78d8172152c54635c5dc6c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Fri, 14 Jul 2023 15:26:12 +0200 Subject: [PATCH 04/17] Simulate fetch failure --- .../DownloadResourceProgressTests.cs | 9 ++++++--- .../testassets/WasmBasicTestApp/wwwroot/main.js | 16 +++++++++------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/DownloadResourceProgressTests.cs b/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/DownloadResourceProgressTests.cs index 1ea0cabdfa99af..f1363408e6b01f 100644 --- a/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/DownloadResourceProgressTests.cs +++ b/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/DownloadResourceProgressTests.cs @@ -20,8 +20,10 @@ public AppSettingsTests(ITestOutputHelper output, SharedBuildPerTestClassFixture { } - [Fact] - public async Task DownloadProgressFinishes() + [Theory] + [InlineData(false)] + [InlineData(true)] + public async Task DownloadProgressFinishes(bool fetchFailure) { CopyTestAsset("WasmBasicTestApp", "DownloadResourceProgressTests"); PublishProject("Debug"); @@ -29,7 +31,8 @@ public async Task DownloadProgressFinishes() var result = await RunSdkStyleApp(new( Configuration: "Debug", ForPublish: true, - TestScenario: "DownloadResourceProgressTest" + TestScenario: "DownloadResourceProgressTest", + BrowserQueryString: new Dictionary { ["fetchFailure"] = fetchFailure.ToString() } )); Assert.Collection( result.TestOutput, diff --git a/src/mono/wasm/testassets/WasmBasicTestApp/wwwroot/main.js b/src/mono/wasm/testassets/WasmBasicTestApp/wwwroot/main.js index e1461dc9635c25..79ac099b567836 100644 --- a/src/mono/wasm/testassets/WasmBasicTestApp/wwwroot/main.js +++ b/src/mono/wasm/testassets/WasmBasicTestApp/wwwroot/main.js @@ -26,14 +26,16 @@ switch (testCase) { dotnet.withApplicationEnvironment(params.get("applicationEnvironment")); break; case "DownloadResourceProgressTest": - let hasFetchFailed = false; - dotnet.withLoadBootResource((type, name, defaultUri, integrity) => { - if (hasFetchFailed || type !== "assembly") - return fetch(defaultUri, { integrity: integrity, cache: 'no-cache' }); + if (params.get("fetchFailure") === "true") { + let hasFetchFailed = false; + dotnet.withLoadBootResource((type, name, defaultUri, integrity) => { + if (hasFetchFailed || type !== "assembly") + return fetch(defaultUri, { integrity: integrity, cache: 'no-cache' }); - hasFetchFailed = true; - throw new Error("Simulating a failed fetch"); - }); + hasFetchFailed = true; + throw new Error("Simulating a failed fetch"); + }); + } dotnet.witModuleConfig({ onDownloadResourceProgress: (loaded, total) => { console.log(`DownloadResourceProgress: ${loaded} / ${total}`); From 71269b3317f3830389ecacf8e4e025aa56b97c6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Fri, 14 Jul 2023 18:16:20 +0200 Subject: [PATCH 05/17] Register WBT --- eng/testing/scenarios/BuildWasmAppsJobsList.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/eng/testing/scenarios/BuildWasmAppsJobsList.txt b/eng/testing/scenarios/BuildWasmAppsJobsList.txt index ee53644517fe7e..a0d669e53e94fd 100644 --- a/eng/testing/scenarios/BuildWasmAppsJobsList.txt +++ b/eng/testing/scenarios/BuildWasmAppsJobsList.txt @@ -30,3 +30,4 @@ Wasm.Build.Tests.WasmTemplateTests Wasm.Build.Tests.TestAppScenarios.LazyLoadingTests Wasm.Build.Tests.TestAppScenarios.LibraryInitializerTests Wasm.Build.Tests.TestAppScenarios.SatelliteLoadingTests +Wasm.Build.Tests.TestAppScenarios.DownloadResourceProgressTests From cfda22fadb54daa3d1468ca92971d84d190df622 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Fri, 14 Jul 2023 18:17:55 +0200 Subject: [PATCH 06/17] Fix typo --- .../TestAppScenarios/DownloadResourceProgressTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/DownloadResourceProgressTests.cs b/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/DownloadResourceProgressTests.cs index f1363408e6b01f..8edde072cc0170 100644 --- a/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/DownloadResourceProgressTests.cs +++ b/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/DownloadResourceProgressTests.cs @@ -36,7 +36,7 @@ public async Task DownloadProgressFinishes(bool fetchFailure) )); Assert.Collection( result.TestOutput, - m => Assert.Equal("DownloadResourceProgress: Finished", m), + m => Assert.Equal("DownloadResourceProgress: Finished", m) ); } } From aef0bd6d964eff7ccb0335e94ecdf6fd158758cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Fri, 14 Jul 2023 19:50:02 +0200 Subject: [PATCH 07/17] Fix typo (2) --- .../TestAppScenarios/DownloadResourceProgressTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/DownloadResourceProgressTests.cs b/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/DownloadResourceProgressTests.cs index 8edde072cc0170..81afdea8cf7a57 100644 --- a/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/DownloadResourceProgressTests.cs +++ b/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/DownloadResourceProgressTests.cs @@ -15,7 +15,7 @@ namespace Wasm.Build.Tests.TestAppScenarios; public class DownloadResourceProgressTests : AppTestBase { - public AppSettingsTests(ITestOutputHelper output, SharedBuildPerTestClassFixture buildContext) + public DownloadResourceProgressTests(ITestOutputHelper output, SharedBuildPerTestClassFixture buildContext) : base(output, buildContext) { } From 622e2deb8c729b6b6c7d5df4ec60707867ef3b59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Fri, 14 Jul 2023 21:10:41 +0200 Subject: [PATCH 08/17] Ehm... make the test work --- .../DownloadResourceProgressTests.cs | 9 +++++---- .../testassets/WasmBasicTestApp/wwwroot/main.js | 13 ++++++++++--- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/DownloadResourceProgressTests.cs b/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/DownloadResourceProgressTests.cs index 81afdea8cf7a57..af8019032d6f08 100644 --- a/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/DownloadResourceProgressTests.cs +++ b/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/DownloadResourceProgressTests.cs @@ -34,9 +34,10 @@ public async Task DownloadProgressFinishes(bool fetchFailure) TestScenario: "DownloadResourceProgressTest", BrowserQueryString: new Dictionary { ["fetchFailure"] = fetchFailure.ToString() } )); - Assert.Collection( - result.TestOutput, - m => Assert.Equal("DownloadResourceProgress: Finished", m) - ); + Assert.True(result.TestOutput.Any(o => o == "DownloadResourceProgress: Finished")); + // Assert.Collection( + // result.TestOutput, + // m => Assert.Equal("DownloadResourceProgress: Finished", m) + // ); } } diff --git a/src/mono/wasm/testassets/WasmBasicTestApp/wwwroot/main.js b/src/mono/wasm/testassets/WasmBasicTestApp/wwwroot/main.js index 79ac099b567836..ab2575e9fe3bf3 100644 --- a/src/mono/wasm/testassets/WasmBasicTestApp/wwwroot/main.js +++ b/src/mono/wasm/testassets/WasmBasicTestApp/wwwroot/main.js @@ -11,7 +11,7 @@ if (testCase == null) { } function testOutput(msg) { - console.log(`TestOutput -> ${msg}}`); + console.log(`TestOutput -> ${msg}`); } // Prepare base runtime parameters @@ -28,7 +28,7 @@ switch (testCase) { case "DownloadResourceProgressTest": if (params.get("fetchFailure") === "true") { let hasFetchFailed = false; - dotnet.withLoadBootResource((type, name, defaultUri, integrity) => { + dotnet.withResourceLoader((type, name, defaultUri, integrity) => { if (hasFetchFailed || type !== "assembly") return fetch(defaultUri, { integrity: integrity, cache: 'no-cache' }); @@ -36,7 +36,7 @@ switch (testCase) { throw new Error("Simulating a failed fetch"); }); } - dotnet.witModuleConfig({ + dotnet.withModuleConfig({ onDownloadResourceProgress: (loaded, total) => { console.log(`DownloadResourceProgress: ${loaded} / ${total}`); if (loaded === total && loaded !== 0) { @@ -72,6 +72,13 @@ try { exports.AppSettingsTest.Run(); exit(0); break; + case "DownloadResourceProgressTest": + exit(0); + break; + default: + console.error(`Unknown test case: ${testCase}`); + exit(3); + break; } } catch (e) { exit(1, e); From 62b577ac717251d6bd22fb758f078828c371d5e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Fri, 14 Jul 2023 21:40:36 +0200 Subject: [PATCH 09/17] Fix --- .../TestAppScenarios/DownloadResourceProgressTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/DownloadResourceProgressTests.cs b/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/DownloadResourceProgressTests.cs index af8019032d6f08..0e59e8ea039569 100644 --- a/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/DownloadResourceProgressTests.cs +++ b/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/DownloadResourceProgressTests.cs @@ -34,7 +34,7 @@ public async Task DownloadProgressFinishes(bool fetchFailure) TestScenario: "DownloadResourceProgressTest", BrowserQueryString: new Dictionary { ["fetchFailure"] = fetchFailure.ToString() } )); - Assert.True(result.TestOutput.Any(o => o == "DownloadResourceProgress: Finished")); + Assert.True(result.TestOutput.Any(m => m.Contains("DownloadResourceProgress: Finished")), "The download progress test didn't emit expected error message"); // Assert.Collection( // result.TestOutput, // m => Assert.Equal("DownloadResourceProgress: Finished", m) From d93f5bf1307431c9e3831a533f7577d9058bb9c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Fri, 14 Jul 2023 21:54:48 +0200 Subject: [PATCH 10/17] Export type DotnetHostBuilder --- src/mono/wasm/runtime/dotnet.d.ts | 2 +- src/mono/wasm/runtime/types/export-types.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/mono/wasm/runtime/dotnet.d.ts b/src/mono/wasm/runtime/dotnet.d.ts index 6d55a73a3cc936..61a764bd71068d 100644 --- a/src/mono/wasm/runtime/dotnet.d.ts +++ b/src/mono/wasm/runtime/dotnet.d.ts @@ -433,4 +433,4 @@ declare global { } declare const createDotnetRuntime: CreateDotnetRuntimeType; -export { AssetEntry, CreateDotnetRuntimeType, DotnetModuleConfig, EmscriptenModule, GlobalizationMode, IMemoryView, ModuleAPI, MonoConfig, ResourceRequest, RuntimeAPI, createDotnetRuntime as default, dotnet, exit }; +export { AssetEntry, CreateDotnetRuntimeType, DotnetHostBuilder, DotnetModuleConfig, EmscriptenModule, GlobalizationMode, IMemoryView, ModuleAPI, MonoConfig, ResourceRequest, RuntimeAPI, createDotnetRuntime as default, dotnet, exit }; diff --git a/src/mono/wasm/runtime/types/export-types.ts b/src/mono/wasm/runtime/types/export-types.ts index aa7f7e09d2db09..af00c844e40daa 100644 --- a/src/mono/wasm/runtime/types/export-types.ts +++ b/src/mono/wasm/runtime/types/export-types.ts @@ -2,7 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. import type { IMemoryView } from "../marshal"; -import type { CreateDotnetRuntimeType, DotnetModuleConfig, RuntimeAPI, MonoConfig, ModuleAPI, AssetEntry, ResourceRequest, GlobalizationMode } from "."; +import type { CreateDotnetRuntimeType, DotnetHostBuilder, DotnetModuleConfig, RuntimeAPI, MonoConfig, ModuleAPI, AssetEntry, ResourceRequest, GlobalizationMode } from "."; import type { EmscriptenModule } from "./emscripten"; import type { dotnet, exit } from "../loader/index"; @@ -21,6 +21,6 @@ export default createDotnetRuntime; export { EmscriptenModule, - RuntimeAPI, ModuleAPI, DotnetModuleConfig, CreateDotnetRuntimeType, MonoConfig, IMemoryView, AssetEntry, ResourceRequest, GlobalizationMode, + RuntimeAPI, ModuleAPI, DotnetHostBuilder, DotnetModuleConfig, CreateDotnetRuntimeType, MonoConfig, IMemoryView, AssetEntry, ResourceRequest, GlobalizationMode, dotnet, exit }; From f653b0a56eea2c9280235edabacfad5709978b83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Fri, 14 Jul 2023 21:55:52 +0200 Subject: [PATCH 11/17] Remove commented code --- .../TestAppScenarios/DownloadResourceProgressTests.cs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/DownloadResourceProgressTests.cs b/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/DownloadResourceProgressTests.cs index 0e59e8ea039569..de5cdaa6cb609c 100644 --- a/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/DownloadResourceProgressTests.cs +++ b/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/DownloadResourceProgressTests.cs @@ -35,9 +35,5 @@ public async Task DownloadProgressFinishes(bool fetchFailure) BrowserQueryString: new Dictionary { ["fetchFailure"] = fetchFailure.ToString() } )); Assert.True(result.TestOutput.Any(m => m.Contains("DownloadResourceProgress: Finished")), "The download progress test didn't emit expected error message"); - // Assert.Collection( - // result.TestOutput, - // m => Assert.Equal("DownloadResourceProgress: Finished", m) - // ); } } From 989ee2c955c2b85a79dd058b887a4ac6a140899f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Fri, 14 Jul 2023 22:54:44 +0200 Subject: [PATCH 12/17] Log URL that is being opened for test. Fix fetchFailure param casing --- .../wasm/Wasm.Build.Tests/TestAppScenarios/AppTestBase.cs | 7 ++++++- .../TestAppScenarios/DownloadResourceProgressTests.cs | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/AppTestBase.cs b/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/AppTestBase.cs index 2e0907344000c5..5cca72d2202696 100644 --- a/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/AppTestBase.cs +++ b/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/AppTestBase.cs @@ -79,7 +79,12 @@ protected async Task RunSdkStyleApp(RunOptions options) if (options.BrowserQueryString != null) queryString += "&" + string.Join("&", options.BrowserQueryString.Select(kvp => $"{kvp.Key}={kvp.Value}")); - page = await runner.RunAsync(runCommand, runArgs, onConsoleMessage: OnConsoleMessage, modifyBrowserUrl: url => url + queryString); + page = await runner.RunAsync(runCommand, runArgs, onConsoleMessage: OnConsoleMessage, modifyBrowserUrl: url => + { + url += queryString; + _testOutput.WriteLine($"Opening browser at {url}"); + return url; + }); void OnConsoleMessage(IConsoleMessage msg) { diff --git a/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/DownloadResourceProgressTests.cs b/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/DownloadResourceProgressTests.cs index de5cdaa6cb609c..208e74628a9364 100644 --- a/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/DownloadResourceProgressTests.cs +++ b/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/DownloadResourceProgressTests.cs @@ -32,7 +32,7 @@ public async Task DownloadProgressFinishes(bool fetchFailure) Configuration: "Debug", ForPublish: true, TestScenario: "DownloadResourceProgressTest", - BrowserQueryString: new Dictionary { ["fetchFailure"] = fetchFailure.ToString() } + BrowserQueryString: new Dictionary { ["fetchFailure"] = fetchFailure.ToString().ToLowerInvariant() } )); Assert.True(result.TestOutput.Any(m => m.Contains("DownloadResourceProgress: Finished")), "The download progress test didn't emit expected error message"); } From 8f38e659610f61b46da8c7f81abc1badc30e8d55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Fri, 14 Jul 2023 23:01:42 +0200 Subject: [PATCH 13/17] Throw silent error so the withExitOnUnhandledError won't kill the app --- src/mono/wasm/testassets/WasmBasicTestApp/wwwroot/main.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/mono/wasm/testassets/WasmBasicTestApp/wwwroot/main.js b/src/mono/wasm/testassets/WasmBasicTestApp/wwwroot/main.js index ab2575e9fe3bf3..83c02855d0a30e 100644 --- a/src/mono/wasm/testassets/WasmBasicTestApp/wwwroot/main.js +++ b/src/mono/wasm/testassets/WasmBasicTestApp/wwwroot/main.js @@ -33,7 +33,9 @@ switch (testCase) { return fetch(defaultUri, { integrity: integrity, cache: 'no-cache' }); hasFetchFailed = true; - throw new Error("Simulating a failed fetch"); + const error = new Error("Simulating a failed fetch"); + error.silent = true; + throw error; }); } dotnet.withModuleConfig({ From 2265d4e2d15f12eb9b021a5d5b7a805d619d1e1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Fri, 14 Jul 2023 23:58:13 +0200 Subject: [PATCH 14/17] Rename parameter. Check that failed fetch happened --- .../TestAppScenarios/DownloadResourceProgressTests.cs | 10 ++++++++-- .../wasm/testassets/WasmBasicTestApp/wwwroot/main.js | 9 +++++---- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/DownloadResourceProgressTests.cs b/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/DownloadResourceProgressTests.cs index 208e74628a9364..851f897731997d 100644 --- a/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/DownloadResourceProgressTests.cs +++ b/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/DownloadResourceProgressTests.cs @@ -23,7 +23,7 @@ public DownloadResourceProgressTests(ITestOutputHelper output, SharedBuildPerTes [Theory] [InlineData(false)] [InlineData(true)] - public async Task DownloadProgressFinishes(bool fetchFailure) + public async Task DownloadProgressFinishes(bool failFirstAssemblyDownload) { CopyTestAsset("WasmBasicTestApp", "DownloadResourceProgressTests"); PublishProject("Debug"); @@ -32,8 +32,14 @@ public async Task DownloadProgressFinishes(bool fetchFailure) Configuration: "Debug", ForPublish: true, TestScenario: "DownloadResourceProgressTest", - BrowserQueryString: new Dictionary { ["fetchFailure"] = fetchFailure.ToString().ToLowerInvariant() } + BrowserQueryString: new Dictionary { ["failFirstAssemblyDownload"] = failFirstAssemblyDownload.ToString().ToLowerInvariant() } )); Assert.True(result.TestOutput.Any(m => m.Contains("DownloadResourceProgress: Finished")), "The download progress test didn't emit expected error message"); + Assert.True( + result.TestOutput.Any(m => m.Contains("Throw error instead of downloading resource") == failFirstAssemblyDownload), + failFirstAssemblyDownload + ? "The download progress test didn't emit expected message about failing download" + : "The download progress test did emit unexpected message about failing download" + ); } } diff --git a/src/mono/wasm/testassets/WasmBasicTestApp/wwwroot/main.js b/src/mono/wasm/testassets/WasmBasicTestApp/wwwroot/main.js index 83c02855d0a30e..ace55e5c78c649 100644 --- a/src/mono/wasm/testassets/WasmBasicTestApp/wwwroot/main.js +++ b/src/mono/wasm/testassets/WasmBasicTestApp/wwwroot/main.js @@ -26,13 +26,14 @@ switch (testCase) { dotnet.withApplicationEnvironment(params.get("applicationEnvironment")); break; case "DownloadResourceProgressTest": - if (params.get("fetchFailure") === "true") { - let hasFetchFailed = false; + if (params.get("failFirstAssemblyDownload") === "true") { + let hasFailedFetch = false; dotnet.withResourceLoader((type, name, defaultUri, integrity) => { - if (hasFetchFailed || type !== "assembly") + if (hasFailedFetch || type !== "assembly") return fetch(defaultUri, { integrity: integrity, cache: 'no-cache' }); - hasFetchFailed = true; + testOutput("Throw error instead of downloading resource"); + hasFailedFetch = true; const error = new Error("Simulating a failed fetch"); error.silent = true; throw error; From d217786197be89cc265edef7bbc6e6c9ddfea746 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Wed, 19 Jul 2023 11:27:08 +0200 Subject: [PATCH 15/17] Check retry download message --- .../DownloadResourceProgressTests.cs | 15 ++++++++++++++- src/mono/wasm/runtime/loader/assets.ts | 3 +++ .../testassets/WasmBasicTestApp/wwwroot/main.js | 2 +- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/DownloadResourceProgressTests.cs b/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/DownloadResourceProgressTests.cs index 851f897731997d..c41d2875c02114 100644 --- a/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/DownloadResourceProgressTests.cs +++ b/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/DownloadResourceProgressTests.cs @@ -34,7 +34,20 @@ public async Task DownloadProgressFinishes(bool failFirstAssemblyDownload) TestScenario: "DownloadResourceProgressTest", BrowserQueryString: new Dictionary { ["failFirstAssemblyDownload"] = failFirstAssemblyDownload.ToString().ToLowerInvariant() } )); - Assert.True(result.TestOutput.Any(m => m.Contains("DownloadResourceProgress: Finished")), "The download progress test didn't emit expected error message"); + Assert.True( + result.TestOutput.Any(m => m.Contains("DownloadResourceProgress: Finished")), + "The download progress test didn't emit expected error message" + ); + Assert.True( + result.ConsoleOutput.Any(m => m.Contains("Retrying download")) == failFirstAssemblyDownload, + failFirstAssemblyDownload + ? "The download progress test didn't emit expected message about retrying download" + : "The download progress test did emit unexpected message about retrying download" + ); + Assert.False( + result.ConsoleOutput.Any(m => m.Contains("Retrying download (2)")), + "The download progress test did emit unexpected message about second download retry" + ); Assert.True( result.TestOutput.Any(m => m.Contains("Throw error instead of downloading resource") == failFirstAssemblyDownload), failFirstAssemblyDownload diff --git a/src/mono/wasm/runtime/loader/assets.ts b/src/mono/wasm/runtime/loader/assets.ts index 0f6ab16d464cb3..b5a1b219b8e9f7 100644 --- a/src/mono/wasm/runtime/loader/assets.ts +++ b/src/mono/wasm/runtime/loader/assets.ts @@ -228,11 +228,14 @@ export async function start_asset_download(asset: AssetEntryInternal): Promise { + dotnet.withDiagnosticTracing(true).withResourceLoader((type, name, defaultUri, integrity) => { if (hasFailedFetch || type !== "assembly") return fetch(defaultUri, { integrity: integrity, cache: 'no-cache' }); From eb8c3e071c1aec641c142893f89d3e8710f17608 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Wed, 19 Jul 2023 11:37:05 +0200 Subject: [PATCH 16/17] Random assembly failure --- .../DownloadResourceProgressTests.cs | 12 ++++++------ .../wasm/testassets/WasmBasicTestApp/wwwroot/main.js | 9 +++++---- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/DownloadResourceProgressTests.cs b/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/DownloadResourceProgressTests.cs index c41d2875c02114..3d47d155008b2d 100644 --- a/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/DownloadResourceProgressTests.cs +++ b/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/DownloadResourceProgressTests.cs @@ -23,7 +23,7 @@ public DownloadResourceProgressTests(ITestOutputHelper output, SharedBuildPerTes [Theory] [InlineData(false)] [InlineData(true)] - public async Task DownloadProgressFinishes(bool failFirstAssemblyDownload) + public async Task DownloadProgressFinishes(bool failSingleAssemblyDownload) { CopyTestAsset("WasmBasicTestApp", "DownloadResourceProgressTests"); PublishProject("Debug"); @@ -32,15 +32,15 @@ public async Task DownloadProgressFinishes(bool failFirstAssemblyDownload) Configuration: "Debug", ForPublish: true, TestScenario: "DownloadResourceProgressTest", - BrowserQueryString: new Dictionary { ["failFirstAssemblyDownload"] = failFirstAssemblyDownload.ToString().ToLowerInvariant() } + BrowserQueryString: new Dictionary { ["failSingleAssemblyDownload"] = failSingleAssemblyDownload.ToString().ToLowerInvariant() } )); Assert.True( result.TestOutput.Any(m => m.Contains("DownloadResourceProgress: Finished")), "The download progress test didn't emit expected error message" ); Assert.True( - result.ConsoleOutput.Any(m => m.Contains("Retrying download")) == failFirstAssemblyDownload, - failFirstAssemblyDownload + result.ConsoleOutput.Any(m => m.Contains("Retrying download")) == failSingleAssemblyDownload, + failSingleAssemblyDownload ? "The download progress test didn't emit expected message about retrying download" : "The download progress test did emit unexpected message about retrying download" ); @@ -49,8 +49,8 @@ public async Task DownloadProgressFinishes(bool failFirstAssemblyDownload) "The download progress test did emit unexpected message about second download retry" ); Assert.True( - result.TestOutput.Any(m => m.Contains("Throw error instead of downloading resource") == failFirstAssemblyDownload), - failFirstAssemblyDownload + result.TestOutput.Any(m => m.Contains("Throw error instead of downloading resource") == failSingleAssemblyDownload), + failSingleAssemblyDownload ? "The download progress test didn't emit expected message about failing download" : "The download progress test did emit unexpected message about failing download" ); diff --git a/src/mono/wasm/testassets/WasmBasicTestApp/wwwroot/main.js b/src/mono/wasm/testassets/WasmBasicTestApp/wwwroot/main.js index e4f792d16ea3a5..2132e2b9791f21 100644 --- a/src/mono/wasm/testassets/WasmBasicTestApp/wwwroot/main.js +++ b/src/mono/wasm/testassets/WasmBasicTestApp/wwwroot/main.js @@ -26,14 +26,15 @@ switch (testCase) { dotnet.withApplicationEnvironment(params.get("applicationEnvironment")); break; case "DownloadResourceProgressTest": - if (params.get("failFirstAssemblyDownload") === "true") { - let hasFailedFetch = false; + if (params.get("failSingleAssemblyDownload") === "true") { + let assemblyCounter = 0; + let failAtAssemblyNumber = Math.floor(Math.random() * 5); dotnet.withDiagnosticTracing(true).withResourceLoader((type, name, defaultUri, integrity) => { - if (hasFailedFetch || type !== "assembly") + assemblyCounter++; + if (failAtAssemblyNumber == assemblyCounter || type !== "assembly") return fetch(defaultUri, { integrity: integrity, cache: 'no-cache' }); testOutput("Throw error instead of downloading resource"); - hasFailedFetch = true; const error = new Error("Simulating a failed fetch"); error.silent = true; throw error; From 8866516c6695bc1386efb1596ae6e62f3ea76986 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Wed, 19 Jul 2023 12:08:57 +0200 Subject: [PATCH 17/17] Fail more than one assembly --- .../DownloadResourceProgressTests.cs | 14 +++++++------- .../testassets/WasmBasicTestApp/wwwroot/main.js | 15 +++++++++++---- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/DownloadResourceProgressTests.cs b/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/DownloadResourceProgressTests.cs index 3d47d155008b2d..0015476f92d082 100644 --- a/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/DownloadResourceProgressTests.cs +++ b/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/DownloadResourceProgressTests.cs @@ -23,24 +23,24 @@ public DownloadResourceProgressTests(ITestOutputHelper output, SharedBuildPerTes [Theory] [InlineData(false)] [InlineData(true)] - public async Task DownloadProgressFinishes(bool failSingleAssemblyDownload) + public async Task DownloadProgressFinishes(bool failAssemblyDownload) { - CopyTestAsset("WasmBasicTestApp", "DownloadResourceProgressTests"); + CopyTestAsset("WasmBasicTestApp", $"DownloadResourceProgressTests_{failAssemblyDownload}"); PublishProject("Debug"); var result = await RunSdkStyleApp(new( Configuration: "Debug", ForPublish: true, TestScenario: "DownloadResourceProgressTest", - BrowserQueryString: new Dictionary { ["failSingleAssemblyDownload"] = failSingleAssemblyDownload.ToString().ToLowerInvariant() } + BrowserQueryString: new Dictionary { ["failAssemblyDownload"] = failAssemblyDownload.ToString().ToLowerInvariant() } )); Assert.True( result.TestOutput.Any(m => m.Contains("DownloadResourceProgress: Finished")), "The download progress test didn't emit expected error message" ); Assert.True( - result.ConsoleOutput.Any(m => m.Contains("Retrying download")) == failSingleAssemblyDownload, - failSingleAssemblyDownload + result.ConsoleOutput.Any(m => m.Contains("Retrying download")) == failAssemblyDownload, + failAssemblyDownload ? "The download progress test didn't emit expected message about retrying download" : "The download progress test did emit unexpected message about retrying download" ); @@ -49,8 +49,8 @@ public async Task DownloadProgressFinishes(bool failSingleAssemblyDownload) "The download progress test did emit unexpected message about second download retry" ); Assert.True( - result.TestOutput.Any(m => m.Contains("Throw error instead of downloading resource") == failSingleAssemblyDownload), - failSingleAssemblyDownload + result.TestOutput.Any(m => m.Contains("Throw error instead of downloading resource") == failAssemblyDownload), + failAssemblyDownload ? "The download progress test didn't emit expected message about failing download" : "The download progress test did emit unexpected message about failing download" ); diff --git a/src/mono/wasm/testassets/WasmBasicTestApp/wwwroot/main.js b/src/mono/wasm/testassets/WasmBasicTestApp/wwwroot/main.js index 2132e2b9791f21..78424722065a2e 100644 --- a/src/mono/wasm/testassets/WasmBasicTestApp/wwwroot/main.js +++ b/src/mono/wasm/testassets/WasmBasicTestApp/wwwroot/main.js @@ -26,13 +26,20 @@ switch (testCase) { dotnet.withApplicationEnvironment(params.get("applicationEnvironment")); break; case "DownloadResourceProgressTest": - if (params.get("failSingleAssemblyDownload") === "true") { + if (params.get("failAssemblyDownload") === "true") { let assemblyCounter = 0; - let failAtAssemblyNumber = Math.floor(Math.random() * 5); + let failAtAssemblyNumbers = [ + Math.floor(Math.random() * 5), + Math.floor(Math.random() * 5) + 5, + Math.floor(Math.random() * 5) + 10 + ]; dotnet.withDiagnosticTracing(true).withResourceLoader((type, name, defaultUri, integrity) => { + if (type !== "assembly") + return defaultUri; + assemblyCounter++; - if (failAtAssemblyNumber == assemblyCounter || type !== "assembly") - return fetch(defaultUri, { integrity: integrity, cache: 'no-cache' }); + if (!failAtAssemblyNumbers.includes(assemblyCounter)) + return defaultUri; testOutput("Throw error instead of downloading resource"); const error = new Error("Simulating a failed fetch");