From 3a870ef55a26e43fe5822ac9c0929a14da8d5b2f Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Tue, 7 May 2024 18:09:15 -0700 Subject: [PATCH] Fix flaky CanRenderComponentWithPersistedState test variations - Verify wasm resources are fully loaded before refreshing --- .../E2ETest/Tests/StatePersistenceTest.cs | 47 +++++----------- .../Modern/BasicTestApp.lib.module.js | 1 - .../RazorComponents/App.razor | 54 +++++++++++-------- .../PageWithoutComponents.razor | 2 +- ...treamingComponentWithPersistentState.razor | 2 +- 5 files changed, 49 insertions(+), 57 deletions(-) diff --git a/src/Components/test/E2ETest/Tests/StatePersistenceTest.cs b/src/Components/test/E2ETest/Tests/StatePersistenceTest.cs index 615fafe6aefb..d49e4fbc5704 100644 --- a/src/Components/test/E2ETest/Tests/StatePersistenceTest.cs +++ b/src/Components/test/E2ETest/Tests/StatePersistenceTest.cs @@ -45,13 +45,13 @@ public override Task InitializeAsync() [InlineData(true, typeof(InteractiveWebAssemblyRenderMode), (string)null)] [InlineData(true, typeof(InteractiveWebAssemblyRenderMode), "WebAssemblyStreaming")] [InlineData(true, typeof(InteractiveAutoRenderMode), (string)null)] - // [InlineData(true, typeof(InteractiveAutoRenderMode), "AutoStreaming")] https://github.com/dotnet/aspnetcore/issues/50810 + [InlineData(true, typeof(InteractiveAutoRenderMode), "AutoStreaming")] [InlineData(false, typeof(InteractiveServerRenderMode), (string)null)] [InlineData(false, typeof(InteractiveServerRenderMode), "ServerStreaming")] [InlineData(false, typeof(InteractiveWebAssemblyRenderMode), (string)null)] [InlineData(false, typeof(InteractiveWebAssemblyRenderMode), "WebAssemblyStreaming")] - // [InlineData(false, typeof(InteractiveAutoRenderMode), (string)null)] https://github.com/dotnet/aspnetcore/issues/50810 - // [InlineData(false, typeof(InteractiveAutoRenderMode), "AutoStreaming")] https://github.com/dotnet/aspnetcore/issues/50810 + [InlineData(false, typeof(InteractiveAutoRenderMode), (string)null)] + [InlineData(false, typeof(InteractiveAutoRenderMode), "AutoStreaming")] public void CanRenderComponentWithPersistedState(bool suppressEnhancedNavigation, Type renderMode, string streaming) { var mode = renderMode switch @@ -83,7 +83,11 @@ public void CanRenderComponentWithPersistedState(bool suppressEnhancedNavigation } else { - SuppressEnhancedNavigation(true); + EnhancedNavigationTestUtil.SuppressEnhancedNavigation(this, true); + if (mode == "auto") + { + BlockWebAssemblyResourceLoad(); + } } if (mode != "auto") @@ -92,21 +96,11 @@ public void CanRenderComponentWithPersistedState(bool suppressEnhancedNavigation } else { - if (suppressEnhancedNavigation) - { - BlockWebAssemblyResourceLoad(); - } // For auto mode, validate that the state is persisted for both runtimes and is able // to be loaded on server and wasm. RenderComponentsWithPersistentStateAndValidate(suppressEnhancedNavigation, mode, renderMode, streaming, interactiveRuntime: "server"); UnblockWebAssemblyResourceLoad(); - - if (suppressEnhancedNavigation) - { - RenderWebAssemblyComponentAndWaitForWebAssemblyRuntime(returnUrl: Browser.Url); - } - Browser.Navigate().Refresh(); RenderComponentsWithPersistentStateAndValidate(suppressEnhancedNavigation, mode, renderMode, streaming, interactiveRuntime: "wasm"); @@ -151,6 +145,7 @@ private void BlockWebAssemblyResourceLoad() private void UnblockWebAssemblyResourceLoad() { ((IJavaScriptExecutor)Browser).ExecuteScript("window.unblockLoadBootResource()"); + Browser.Exists(By.Id("unblocked-wasm")); } private void RenderComponentsWithPersistentStateAndValidate( @@ -159,9 +154,8 @@ private void RenderComponentsWithPersistentStateAndValidate( Type renderMode, string streaming, string interactiveRuntime = null, - string stateValue = null) + string stateValue = "restored") { - stateValue ??= "restored"; // No need to navigate if we are using enhanced navigation, the tests will have already navigated to the page via a link. if (suppressEnhancedNavigation) { @@ -198,11 +192,13 @@ private void RenderComponentsWithPersistentStateAndValidate( streamingCompleted: false, interactiveRuntime: interactiveRuntime); - if (streaming != null) + if (streaming == null) { - Browser.Click(By.Id("end-streaming")); + return; } + Browser.Click(By.Id("end-streaming")); + AssertPageState( mode: mode, renderMode: renderMode.Name, @@ -240,19 +236,4 @@ private void AssertPageState( Browser.Equal("Streaming: True", () => Browser.FindElement(By.Id("streaming")).Text); } } - - private void RenderWebAssemblyComponentAndWaitForWebAssemblyRuntime(string returnUrl = null) - { - Navigate("subdir/persistent-state/page-with-webassembly-interactivity"); - - Browser.Equal("True", () => Browser.FindElement(By.Id("is-interactive-counter")).Text); - - if (returnUrl is not null) - { - Navigate(returnUrl); - } - } - - private void SuppressEnhancedNavigation(bool shouldSuppress) - => EnhancedNavigationTestUtil.SuppressEnhancedNavigation(this, shouldSuppress); } diff --git a/src/Components/test/testassets/BasicTestApp/wwwroot/JSInitializers/Modern/BasicTestApp.lib.module.js b/src/Components/test/testassets/BasicTestApp/wwwroot/JSInitializers/Modern/BasicTestApp.lib.module.js index b9220c73a442..4fc29f147508 100644 --- a/src/Components/test/testassets/BasicTestApp/wwwroot/JSInitializers/Modern/BasicTestApp.lib.module.js +++ b/src/Components/test/testassets/BasicTestApp/wwwroot/JSInitializers/Modern/BasicTestApp.lib.module.js @@ -30,7 +30,6 @@ export function beforeServerStart(options) { return new Promise((resolve, reject) => { options.circuitHandlers.push({ onCircuitOpened: () => { - debugger; appendElement('modern-circuit-opened', 'Modern "circuitOpened"'); }, onCircuitClosed: () => appendElement('modern-circuit-closed', 'Modern "circuitClosed"') diff --git a/src/Components/test/testassets/Components.TestServer/RazorComponents/App.razor b/src/Components/test/testassets/Components.TestServer/RazorComponents/App.razor index befd36e52a53..094bb249394f 100644 --- a/src/Components/test/testassets/Components.TestServer/RazorComponents/App.razor +++ b/src/Components/test/testassets/Components.TestServer/RazorComponents/App.razor @@ -18,24 +18,41 @@