Skip to content

Commit cc6f871

Browse files
authored
Fix E2E tests persistent flakiness + build hanging (#3188)
* 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
1 parent e752bbe commit cc6f871

File tree

4 files changed

+20
-22
lines changed

4 files changed

+20
-22
lines changed

tests/E2E Tests/WebAppUiTests/B2CWebAppCallsWebApiLocally.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public async Task Susi_B2C_LocalAccount_TodoAppFunctionsCorrectlyAsync()
5555
{
5656
{"ASPNETCORE_ENVIRONMENT", "Development"},
5757
{"AzureAdB2C__ClientSecret", clientSecret},
58-
{TC.KestrelEndpointEnvVar, TC.HttpsStarColon + TodoListClientPort}
58+
{TC.KestrelEndpointEnvVar, TC.HttpStarColon + TodoListClientPort}
5959
};
6060

6161
// Get email and password from keyvault.
@@ -92,7 +92,7 @@ public async Task Susi_B2C_LocalAccount_TodoAppFunctionsCorrectlyAsync()
9292
{
9393
try
9494
{
95-
await page.GotoAsync(TC.LocalhostUrl + TodoListClientPort);
95+
await page.GotoAsync(TC.LocalhostHttpUrl + TodoListClientPort);
9696
break;
9797
}
9898
catch (PlaywrightException ex)
@@ -167,7 +167,7 @@ public async Task Susi_B2C_LocalAccount_TodoAppFunctionsCorrectlyAsync()
167167
Queue<Process> processes = new Queue<Process>();
168168
if (serviceProcess != null) { processes.Enqueue(serviceProcess); }
169169
if (clientProcess != null) { processes.Enqueue(clientProcess); }
170-
UiTestHelpers.KillProcessTrees(processes);
170+
await UiTestHelpers.KillProcessTreesAsync(processes);
171171

172172
// Stop tracing and export it into a zip archive.
173173
string path = UiTestHelpers.GetTracePath(_testAssemblyPath, TraceFileName);

tests/E2E Tests/WebAppUiTests/UiTestHelpers.cs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -173,30 +173,23 @@ public static Process StartProcessLocally(
173173
{
174174
Thread.Sleep(1000 * currentAttempt++); // linear backoff
175175
process = Process.Start(processStartInfo);
176-
} while (currentAttempt++ <= maxRetries && ProcessIsAlive(process));
176+
} while (currentAttempt++ <= maxRetries && !ProcessIsAlive(process));
177177

178178
if (process == null)
179179
{
180180
throw new Exception($"Could not start process {executableName}");
181181
}
182182
else
183183
{
184-
// Log the output and error streams
185184
process.OutputDataReceived += (sender, e) =>
186185
{
187-
output.WriteLine($"{process.Id} ");
188-
output.WriteLine(e?.Data ?? "null output data received.");
186+
output.WriteLine(e?.Data == null ? "null output data received." : $"{process.Id} {e.Data}");
189187
};
190-
191188
process.ErrorDataReceived += (sender, e) =>
192189
{
193-
output.WriteLine($"{process.Id} ");
194-
output.WriteLine(e?.Data ?? "null error data received.");
190+
output.WriteLine(e?.Data == null ? "null output data received." : $"{process.Id} {e.Data}");
195191
};
196192

197-
process.BeginOutputReadLine();
198-
process.BeginErrorReadLine();
199-
200193
return process;
201194
}
202195
}
@@ -252,7 +245,7 @@ public static string GetTracePath(string testAssemblyLocation, string traceName)
252245
/// </summary>
253246
/// <param name="processQueue">queue of parent processes</param>
254247
[SupportedOSPlatform("windows")]
255-
public static void KillProcessTrees(Queue<Process> processQueue)
248+
public static async Task KillProcessTreesAsync(Queue<Process> processQueue)
256249
{
257250
Process currentProcess;
258251
while (processQueue.Count > 0)
@@ -265,6 +258,10 @@ public static void KillProcessTrees(Queue<Process> processQueue)
265258
{
266259
processQueue.Enqueue(child);
267260
}
261+
await currentProcess.WaitForExitAsync();
262+
currentProcess.StandardOutput.Close();
263+
currentProcess.StandardError.Close();
264+
268265
currentProcess.Kill();
269266
currentProcess.Close();
270267
}

tests/E2E Tests/WebAppUiTests/WebAppCallsApiCallsGraphLocally.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public async Task ChallengeUser_MicrosoftIdFlow_LocalApp_ValidEmailPasswordCreds
4949
var grpcEnvVars = new Dictionary<string, string>
5050
{
5151
{"ASPNETCORE_ENVIRONMENT", "Development"},
52-
{TC.KestrelEndpointEnvVar, TC.HttpsStarColon + GrpcPort}
52+
{TC.KestrelEndpointEnvVar, TC.HttpStarColon + GrpcPort}
5353
};
5454
var serviceEnvVars = new Dictionary<string, string>
5555
{
@@ -59,7 +59,7 @@ public async Task ChallengeUser_MicrosoftIdFlow_LocalApp_ValidEmailPasswordCreds
5959
var clientEnvVars = new Dictionary<string, string>
6060
{
6161
{"ASPNETCORE_ENVIRONMENT", "Development"},
62-
{TC.KestrelEndpointEnvVar, TC.HttpsStarColon + TodoListClientPort}
62+
{TC.KestrelEndpointEnvVar, TC.HttpStarColon + TodoListClientPort}
6363
};
6464

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

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

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

251251
// Sign in again using Todo List button
@@ -258,7 +258,7 @@ public async Task ChallengeUser_MicrosoftIdFlow_LocalApp_ValidEmailPasswordCreds
258258
}
259259
catch (Exception ex)
260260
{
261-
//Adding guid incase of multiple test runs. This will allow screenshots to be matched to their appropriet test runs.
261+
//Adding guid incase of multiple test runs. This will allow screenshots to be matched to their appropriate test runs.
262262
var guid = Guid.NewGuid().ToString();
263263
try
264264
{
@@ -341,7 +341,7 @@ private async Task<IPage> NavigateToWebAppAsync(IBrowserContext context, uint po
341341
{
342342
try
343343
{
344-
await page.GotoAsync(TC.LocalhostUrl + port);
344+
await page.GotoAsync(TC.LocalhostHttpUrl + port);
345345
break;
346346
}
347347
catch (PlaywrightException ex)

tests/Microsoft.Identity.Web.Test.Common/TestConstants.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,8 @@ public static class TestConstants
175175
public const string PasswordText = "Password";
176176
public const string TodoTitle1 = "Testing create todo item";
177177
public const string TodoTitle2 = "Testing edit todo item";
178-
public const string LocalhostUrl = @"https://localhost:";
178+
public const string LocalhostHttpsUrl = @"https://localhost:";
179+
public const string LocalhostHttpUrl = @"http://localhost:";
179180
public const string KestrelEndpointEnvVar = "Kestrel:Endpoints:Http:Url";
180181
public const string HttpStarColon = "http://*:";
181182
public const string HttpsStarColon = "https://*:";

0 commit comments

Comments
 (0)