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

Migrate host.tests from Newtonsoft to STJ #76901

Merged
merged 2 commits into from
Oct 21, 2022

Conversation

am11
Copy link
Member

@am11 am11 commented Oct 11, 2022

Also updated FluentAssertions and Moq packages to latest versions (which are available in internal nuget feed).

@dotnet-issue-labeler
Copy link

I couldn't figure out the best area label to add to this PR. If you have write-permissions please help me learn by adding exactly one area label.

@ghost ghost added the community-contribution Indicates that the PR has been added by a community member label Oct 11, 2022
@am11
Copy link
Member Author

am11 commented Oct 11, 2022

Newtonsoft PackageReference will still be there in assets, as some tests publish the project and verify that the types from external dependencies are loaded.

@am11 am11 force-pushed the feature/host/migrate-newtonsoft-stj branch 3 times, most recently from de46dd7 to c43f539 Compare October 11, 2022 20:15
@am11 am11 closed this Oct 11, 2022
@am11 am11 reopened this Oct 11, 2022
@am11 am11 force-pushed the feature/host/migrate-newtonsoft-stj branch 4 times, most recently from 6b70fd4 to 1e266f6 Compare October 12, 2022 10:26
@am11 am11 force-pushed the feature/host/migrate-newtonsoft-stj branch from 1e266f6 to 608150a Compare October 12, 2022 10:49
@am11 am11 marked this pull request as ready for review October 12, 2022 12:42
@am11 am11 requested a review from vitek-karas October 12, 2022 12:45
{
return new Framework((string)jobject["name"], (string)jobject["version"])
return new Framework(jobject["name"].ToString(), jobject["version"].ToString())
Copy link
Member Author

@am11 am11 Oct 12, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eiriktsarpalis, the reason for changing this line was; given these two files:

{  "name": "foo" }
{  "name": false }

first one successfully casts to string but second one throws an exception about 'False' type conversion to System.String.

If this is not an intentional decision then IMO, we should allow explicit cast to string on JsonNode for all JSON types.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is by design -- Any coercions from bool to string will need to be performed explicitly by the user.

Copy link
Member

@eerhardt eerhardt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DependencyModel tests LGTM

@@ -21,121 +21,121 @@ public CommandResultAssertions(CommandResult commandResult)
public AndConstraint<CommandResultAssertions> ExitWith(int expectedExitCode)
{
Execute.Assertion.ForCondition(Result.ExitCode == expectedExitCode)
.FailWithPreformatted($"Expected command to exit with {expectedExitCode} but it did not.{GetDiagnosticsInfo()}");
.FailWith($"Expected command to exit with {expectedExitCode} but it did not.{GetDiagnosticsInfo()}");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought we had to explicitly use our extension and AddFailure (or I guess AddPreFormattedFailure in newer versions) because FailWith would always go through the the FluentAssertions formatter which messed with things like newlines. Does the new version not do that anymore?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There were a lot of API changes between v4 and the latest v6. AssertionScope.Succeeded etc. are not available on public surface anymore.

FailWith would always go through the the FluentAssertions formatter which messed with things like newlines.

If this is still a problem, we can change the behavior with AssertionOptions.FormattingOptions.UseLineBreaks = true (or fluent API .UsingLineBreaks).

Copy link
Member

@elinor-fung elinor-fung left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@am11
Copy link
Member Author

am11 commented Oct 20, 2022

Ready to merge? :)

cc @ilonatommy, in case we want to drop Newtonsoft.Json dependency in favor of shared framework's System.Text.Json from BrowserDebugProxy, we can use this as reference for migration.

@elinor-fung
Copy link
Member

Ah, thanks for the ping.

Are the wasm failures pre-existing/known? cc @lewing @radical
They all seem to be from hitting IndexOutOfRangeException when using mocks, so I'd like to check that it is not from moving to the newer Moq package.

From https://dev.azure.com/dnceng-public/public/_build/results?buildId=49477&view=ms.vss-test-web.build-test-results-tab&runId=999620&resultId=127840&paneView=debug:

[FAIL] System.ComponentModel.Tests.TypeDescriptionProviderTests.IsSupportedType_NullTypeWithParent_ThrowsArgumentNullException
System.IndexOutOfRangeException : Index was outside the bounds of the array.
   at Castle.DynamicProxy.Generators.MethodWithInvocationGenerator.BuildProxiedMethodBody(MethodEmitter , ClassEmitter , INamingScope )
   at Castle.DynamicProxy.Generators.MethodGenerator.Generate(ClassEmitter , INamingScope )
   at Castle.DynamicProxy.Contributors.CompositeTypeContributor.ImplementMethod(MetaMethod , ClassEmitter , OverrideMethodDelegate )
   at Castle.DynamicProxy.Contributors.CompositeTypeContributor.ImplementProperty(ClassEmitter , MetaProperty )
   at Castle.DynamicProxy.Contributors.CompositeTypeContributor.Generate(ClassEmitter )
   at Castle.DynamicProxy.Generators.BaseClassProxyGenerator.GenerateType(String , INamingScope )
   at Castle.DynamicProxy.Generators.BaseProxyGenerator.<>c__DisplayClass13_0.<GetProxyType>b__0(CacheKey )
   at Castle.Core.Internal.SynchronizedDictionary`2[[Castle.DynamicProxy.Generators.CacheKey, Castle.Core, Version=5.0.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc],[System.Type, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].GetOrAdd(CacheKey , Func`2 )
   at Castle.DynamicProxy.Generators.BaseProxyGenerator.GetProxyType()
   at Castle.DynamicProxy.DefaultProxyBuilder.CreateClassProxyType(Type , Type[] , ProxyGenerationOptions )
   at Castle.DynamicProxy.ProxyGenerator.CreateClassProxyType(Type , Type[] , ProxyGenerationOptions )
   at Castle.DynamicProxy.ProxyGenerator.CreateClassProxy(Type , Type[] , ProxyGenerationOptions , Object[] , IInterceptor[] )
   at Moq.CastleProxyFactory.CreateProxy(Type , IInterceptor , Type[] , Object[] )
   at Moq.Mock`1[[System.ComponentModel.TypeDescriptionProvider, System.ComponentModel.TypeConverter, Version=7.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a]].InitializeInstance()
   at Moq.Mock`1[[System.ComponentModel.TypeDescriptionProvider, System.ComponentModel.TypeConverter, Version=7.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a]].OnGetObject()
   at Moq.Mock.get_Object()
   at Moq.Mock`1[[System.ComponentModel.TypeDescriptionProvider, System.ComponentModel.TypeConverter, Version=7.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a]].get_Object()
   at System.ComponentModel.Tests.TypeDescriptionProviderTests.IsSupportedType_NullTypeWithParent_ThrowsArgumentNullException()
   at System.Reflection.MethodInvoker.InterpretedInvoke(Object , Span`1 , BindingFlags )

@radical
Copy link
Member

radical commented Oct 20, 2022

The wasm failures are being hit only when the tests are trimmed. So, this is likely missing something that needs to be preserved, like in https://github.com/dotnet/runtime/blob/main/eng/testing/ILLinkDescriptors/ILLink.Descriptors.Castle.xml

@am11
Copy link
Member Author

am11 commented Oct 21, 2022

Remaining failures are unrelated #77282.

@elinor-fung elinor-fung merged commit b4a3c68 into dotnet:main Oct 21, 2022
@elinor-fung
Copy link
Member

Thanks, @am11!

@am11 am11 deleted the feature/host/migrate-newtonsoft-stj branch October 21, 2022 03:40
@ghost ghost locked as resolved and limited conversation to collaborators Nov 25, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-Infrastructure-installer community-contribution Indicates that the PR has been added by a community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants