splat
splat copied to clipboard
[BUG] Locator WithResolver not testable
from @anaisbetts Consider the following:
- Test #1 calls WithResolver(), as a part of that by default we suppress auto-registration - this is implemented as an atomic refcount, we add a ref
- Test #2 kicks off, it calls WithResolver(false) - we set the resolver, but because the prev ref is still at 1, the new resolver doesn't get initialized
- Test #1 finally finishes, we remove our ref (edited)
The ThreadStatic trick is definitely like, a compromise Basically the core idea is, if you try to Set the locator, and you're in a unit test, we'll per-thread set it If you're in the app, we never do this ThreadStatic bizness MainThreadScheduler works similarly So it means you can have two tests who pave Locator at the same time, and they might work, ofc if you schedule a Task everything falls over But, we make you fall over a little less often What you really want is "TaskContextStatic", i.e. something that follows the same "context" across a bunch of threads
Which I think exists now, but definitely didn't at the time Maybe this is https://docs.microsoft.com/en-us/dotnet/api/system.threading.asynclocal-1?redirectedfrom=MSDN&view=netframework-4.8?