Skip to content

Commit 8b6ccff

Browse files
authored
Fix AuthStateAsyncReturnsUnrelatedCancelledTask_TreatAsFailure flake (#20881)
1 parent cf1c5cb commit 8b6ccff

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/Components/Server/test/Circuits/RevalidatingServerAuthenticationStateProvider.cs renamed to src/Components/Server/test/Circuits/RevalidatingServerAuthenticationStateProviderTest.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,17 +185,21 @@ public async Task SuppliesCancellationTokenThatSignalsWhenRevalidationLoopIsBein
185185
}
186186

187187
[Fact]
188-
[QuarantinedTest("https://github.com/dotnet/aspnetcore/issues/19940")]
189188
public async Task IfValidateAuthenticationStateAsyncReturnsUnrelatedCancelledTask_TreatAsFailure()
190189
{
191190
// Arrange
192191
var validationTcs = new TaskCompletionSource<bool>();
192+
var incrementExecuted = new TaskCompletionSource<bool>();
193193
var authenticationStateChangedCount = 0;
194194
using var provider = new TestRevalidatingServerAuthenticationStateProvider(
195195
TimeSpan.FromMilliseconds(50));
196196
provider.NextValidationResult = validationTcs.Task;
197197
provider.SetAuthenticationState(CreateAuthenticationStateTask("test user"));
198-
provider.AuthenticationStateChanged += _ => { authenticationStateChangedCount++; };
198+
provider.AuthenticationStateChanged += _ =>
199+
{
200+
authenticationStateChangedCount++;
201+
incrementExecuted.TrySetResult(true);
202+
};
199203

200204
// Be waiting for the first ValidateAuthenticationStateAsync to complete
201205
await provider.NextValidateAuthenticationStateAsyncCall;
@@ -208,6 +212,7 @@ public async Task IfValidateAuthenticationStateAsyncReturnsUnrelatedCancelledTas
208212

209213
// Assert: Since we didn't ask for that operation to be canceled, this is treated as
210214
// a failure to validate, so we force a logout
215+
await incrementExecuted.Task.TimeoutAfter(TimeSpan.FromSeconds(5));
211216
Assert.Equal(1, authenticationStateChangedCount);
212217
var newAuthState = await provider.GetAuthenticationStateAsync();
213218
Assert.False(newAuthState.User.Identity.IsAuthenticated);

0 commit comments

Comments
 (0)