Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public B2CWebAppCallsWebApiLocally(ITestOutputHelper output)

[Fact]
[SupportedOSPlatform("windows")]
public async Task Susi_B2C_LocalAccount_TodoAppFucntionsCorrectlyAsync()
public async Task Susi_B2C_LocalAccount_TodoAppFunctionsCorrectlyAsync()
{
// Web app and api environmental variable setup.
DefaultAzureCredential azureCred = new();
Expand Down Expand Up @@ -79,9 +79,9 @@ public async Task Susi_B2C_LocalAccount_TodoAppFucntionsCorrectlyAsync()
// The delay before starting client prevents transient devbox issue where the client fails to load the first time after rebuilding.
serviceProcess = UiTestHelpers.StartProcessLocally(_testAssemblyPath, _devAppPath + TC.s_todoListServicePath, TC.s_todoListServiceExe, serviceEnvVars);
await Task.Delay(3000);
clientProcess = UiTestHelpers.StartProcessLocally(_testAssemblyPath, _devAppPath + TC.s_todoListClientPath, TC.s_todoListClientExe, clientEnvVars);
clientProcess = UiTestHelpers.StartProcessLocally(_testAssemblyPath, _devAppPath + TC.s_todoListClientPath, TC.s_todoListClientExe, clientEnvVars, 5);

if (!UiTestHelpers.ProcessesAreAlive(new List<Process>() { clientProcess, serviceProcess }))
if (!UiTestHelpers.ProcessesAreAlive([clientProcess, serviceProcess]))
{
Assert.Fail(TC.WebAppCrashedString);
}
Expand Down
26 changes: 22 additions & 4 deletions tests/E2E Tests/WebAppUiTests/UiTestHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,13 @@ await page.Context.Tracing.StartAsync(new()
/// <param name="executableName">The name of the executable that launches the process.</param>
/// <param name="portNumber">The port for the process to listen on.</param>
/// <param name="isHttp">If the launch URL is http or https. Default is https.</param>
/// <param name="maxRetries">Optionally, maximum number of retries if the process exited prematurely.</param>
/// <returns>The started process.</returns>
public static Process StartProcessLocally(string testAssemblyLocation, string appLocation, string executableName, Dictionary<string, string>? environmentVariables = null)
public static Process StartProcessLocally(
string testAssemblyLocation,
string appLocation, string executableName,
Dictionary<string, string>? environmentVariables = null,
int maxRetries = 0)
{
string applicationWorkingDirectory = GetApplicationWorkingDirectory(testAssemblyLocation, appLocation);
ProcessStartInfo processStartInfo = new ProcessStartInfo(applicationWorkingDirectory + executableName)
Expand All @@ -161,14 +166,27 @@ public static Process StartProcessLocally(string testAssemblyLocation, string ap
}
}

Process? process = Process.Start(processStartInfo);
var currentAttempt = 1;
Process? process;
do
{
Thread.Sleep(1000 * currentAttempt++); // Exponential backoff
process = Process.Start(processStartInfo);
} while (currentAttempt++ <= maxRetries && ProcessIsAlive(process));

if (process == null)
{
throw new Exception($"Could not start process {executableName}");
}
else
{
// Log the output and error streams
process.OutputDataReceived += (sender, e) => Console.WriteLine(e.Data);
process.ErrorDataReceived += (sender, e) => Console.Error.WriteLine(e.Data);

process.BeginOutputReadLine();
process.BeginErrorReadLine();

return process;
}
}
Expand Down Expand Up @@ -275,9 +293,9 @@ public static bool ProcessesAreAlive(List<Process> processes)
/// </summary>
/// <param name="process">Process to check</param>
/// <returns>True if alive false if not</returns>
public static bool ProcessIsAlive(Process process)
public static bool ProcessIsAlive(Process? process)
{
return !process.HasExited;
return process != null && !process.HasExited;
}

/// <summary>
Expand Down
Loading