[Azure Search] Remove JsonConvert.DefaultSettings check from unit tests #4053
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.
Some time ago, we added a check to every Azure Search unit test that uses the Run() method. This check is intended to ensure that none of our SDK code uses the global JsonConvert.DefaultSettings, since these can be altered by other code in the same AppDomain. This was causing issues for customers, and is the reason we added SafeJsonConvert to ClientRuntime and AutoRest.
The check in the Run() method installs a custom JsonConverter and ContractResolver that throw exceptions whenever they're called. It does this using a try/finally block so that the change should only be visible while running the unit test.
Unfortunately, since JsonConvert.DefaultSettings is global state, this approach is fragile. For example, running tests in parallel can break this because some infrastructure such as the VS test runner framework itself uses JSON.NET in ways that rely on DefaultSettings.
Given the fragility of this approach, we've decided to remove these checks altogether since they were causing spurious test failures.
Description
This checklist is used to make sure that common guidelines for a pull request are followed.
General Guidelines
Testing Guidelines
SDK Generation Guidelines
*.csproj
andAssemblyInfo.cs
files have been updated with the new version of the SDK.