Skip to content

Commit 070153c

Browse files
authored
Removed AwaitConfigure(false) from flaky tests (#3045)
1 parent c7213de commit 070153c

File tree

7 files changed

+72
-72
lines changed

7 files changed

+72
-72
lines changed

tests/E2E Tests/WebAppUiTests/B2CWebAppCallsWebApiLocally.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public async Task Susi_B2C_LocalAccount_TodoAppFucntionsCorrectly()
103103
if (InitialConnectionRetryCount == 0) { throw ex; }
104104
}
105105
}
106-
LabResponse labResponse = await LabUserHelper.GetB2CLocalAccountAsync().ConfigureAwait(false);
106+
LabResponse labResponse = await LabUserHelper.GetB2CLocalAccountAsync();
107107

108108
// Initial sign in
109109
_output.WriteLine("Starting web app sign-in flow.");

tests/E2E Tests/WebAppUiTests/TestingWebAppLocally.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ public TestingWebAppLocally(ITestOutputHelper output)
3939
[SupportedOSPlatform("windows")]
4040
public async Task ChallengeUser_MicrosoftIdFlow_LocalApp_ValidEmailPassword()
4141
{
42-
LabResponse labResponse = await LabUserHelper.GetDefaultUserAsync().ConfigureAwait(false);
42+
LabResponse labResponse = await LabUserHelper.GetDefaultUserAsync();
4343

4444
var clientEnvVars = new Dictionary<string, string>();
4545

46-
await ExecuteWebAppCallsGraphFlow(labResponse.User.Upn, labResponse.User.GetOrFetchPassword(), clientEnvVars, TraceFileClassName).ConfigureAwait(false);
46+
await ExecuteWebAppCallsGraphFlow(labResponse.User.Upn, labResponse.User.GetOrFetchPassword(), clientEnvVars, TraceFileClassName);
4747
}
4848

4949
[Theory]
@@ -61,7 +61,7 @@ public async Task ChallengeUser_MicrosoftIdFlow_LocalApp_ValidEmailWithCiamPassw
6161
{"AzureAd__Instance", "" }
6262
};
6363

64-
await ExecuteWebAppCallsGraphFlow("[email protected]", LabUserHelper.FetchUserPassword("msidlabciam6"), clientEnvVars, TraceFileClassNameCiam).ConfigureAwait(false);
64+
await ExecuteWebAppCallsGraphFlow("[email protected]", LabUserHelper.FetchUserPassword("msidlabciam6"), clientEnvVars, TraceFileClassNameCiam);
6565
}
6666

6767
private async Task ExecuteWebAppCallsGraphFlow(string upn, string credential, Dictionary<string, string>? clientEnvVars, string traceFileClassName)

tests/E2E Tests/WebAppUiTests/WebAppCallsApiCallsGraphLocally.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ public async Task ChallengeUser_MicrosoftIdFlow_LocalApp_ValidEmailPasswordCreds
9797
Assert.Fail(TC.WebAppCrashedString + " " + runningProcesses.ToString());
9898
}
9999

100-
page = await NavigateToWebApp(context, TodoListClientPort).ConfigureAwait(false);
101-
LabResponse labResponse = await LabUserHelper.GetDefaultUserAsync().ConfigureAwait(false);
100+
page = await NavigateToWebApp(context, TodoListClientPort);
101+
LabResponse labResponse = await LabUserHelper.GetDefaultUserAsync();
102102

103103
// Initial sign in
104104
_output.WriteLine("Starting web app sign-in flow.");

tests/Microsoft.Identity.Web.Test.Integration/AcquireTokenForAppIntegrationTests.cs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public async Task GetAccessTokenOrAuthResultForApp_ReturnsAccessTokenOrAuthResul
8585
}
8686

8787
AuthenticationResult authResult =
88-
await _tokenAcquisition.GetAuthenticationResultForAppAsync(TestConstants.s_scopeForApp, tokenAcquisitionOptions: tokenAcquisitionOptions).ConfigureAwait(false);
88+
await _tokenAcquisition.GetAuthenticationResultForAppAsync(TestConstants.s_scopeForApp, tokenAcquisitionOptions: tokenAcquisitionOptions);
8989

9090
// Assert
9191
Assert.NotNull(authResult);
@@ -97,7 +97,7 @@ public async Task GetAccessTokenOrAuthResultForApp_ReturnsAccessTokenOrAuthResul
9797
else
9898
{
9999
string token =
100-
await _tokenAcquisition.GetAccessTokenForAppAsync(TestConstants.s_scopeForApp).ConfigureAwait(false);
100+
await _tokenAcquisition.GetAccessTokenForAppAsync(TestConstants.s_scopeForApp);
101101

102102
// Assert
103103
Assert.NotNull(token);
@@ -116,16 +116,16 @@ public async Task GetAccessTokenForAppAndAuthResultForApp_WithMetaTenant_ShouldT
116116

117117
// Act & Assert
118118
async Task tokenResult() =>
119-
await _tokenAcquisition.GetAccessTokenForAppAsync(TestConstants.s_scopeForApp, tenant: metaTenant).ConfigureAwait(false);
119+
await _tokenAcquisition.GetAccessTokenForAppAsync(TestConstants.s_scopeForApp, tenant: metaTenant);
120120

121-
ArgumentException ex = await Assert.ThrowsAsync<ArgumentException>(tokenResult).ConfigureAwait(false);
121+
ArgumentException ex = await Assert.ThrowsAsync<ArgumentException>(tokenResult);
122122
Assert.Contains(IDWebErrorMessage.ClientCredentialTenantShouldBeTenanted, ex.Message, System.StringComparison.OrdinalIgnoreCase);
123123

124124
// Act & Assert
125125
async Task authResult() =>
126-
await _tokenAcquisition.GetAuthenticationResultForAppAsync(TestConstants.s_scopeForApp, tenant: metaTenant).ConfigureAwait(false);
126+
await _tokenAcquisition.GetAuthenticationResultForAppAsync(TestConstants.s_scopeForApp, tenant: metaTenant);
127127

128-
ArgumentException ex2 = await Assert.ThrowsAsync<ArgumentException>(authResult).ConfigureAwait(false);
128+
ArgumentException ex2 = await Assert.ThrowsAsync<ArgumentException>(authResult);
129129
Assert.Contains(IDWebErrorMessage.ClientCredentialTenantShouldBeTenanted, ex2.Message, System.StringComparison.OrdinalIgnoreCase);
130130

131131
Assert.Equal(0, _msalTestTokenCacheProvider.Count);
@@ -144,7 +144,7 @@ public async Task GetAccessTokenOrAuthResultForApp_ConsumersTenantAsync(bool get
144144
if (getAuthResult)
145145
{
146146
AuthenticationResult authResult =
147-
await _tokenAcquisition.GetAuthenticationResultForAppAsync(TestConstants.s_scopeForApp, tenant: Constants.Consumers).ConfigureAwait(false);
147+
await _tokenAcquisition.GetAuthenticationResultForAppAsync(TestConstants.s_scopeForApp, tenant: Constants.Consumers);
148148

149149
// Assert
150150
Assert.NotNull(authResult);
@@ -155,7 +155,7 @@ public async Task GetAccessTokenOrAuthResultForApp_ConsumersTenantAsync(bool get
155155
else
156156
{
157157
string token =
158-
await _tokenAcquisition.GetAccessTokenForAppAsync(TestConstants.s_scopeForApp, tenant: Constants.Consumers).ConfigureAwait(false);
158+
await _tokenAcquisition.GetAccessTokenForAppAsync(TestConstants.s_scopeForApp, tenant: Constants.Consumers);
159159

160160
// Assert
161161
Assert.NotNull(token);
@@ -177,7 +177,7 @@ public async Task GetAccessTokenOrAuthResultForApp_TenantSpecificAsync(bool getA
177177
if (getAuthResult)
178178
{
179179
AuthenticationResult authResult =
180-
await _tokenAcquisition.GetAuthenticationResultForAppAsync(TestConstants.s_scopeForApp, tenant: TestConstants.ConfidentialClientLabTenant).ConfigureAwait(false);
180+
await _tokenAcquisition.GetAuthenticationResultForAppAsync(TestConstants.s_scopeForApp, tenant: TestConstants.ConfidentialClientLabTenant);
181181

182182
// Assert
183183
Assert.NotNull(authResult);
@@ -190,7 +190,7 @@ public async Task GetAccessTokenOrAuthResultForApp_TenantSpecificAsync(bool getA
190190
string token =
191191
await _tokenAcquisition.GetAccessTokenForAppAsync(
192192
TestConstants.s_scopeForApp,
193-
tenant: TestConstants.ConfidentialClientLabTenant).ConfigureAwait(false);
193+
tenant: TestConstants.ConfidentialClientLabTenant);
194194

195195
// Assert
196196
Assert.NotNull(token);
@@ -207,17 +207,17 @@ public async Task GetAccessTokenForApp_WithUserScope_MsalServiceExceptionThrownA
207207

208208
// Act & Assert
209209
async Task result() =>
210-
await _tokenAcquisition.GetAccessTokenForAppAsync(TestConstants.s_userReadScope.First()).ConfigureAwait(false);
210+
await _tokenAcquisition.GetAccessTokenForAppAsync(TestConstants.s_userReadScope.First());
211211

212-
ArgumentException ex = await Assert.ThrowsAsync<ArgumentException>(result).ConfigureAwait(false);
212+
ArgumentException ex = await Assert.ThrowsAsync<ArgumentException>(result);
213213

214214
Assert.Contains(IDWebErrorMessage.ClientCredentialScopeParameterShouldEndInDotDefault, ex.Message, System.StringComparison.OrdinalIgnoreCase);
215215

216216
// Act & Assert
217217
async Task authResult() =>
218-
await _tokenAcquisition.GetAuthenticationResultForAppAsync(TestConstants.s_userReadScope.First()).ConfigureAwait(false);
218+
await _tokenAcquisition.GetAuthenticationResultForAppAsync(TestConstants.s_userReadScope.First());
219219

220-
ArgumentException ex2 = await Assert.ThrowsAsync<ArgumentException>(authResult).ConfigureAwait(false);
220+
ArgumentException ex2 = await Assert.ThrowsAsync<ArgumentException>(authResult);
221221

222222
Assert.Contains(IDWebErrorMessage.ClientCredentialScopeParameterShouldEndInDotDefault, ex2.Message, System.StringComparison.OrdinalIgnoreCase);
223223
Assert.Equal(0, _msalTestTokenCacheProvider.Count);
@@ -247,7 +247,7 @@ public async Task GetAccessTokenForApp_WithAnonymousController_Async()
247247
var tokenAcquisition = services.GetRequiredService<ITokenAcquisition>();
248248
var tokenAcquisitionHost = services.GetRequiredService<ITokenAcquisitionHost>();
249249

250-
var token = await tokenAcquisition.GetAccessTokenForAppAsync("https://graph.microsoft.com/.default").ConfigureAwait(false);
250+
var token = await tokenAcquisition.GetAccessTokenForAppAsync("https://graph.microsoft.com/.default");
251251

252252
Assert.NotNull(token);
253253
}

tests/Microsoft.Identity.Web.Test.Integration/AcquireTokenForUserIntegrationTests.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ public async Task GetTokenForUserAsync(
4949
// Arrange
5050
HttpClient client = CreateHttpClient(addInMemoryTokenCache);
5151

52-
var result = await AcquireTokenForLabUserAsync().ConfigureAwait(false);
52+
var result = await AcquireTokenForLabUserAsync();
5353

5454
// Act
55-
HttpResponseMessage response = await CreateHttpResponseMessage(webApiUrl, client, result).ConfigureAwait(false);
55+
HttpResponseMessage response = await CreateHttpResponseMessage(webApiUrl, client, result);
5656

5757
// Assert
5858
Assert.True(response.IsSuccessStatusCode);
@@ -78,10 +78,10 @@ public async Task GetTokenForUserWithDifferentAuthSchemeAsync(
7878
// Arrange
7979
HttpClient client = CreateHttpClient(addInMemoryTokenCache);
8080

81-
var result = await AcquireTokenForLabUserAsync().ConfigureAwait(false);
81+
var result = await AcquireTokenForLabUserAsync();
8282

8383
// Act
84-
HttpResponseMessage response = await CreateHttpResponseMessage(webApiUrl, client, result).ConfigureAwait(false);
84+
HttpResponseMessage response = await CreateHttpResponseMessage(webApiUrl, client, result);
8585

8686
// Assert
8787
Assert.True(response.IsSuccessStatusCode);
@@ -119,11 +119,11 @@ public async Task TestSigningKeyIssuer()
119119
);
120120

121121
// Act
122-
var result = await AcquireTokenForLabUserAsync().ConfigureAwait(false);
122+
var result = await AcquireTokenForLabUserAsync();
123123
HttpResponseMessage response = await CreateHttpResponseMessage(
124124
TestConstants.SecurePage2GetTokenForUserAsync,
125125
client,
126-
result).ConfigureAwait(false);
126+
result);
127127
p.Kill();
128128

129129
// Assert
@@ -154,7 +154,7 @@ private static async Task<HttpResponseMessage> CreateHttpResponseMessage(string
154154
Constants.Bearer,
155155
result.AccessToken));
156156
}
157-
response = await client.SendAsync(httpRequestMessage).ConfigureAwait(false);
157+
response = await client.SendAsync(httpRequestMessage);
158158
}
159159

160160
return response;
@@ -194,7 +194,7 @@ private HttpClient CreateHttpClient(
194194

195195
private static async Task<AuthenticationResult> AcquireTokenForLabUserAsync()
196196
{
197-
var labResponse = await LabUserHelper.GetSpecificUserAsync(TestConstants.OBOUser).ConfigureAwait(false);
197+
var labResponse = await LabUserHelper.GetSpecificUserAsync(TestConstants.OBOUser);
198198
var msalPublicClient = PublicClientApplicationBuilder
199199
.Create(TestConstants.OBOClientSideClientId)
200200
.WithAuthority(labResponse.Lab.Authority, TestConstants.Organizations)
@@ -206,7 +206,7 @@ private static async Task<AuthenticationResult> AcquireTokenForLabUserAsync()
206206
TestConstants.OBOUser,
207207
labResponse.User.GetOrFetchPassword())
208208
.ExecuteAsync(CancellationToken.None)
209-
.ConfigureAwait(false);
209+
;
210210

211211
return authResult;
212212
}

tests/Microsoft.Identity.Web.Test/CacheExtensionsTests.cs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -37,23 +37,23 @@ public async Task CacheExtensions_CcaAlreadyExists_TestsAsync()
3737
{
3838
AuthenticationResult result;
3939
// new InMemory serializer and new cca
40-
result = await CreateAppAndGetTokenAsync(CacheType.InMemory).ConfigureAwait(false);
40+
result = await CreateAppAndGetTokenAsync(CacheType.InMemory);
4141
Assert.Equal(TokenSource.IdentityProvider, result.AuthenticationResultMetadata.TokenSource);
4242
AssertCacheTelemetry(result, CacheLevel.None);
4343

44-
result = await CreateAppAndGetTokenAsync(CacheType.InMemory, addTokenMock: false).ConfigureAwait(false);
44+
result = await CreateAppAndGetTokenAsync(CacheType.InMemory, addTokenMock: false);
4545
Assert.Equal(TokenSource.Cache, result.AuthenticationResultMetadata.TokenSource);
4646
AssertCacheTelemetry(result, CacheLevel.L1Cache);
4747

4848
//Resetting token caches due to potential collision with other tests
4949
TokenCacheExtensions.s_serviceProviderFromAction.Clear();
5050

5151
// new DistributedInMemory and same cca
52-
result = await CreateAppAndGetTokenAsync(CacheType.DistributedInMemory).ConfigureAwait(false);
52+
result = await CreateAppAndGetTokenAsync(CacheType.DistributedInMemory);
5353
Assert.Equal(TokenSource.IdentityProvider, result.AuthenticationResultMetadata.TokenSource);
5454
AssertCacheTelemetry(result, CacheLevel.None);
5555

56-
result = await CreateAppAndGetTokenAsync(CacheType.DistributedInMemory, addTokenMock: false).ConfigureAwait(false);
56+
result = await CreateAppAndGetTokenAsync(CacheType.DistributedInMemory, addTokenMock: false);
5757
Assert.Equal(TokenSource.Cache, result.AuthenticationResultMetadata.TokenSource);
5858
AssertCacheTelemetry(result, CacheLevel.L1Cache);
5959
}
@@ -63,11 +63,11 @@ public async Task CacheExtensions_CcaAlreadyExistsL2_TestsAsync()
6363
{
6464
AuthenticationResult result;
6565
// new DistributedInMemory serializer with L1 cache disabled
66-
result = await CreateAppAndGetTokenAsync(CacheType.DistributedInMemory, disableL1Cache: true).ConfigureAwait(false);
66+
result = await CreateAppAndGetTokenAsync(CacheType.DistributedInMemory, disableL1Cache: true);
6767
Assert.Equal(TokenSource.IdentityProvider, result.AuthenticationResultMetadata.TokenSource);
6868
AssertCacheTelemetry(result, CacheLevel.None);
6969

70-
result = await CreateAppAndGetTokenAsync(CacheType.DistributedInMemory, addTokenMock: false, disableL1Cache: true).ConfigureAwait(false);
70+
result = await CreateAppAndGetTokenAsync(CacheType.DistributedInMemory, addTokenMock: false, disableL1Cache: true);
7171
Assert.Equal(TokenSource.Cache, result.AuthenticationResultMetadata.TokenSource);
7272
AssertCacheTelemetry(result, CacheLevel.L2Cache);
7373
}
@@ -181,10 +181,10 @@ public async Task SingletonMsal_ResultsInCorrectCacheEntries_Test()
181181
// Different tenants used to created different cache entries
182182
var result1 = await confidentialApp.AcquireTokenForClient(new[] { TestConstants.s_scopeForApp })
183183
.WithTenantId(tenantId1)
184-
.ExecuteAsync().ConfigureAwait(false);
184+
.ExecuteAsync();
185185
var result2 = await confidentialApp.AcquireTokenForClient(new[] { TestConstants.s_scopeForApp })
186186
.WithTenantId(tenantId2)
187-
.ExecuteAsync().ConfigureAwait(false);
187+
.ExecuteAsync();
188188

189189
Assert.Equal(TokenSource.IdentityProvider, result1.AuthenticationResultMetadata.TokenSource);
190190
Assert.Equal(TokenSource.IdentityProvider, result2.AuthenticationResultMetadata.TokenSource);
@@ -261,12 +261,12 @@ private async Task<AuthenticationResult> GetTokensAssociatedWithKey(string? cach
261261
.WithClientSecret(TestConstants.ClientSecret)
262262
.Build();
263263

264-
await msalMemoryTokenCacheProvider.InitializeAsync(confidentialApp.AppTokenCache).ConfigureAwait(false);
264+
await msalMemoryTokenCacheProvider.InitializeAsync(confidentialApp.AppTokenCache);
265265

266266
AuthenticationResult result = await confidentialApp
267267
.AcquireTokenForClient(["https://graph.microsoft.com/.default"])
268268
.ExecuteAsync()
269-
.ConfigureAwait(false);
269+
;
270270

271271
Assert.Equal(
272272
expectCacheHit ?
@@ -289,13 +289,13 @@ private async Task<AuthenticationResult> GetTokensAssociatedWithKey(string? cach
289289
[Fact]
290290
public async Task CacheKeyExtensibility()
291291
{
292-
var result = await GetTokensAssociatedWithKey("foo", expectCacheHit: false).ConfigureAwait(false);
293-
result = await GetTokensAssociatedWithKey("bar", expectCacheHit: false).ConfigureAwait(false);
294-
result = await GetTokensAssociatedWithKey(null, expectCacheHit: false).ConfigureAwait(false);
292+
var result = await GetTokensAssociatedWithKey("foo", expectCacheHit: false);
293+
result = await GetTokensAssociatedWithKey("bar", expectCacheHit: false);
294+
result = await GetTokensAssociatedWithKey(null, expectCacheHit: false);
295295

296-
result = await GetTokensAssociatedWithKey("foo", expectCacheHit: true).ConfigureAwait(false);
297-
result = await GetTokensAssociatedWithKey("bar", expectCacheHit: true).ConfigureAwait(false);
298-
result = await GetTokensAssociatedWithKey(null, expectCacheHit: true).ConfigureAwait(false);
296+
result = await GetTokensAssociatedWithKey("foo", expectCacheHit: true);
297+
result = await GetTokensAssociatedWithKey("bar", expectCacheHit: true);
298+
result = await GetTokensAssociatedWithKey(null, expectCacheHit: true);
299299
}
300300

301301
private enum CacheType
@@ -353,7 +353,7 @@ private static async Task<AuthenticationResult> CreateAppAndGetTokenAsync(
353353
}
354354

355355
var result = await confidentialApp.AcquireTokenForClient(new[] { TestConstants.s_scopeForApp })
356-
.ExecuteAsync().ConfigureAwait(false);
356+
.ExecuteAsync();
357357

358358
tokenHandler.ReplaceMockHttpMessageHandler = null!;
359359
return result;

0 commit comments

Comments
 (0)