From 4e2b10eeaba586ddc9ba8291204a0cc70649e4b6 Mon Sep 17 00:00:00 2001 From: Leendert de Borst Date: Sun, 23 Jun 2024 17:12:35 +0200 Subject: [PATCH] Add try/catch to E2E test init (#43) --- .../Infrastructure/BlazorWasmAppManager.cs | 36 +++++++++++++++---- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/src/Tests/AliasVault.E2ETests/Infrastructure/BlazorWasmAppManager.cs b/src/Tests/AliasVault.E2ETests/Infrastructure/BlazorWasmAppManager.cs index 64b3fa937..e074ef090 100644 --- a/src/Tests/AliasVault.E2ETests/Infrastructure/BlazorWasmAppManager.cs +++ b/src/Tests/AliasVault.E2ETests/Infrastructure/BlazorWasmAppManager.cs @@ -54,11 +54,34 @@ public class BlazorWasmAppManager _blazorWasmErrors.Add(args.Data); }; - _blazorWasmProcess.Start(); - _blazorWasmProcess.BeginOutputReadLine(); - _blazorWasmProcess.BeginErrorReadLine(); - - await WaitForStartupAsync(port); + try + { + _blazorWasmProcess.Start(); + _blazorWasmProcess.BeginOutputReadLine(); + _blazorWasmProcess.BeginErrorReadLine(); + await WaitForStartupAsync(port); + } + catch (Exception ex) + { + // Retry up to 3 times + for (int i = 0; i < 3; i++) + { + try + { + _blazorWasmProcess.Start(); + _blazorWasmProcess.BeginOutputReadLine(); + _blazorWasmProcess.BeginErrorReadLine(); + await WaitForStartupAsync(port); + break; // Success, exit the loop + } + catch (Exception) + { + // Retry failed, log the exception and continue to the next attempt + await TestContext.Out.WriteLineAsync($"Failed to start Blazor WebAssembly application. Retry attempt {i + 1}"); + await TestContext.Out.WriteLineAsync(ex.Message); + } + } + } } /// @@ -172,8 +195,7 @@ public class BlazorWasmAppManager if (_blazorWasmErrors.Count > 0) { - Assert.Fail($"WASM failed to start: {string.Join(Environment.NewLine, _blazorWasmErrors)}"); - return; + throw new Exception($"WASM failed to start: {string.Join(Environment.NewLine, _blazorWasmErrors)}"); } } }