Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Azure Search] Remove JsonConvert.DefaultSettings check from unit tests #4053

Merged

Conversation

brjohnstmsft
Copy link
Member

@brjohnstmsft brjohnstmsft commented Feb 7, 2018

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

  • Title of the pull request is clear and informative.
  • There are a small number of commits, each of which have an informative message. This means that previously merged commits do not appear in the history of the PR. For more information on cleaning up the commits in your PR, see this page.

Testing Guidelines

  • Pull request includes test coverage for the included changes.

SDK Generation Guidelines

  • If an SDK is being regenerated based on a new swagger spec, a link to the pull request containing these swagger spec changes has been included above.
  • The generate.cmd file for the SDK has been updated with the version of AutoRest, as well as the commitid of your swagger spec or link to the swagger spec, used to generate the code.
  • The *.csproj and AssemblyInfo.cs files have been updated with the new version of the SDK.

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.
@shahabhijeet shahabhijeet merged commit 194dfa9 into Azure:psSdkJson6 Feb 7, 2018
@brjohnstmsft brjohnstmsft deleted the fix-search-test-failures branch February 7, 2018 22:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants