AzureAD / microsoft-authentication-library-for-dotnet

Microsoft Authentication Library (MSAL) for .NET
https://aka.ms/msal-net
MIT License
1.39k stars 341 forks source link

[Bug] Nightly build fails frequently due to unstable test #3396

Open trwalke opened 2 years ago

trwalke commented 2 years ago

The test that seems to fail very frequently is ATS_NonExpired_NeedsRefresh_AADUnavailableResponse_Async

error: Assert.IsTrue failed. Background refresh 2 did not execute.

Stack Trace: at Microsoft.Identity.Test.Unit.PublicApiTests.RefreshInTests.ATS_NonExpired_NeedsRefresh_AADUnavailableResponse_Async() in \tests\Microsoft.Identity.Test.Unit\PublicApiTests\RefreshInTests.cs:line 153 at Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.ThreadOperations.ExecuteWithAbortSafety(Action action)

Logs Output: Debug Trace: Framework: .NET Core Test started ATS_NonExpired_NeedsRefresh_AADUnavailableResponse_Async

  1. Setup an app with a token cache with one AT
  2. Setup an app with a token cache with one AT
  3. Configure AT so that it shows it needs to be refreshed
  4. Configure AAD to respond with a 500 error Test ATS_NonExpired_NeedsRefresh_AADUnavailableResponse_Async adds an HttpMessageHandler for https://login.microsoftonline.com/common/discovery/instance Test ATS_NonExpired_NeedsRefresh_AADUnavailableResponse_Async adds an HttpMessageHandler for Test ATS_NonExpired_NeedsRefresh_AADUnavailableResponse_Async adds an HttpMessageHandler for Test ATS_NonExpired_NeedsRefresh_AADUnavailableResponse_Async dequeued a mock handler for https://login.microsoftonline.com/common/discovery/instance Test ATS_NonExpired_NeedsRefresh_AADUnavailableResponse_Async dequeued a mock handler for Test ATS_NonExpired_NeedsRefresh_AADUnavailableResponse_Async dequeued a mock handler for Test ATS_NonExpired_NeedsRefresh_AADUnavailableResponse_Async adds an HttpMessageHandler for Test finished ATS_NonExpired_NeedsRefresh_AADUnavailableResponse_Async Which version of MSAL.NET are you using? 4.44.0

Repro The test seems to fail randomly but does occur about 2-3 times a week during nightly builds.

bgavrilMS commented 2 years ago

This happens because the background refresh adds jitter between -5 min and + 5 min, so the test can potentially wait up to 5 min for the background refresh to occur. This needs to be refactored so that tests can control the jitter interval.

localden commented 4 months ago

@trwalke @bgavrilMS is this still the case?