Fix intermittient test failures that use Locator, introduced a scope #4251
+135
−145
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request introduces a new
LocatorScopehelper to safely isolate and restore the global service locator state (Locator.Current) during tests, and applies it to several test fixtures that modify the locator. This change ensures better test reliability and prevents state leakage between tests. Additionally, the documentation is updated to reflect the new approach.Test isolation improvements:
LocatorScopeclass inReactiveUI.Tests.Infrastructure.StaticStateto snapshot and restoreLocator.Currentduring tests, preventing global state leakage and making tests more reliable.CommandBindingTests,MessageBusTest,RoutedViewHostTests,ViewModelViewHostTests) to useLocatorScopein their setup and teardown methods, ensuring the service locator is properly isolated for each test run. [1] [2] [3] [4]Test metadata and documentation:
WhenAnyObservableTestsas[NotInParallel]and added XML documentation explaining the need for test isolation due to reliance on the service locator.LocatorScopewhere required. [1] [2]Documentation updates:
StaticState/README.mdand replaced its guidance with the newLocatorScopeapproach for managing static state in tests.