Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix E2E tests persistent flakiness + build hanging #3188

Merged
merged 6 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -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();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do they exit by themselves?

currentProcess.StandardOutput.Close();
currentProcess.StandardError.Close();

currentProcess.Kill();
currentProcess.Close();
}
Expand Down
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
Loading