Skip to content

[BUG] Locator WithResolver not testable #382

@dpvreony

Description

@dpvreony

from @anaisbetts
Consider the following:

  1. Test Initial project structure #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
  2. Test Platform-independent Bitmaps #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
  3. Test Initial project structure #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?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions