Add try/catch to E2E test init (#43)

This commit is contained in:
Leendert de Borst
2024-06-23 17:12:35 +02:00
parent 05e9285752
commit 4e2b10eeab

View File

@@ -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);
}
}
}
}
/// <summary>
@@ -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)}");
}
}
}