Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

Set fixed culture for CookieContainer blob sanity check #23285

Merged
merged 2 commits into from
Aug 17, 2017

Conversation

ViktorHofer
Copy link
Member

Fixes https://github.com/dotnet/corefx/issues/21720

Not defining a fixed culture causes various test cases to fail sometimes as the at runtime instantiated object isn't the same as the serialized stored one.

RemoteExecutor isn't possible in this case as we can't let every test case (~300) invoke a new RemoteExecutor instance. Try-Finally pattern is also not possible as we are using yield return statements. For this method I think this is the best solution.

@stephentoub
Copy link
Member

RemoteExecutor isn't possible in this case as we can't let every test case (~300) invoke a new RemoteExecutor instance.

Why is that prohibitive?

@@ -42,6 +42,10 @@ public static IEnumerable<object[]> SerializableEqualityComparers_MemberData()
/// </summary>
public static IEnumerable<object[]> SerializableObjects_MemberData()
{
// Save old culture and set a fixed culture for object instantiation
CultureInfo oldCulture = CultureInfo.CurrentCulture;
CultureInfo.CurrentCulture = new CultureInfo("en-US");
Copy link
Member

Choose a reason for hiding this comment

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

As this is an iterator, control returns to the caller at each yield point, and we don't know what xunit does or doesn't do between each yield. That means we're changing the culture on a thread that will then potentially be used for something else. If you want to do it this way, we should change SerializableObject_MemberData to not be an iterator, e.g. just have it return and return an object[][] populated with all of these entries, rather than yielding them. Then you can set the culture before, and unset it after in a finally block, and no one else will use the thread in the interim.

That said, I was under the impression this setting of culture like this was a no-no on uapaot, as it currently has process-wide impact, which is why we use RemoteInvoke for these. Has that been fixed, or if not, why is this ok in this case?
cc: @tarekgh

Copy link
Member

Choose a reason for hiding this comment

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

I would recommend any test setting current culture to be executed remotely even if the test not UAP specific test. This will make the test more predictable and reliable.

by the way, we have a request (and tracking issue) to enable the way in uap to use current culture as it is used in the desktop apps.

Copy link
Member Author

Choose a reason for hiding this comment

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

@stephentoub I will follow your suggestion and change the method from an iterator to simply return the object[][] array and inside of it use a try - finally block. Thanks for the tip, that's better than my current solution.

I don't want to change the test roundtripping test to use RemoteExecutor as some downsides come with it:
a) Test execution time increases dramatically
b) Refactoring would needed to be done so that all the object instantiations and checks would happen inside the RemoteExecutor. That would mean that we can't use the MemberData xunit pattern and everything would execute in one test instead of 300 separate tests. For mc logging I don't really want to go that way, mainly, because I already had it like that before and even with extensive logging the test behavior and possible exceptions was hard to understand.

Because of these reasons I want to avoid using an RemoteExecutor here. If other tests in other classes rely on the culture I could still put the xunit argument (forgot its name) onto the class to not execute both at the same time.

@tarekgh
Copy link
Member

tarekgh commented Aug 16, 2017

other than @stephentoub comment, LGTM.

@ViktorHofer ViktorHofer force-pushed the OSXSerialization branch 2 times, most recently from 199ff77 to d97c4e0 Compare August 17, 2017 14:21
@ViktorHofer
Copy link
Member Author

@stephentoub PTAL

@stephentoub stephentoub merged commit 04c1a2c into dotnet:master Aug 17, 2017
@karelz karelz modified the milestone: 2.1.0 Aug 20, 2017
ViktorHofer added a commit to ViktorHofer/corefx that referenced this pull request Aug 24, 2017
* Set fixed culture for CookieContainer blob sanity check

* PR feedback
ViktorHofer added a commit to ViktorHofer/corefx that referenced this pull request Aug 24, 2017
* Set fixed culture for CookieContainer blob sanity check

* PR feedback
picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
…x#23285)

* Set fixed culture for CookieContainer blob sanity check

* PR feedback


Commit migrated from dotnet/corefx@04c1a2c
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
5 participants