Conversation
|
I want to include one more change to this PR. Converting to draft for now. |
|
TLTR: I disable Windows EventLog for The issue is not specific for In Used master branch to run
Output for Iteration #0: started, Thread: 12
Stopping 51492383, Thread: 12
Stopping 51492383, Thread: 7
Stopped 51492383, Thread: 12
Stopped 51492383, Thread: 7
Iteration #0: stopped, Thread: 12
Iteration #1: started, Thread: 12
Stopping 44741746, Thread: 12
Stopping 44741746, Thread: 18
Stopped 44741746, Thread: 18
Stopped 44741746, Thread: 12
Iteration #1: stopped, Thread: 12
Iteration #2: started, Thread: 12
Stopping 51772423, Thread: 12
Failed with System.ObjectDisposedException 51772423, Thread: 12
Iteration #2: stopped, Thread: 12
Iteration #3: started, Thread: 12
Stopping 59583888, Thread: 12
Stopping 59583888, Thread: 13
Stopped 59583888, Thread: 13
Stopped 59583888, Thread: 12
Iteration #3: stopped, Thread: 12
Iteration #4: started, Thread: 12
Stopping 3829499, Thread: 12
Failed with System.ObjectDisposedException 3829499, Thread: 12
Iteration #4: stopped, Thread: 12
Iteration #5: started, Thread: 12
Stopping 1636903, Thread: 12
Stopping 1636903, Thread: 18
Stopped 1636903, Thread: 12
Stopped 1636903, Thread: 18
Iteration #5: stopped, Thread: 12
Iteration #6: started, Thread: 12
Stopping 34657907, Thread: 12
Failed with System.ObjectDisposedException 34657907, Thread: 12
Iteration #6: stopped, Thread: 12
Iteration #7: started, Thread: 12
Stopping 24929770, Thread: 12
Failed with System.ObjectDisposedException 24929770, Thread: 12
Iteration #7: stopped, Thread: 12
Iteration #8: started, Thread: 12
Stopping 46209412, Thread: 12
Stopping 46209412, Thread: 18
Stopped 46209412, Thread: 12
Stopped 46209412, Thread: 18
Iteration #8: stopped, Thread: 12
Iteration #9: started, Thread: 12
Stopping 13695991, Thread: 12
Stopping 13695991, Thread: 18
Stopped 13695991, Thread: 12
Stopped 13695991, Thread: 18
Iteration #9: stopped, Thread: 12Output for Runtime2. Version with a lock, single thread calls
|
This PR includes fixes to avoid flaky tests when using Alba.
AlbaHostcan createIHostusing two ways: either owning it directly ("direct" host) or viaIAlbaWebApplicationFactory("factory" host). Ideally both types should behave the same, but it's not the case. E.g. whenAlbaHost.StopAsyncis called only "direct" host is stoppedalba/src/Alba/AlbaHost.cs
Line 105 in f2c0641
I make
StopAsyncto behave the same for both types. It can make some workarounds redundant (see Fix flaky Wolverine.Http.Tests wolverine#2218 (comment)).AlbaHost itself have flaky tests. Set of the tests if running together can return unexpected 401 status codes. The problem is caused by code from Microsoft.Identity.Web. There is a static singleton - LogHelper.Logger - configured by the library (see https://github.com/AzureAD/microsoft-identity-web/blob/716239cb42aa167b5ae2a221e8b3bf1681afbd5b/src/Microsoft.Identity.Web.TokenAcquisition/MicrosoftIdentityBaseAuthenticationBuilder.cs#L69). One scenario completes, the host is disposed, but the static singleton keeps the disposed services (e.g.
EventLogInternal). When another scenario is running token validation tries to log and fails withObjectDisposedException. As the result a valid token returns unexpected 401 status code.I disable logging for Microsoft.Identity.Web to avoid using the static singleton.
Two selected tests (or the whole set from the screenshot) when running together fail:

This is how token validation fails:
