Vstest: Tests never finish when JsonConvert DefaultSettings changed

Created on 4 Jan 2018  路  3Comments  路  Source: microsoft/vstest

Description

Hopefully I am reporting this in the correct place, sorry if not!
Running in either VS2017 or using dotnet test, the runner hangs indefinitely if the JsonConvert.DefaultSettings have been set as below:

JsonConvert.DefaultSettings = () => new JsonSerializerSettings
{
    ContractResolver = new DefaultContractResolver
    {
        NamingStrategy = new SnakeCaseNamingStrategy()
    }
};

I have tested this using MSTest, Nunit and Xunit and the same issue seems to happen across the board, which leads me to believe its the vstest runner itself.

Steps to reproduce

XUnitTestProject1.zip
Above is a sample project with 2 tests. One which hangs and one which doesn't.

Expected behavior

For the tests to finish running

Actual behavior

Tests never finish running. I have to go and end the dotnet process manually.

Diagnostic logs

logs.zip

Environment

Windows 10, .net core 2.0

bug

Most helpful comment

@ejcoyle88 , thanks for bringing this issue. Investigating this helped us realized how our serialization can get impacted. We plan to discuss this further internally.
The code is open source anyways, if you get a chance, please feel free to contribute.. 馃槂

All 3 comments

@ejcoyle88 , We use JsonConvert.SerializeObject to serialize the message we need to send back to vstest runner. Since you are modifying the default Json Serializer, vstest.console does not understand the message it receives from testhost process. Meanwhile testhost is waiting to receive an appropriate shutdown message from vstest.console, which it never receives. This is causing the system to be in hung state.

Can you please change your test code to not modify Default settings of JsonConvert, rather create your own custom Json Serializer, & use it serialize data? You can take reference from here.

Hi @mayankbansal018,

We've already gone ahead and reworked our projects to use the serializer this way. 馃槃
I reported the issue because many guides seem to suggest setting your JsonConvert settings using the DefaultSettings property, and so this may be an issue other people also see.

If this isn't something that can be fixed within the test runner, it would be much better for debugging if the runner could report an error when the JsonConvert.DefaultSettings are in a form that would cause it to hang.

@ejcoyle88 , thanks for bringing this issue. Investigating this helped us realized how our serialization can get impacted. We plan to discuss this further internally.
The code is open source anyways, if you get a chance, please feel free to contribute.. 馃槂

Was this page helpful?
0 / 5 - 0 ratings