Skip to content

Commit

Permalink
Fix E2E tests persistent flakiness + build hanging (#3188)
Browse files Browse the repository at this point in the history
* fix flakiness due to failure to configure HTTPS endpoint due to lack of certificate

* close std out/error on the processes now that we're logging them

* trial https for webapp tests

* https for webapp test trial

* rm log for testing purposes only

* await the process.WaitForExitAsync call
  • Loading branch information
kllysng authored Jan 9, 2025
1 parent e752bbe commit cc6f871
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 22 deletions.
6 changes: 3 additions & 3 deletions tests/E2E Tests/WebAppUiTests/B2CWebAppCallsWebApiLocally.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public async Task Susi_B2C_LocalAccount_TodoAppFunctionsCorrectlyAsync()
{
{"ASPNETCORE_ENVIRONMENT", "Development"},
{"AzureAdB2C__ClientSecret", clientSecret},
{TC.KestrelEndpointEnvVar, TC.HttpsStarColon + TodoListClientPort}
{TC.KestrelEndpointEnvVar, TC.HttpStarColon + TodoListClientPort}
};

// Get email and password from keyvault.
Expand Down Expand Up @@ -92,7 +92,7 @@ public async Task Susi_B2C_LocalAccount_TodoAppFunctionsCorrectlyAsync()
{
try
{
await page.GotoAsync(TC.LocalhostUrl + TodoListClientPort);
await page.GotoAsync(TC.LocalhostHttpUrl + TodoListClientPort);
break;
}
catch (PlaywrightException ex)
Expand Down Expand Up @@ -167,7 +167,7 @@ public async Task Susi_B2C_LocalAccount_TodoAppFunctionsCorrectlyAsync()
Queue<Process> processes = new Queue<Process>();
if (serviceProcess != null) { processes.Enqueue(serviceProcess); }
if (clientProcess != null) { processes.Enqueue(clientProcess); }
UiTestHelpers.KillProcessTrees(processes);
await UiTestHelpers.KillProcessTreesAsync(processes);

// Stop tracing and export it into a zip archive.
string path = UiTestHelpers.GetTracePath(_testAssemblyPath, TraceFileName);
Expand Down
19 changes: 8 additions & 11 deletions tests/E2E Tests/WebAppUiTests/UiTestHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,30 +173,23 @@ public static Process StartProcessLocally(
{
Thread.Sleep(1000 * currentAttempt++); // linear backoff
process = Process.Start(processStartInfo);
} while (currentAttempt++ <= maxRetries && ProcessIsAlive(process));
} 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) =>
{
output.WriteLine($"{process.Id} ");
output.WriteLine(e?.Data ?? "null output data received.");
output.WriteLine(e?.Data == null ? "null output data received." : $"{process.Id} {e.Data}");
};

process.ErrorDataReceived += (sender, e) =>
{
output.WriteLine($"{process.Id} ");
output.WriteLine(e?.Data ?? "null error data received.");
output.WriteLine(e?.Data == null ? "null output data received." : $"{process.Id} {e.Data}");
};

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

return process;
}
}
Expand Down Expand Up @@ -252,7 +245,7 @@ public static string GetTracePath(string testAssemblyLocation, string traceName)
/// </summary>
/// <param name="processQueue">queue of parent processes</param>
[SupportedOSPlatform("windows")]
public static void KillProcessTrees(Queue<Process> processQueue)
public static async Task KillProcessTreesAsync(Queue<Process> processQueue)
{
Process currentProcess;
while (processQueue.Count > 0)
Expand All @@ -265,6 +258,10 @@ public static void KillProcessTrees(Queue<Process> processQueue)
{
processQueue.Enqueue(child);
}
await currentProcess.WaitForExitAsync();
currentProcess.StandardOutput.Close();
currentProcess.StandardError.Close();

currentProcess.Kill();
currentProcess.Close();
}
Expand Down
14 changes: 7 additions & 7 deletions tests/E2E Tests/WebAppUiTests/WebAppCallsApiCallsGraphLocally.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public async Task ChallengeUser_MicrosoftIdFlow_LocalApp_ValidEmailPasswordCreds
var grpcEnvVars = new Dictionary<string, string>
{
{"ASPNETCORE_ENVIRONMENT", "Development"},
{TC.KestrelEndpointEnvVar, TC.HttpsStarColon + GrpcPort}
{TC.KestrelEndpointEnvVar, TC.HttpStarColon + GrpcPort}
};
var serviceEnvVars = new Dictionary<string, string>
{
Expand All @@ -59,7 +59,7 @@ public async Task ChallengeUser_MicrosoftIdFlow_LocalApp_ValidEmailPasswordCreds
var clientEnvVars = new Dictionary<string, string>
{
{"ASPNETCORE_ENVIRONMENT", "Development"},
{TC.KestrelEndpointEnvVar, TC.HttpsStarColon + TodoListClientPort}
{TC.KestrelEndpointEnvVar, TC.HttpStarColon + TodoListClientPort}
};

Dictionary<string, Process>? processes = null;
Expand Down Expand Up @@ -109,7 +109,7 @@ public async Task ChallengeUser_MicrosoftIdFlow_LocalApp_ValidEmailPasswordCreds
// Sign out
_output.WriteLine("Starting web app sign-out flow.");
await page.GetByRole(AriaRole.Link, new() { Name = "Sign out" }).ClickAsync();
await UiTestHelpers.PerformSignOut_MicrosoftIdFlowAsync(page, email, TC.LocalhostUrl + TodoListClientPort + SignOutPageUriPath, _output);
await UiTestHelpers.PerformSignOut_MicrosoftIdFlowAsync(page, email, TC.LocalhostHttpUrl + TodoListClientPort + SignOutPageUriPath, _output);
_output.WriteLine("Web app sign out successful.");

// Sign in again using Todo List button
Expand Down Expand Up @@ -198,7 +198,7 @@ public async Task ChallengeUser_MicrosoftIdFlow_LocalApp_ValidEmailPasswordCreds
{"AzureAd__ClientId", "b244c86f-ed88-45bf-abda-6b37aa482c79"},
{"AzureAd__Authority", authority},
{"DownstreamApi__Scopes__0", "api://634de702-3173-4a71-b336-a4fab786a479/.default"},
{TC.KestrelEndpointEnvVar, TC.HttpsStarColon + WebAppCiamPort}
{TC.KestrelEndpointEnvVar, TC.HttpStarColon + WebAppCiamPort}
};

Dictionary<string, Process>? processes = null;
Expand Down Expand Up @@ -245,7 +245,7 @@ public async Task ChallengeUser_MicrosoftIdFlow_LocalApp_ValidEmailPasswordCreds
// Sign out
_output.WriteLine("Starting web app sign-out flow.");
await page.GetByRole(AriaRole.Link, new() { Name = "Sign out" }).ClickAsync();
await UiTestHelpers.PerformSignOut_MicrosoftIdFlowAsync(page, email, TC.LocalhostUrl + WebAppCiamPort + SignOutPageUriPath, _output);
await UiTestHelpers.PerformSignOut_MicrosoftIdFlowAsync(page, email, TC.LocalhostHttpUrl + WebAppCiamPort + SignOutPageUriPath, _output);
_output.WriteLine("Web app sign out successful.");

// Sign in again using Todo List button
Expand All @@ -258,7 +258,7 @@ public async Task ChallengeUser_MicrosoftIdFlow_LocalApp_ValidEmailPasswordCreds
}
catch (Exception ex)
{
//Adding guid incase of multiple test runs. This will allow screenshots to be matched to their appropriet test runs.
//Adding guid incase of multiple test runs. This will allow screenshots to be matched to their appropriate test runs.
var guid = Guid.NewGuid().ToString();
try
{
Expand Down Expand Up @@ -341,7 +341,7 @@ private async Task<IPage> NavigateToWebAppAsync(IBrowserContext context, uint po
{
try
{
await page.GotoAsync(TC.LocalhostUrl + port);
await page.GotoAsync(TC.LocalhostHttpUrl + port);
break;
}
catch (PlaywrightException ex)
Expand Down
3 changes: 2 additions & 1 deletion tests/Microsoft.Identity.Web.Test.Common/TestConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@ public static class TestConstants
public const string PasswordText = "Password";
public const string TodoTitle1 = "Testing create todo item";
public const string TodoTitle2 = "Testing edit todo item";
public const string LocalhostUrl = @"https://localhost:";
public const string LocalhostHttpsUrl = @"https://localhost:";
public const string LocalhostHttpUrl = @"http://localhost:";
public const string KestrelEndpointEnvVar = "Kestrel:Endpoints:Http:Url";
public const string HttpStarColon = "http://*:";
public const string HttpsStarColon = "https://*:";
Expand Down

0 comments on commit cc6f871

Please sign in to comment.