-
Notifications
You must be signed in to change notification settings - Fork 701
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
Fix tests failing when run on systems with non-English language/locale settings #5442
Fix tests failing when run on systems with non-English language/locale settings #5442
Conversation
@@ -2290,6 +2291,9 @@ public async Task TestPackageManager_DowngradePackageFor_BottomtProject_Success( | |||
[Fact] | |||
public async Task TestPackageManager_CancellationTokenPassed() | |||
{ | |||
// Get exception messages in English | |||
Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make sense to set this globally for all of our tests so that in the future we don't cause this to happen again?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would. The question is how to do it assembly/codebase wise?
Or do we want at least to set this on a test class level instead of individual tests level?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be honest, making the threads run in invariant culture doesn't make me proud of our code quality.
Something I particularly don't like is that there's no cleanup afterwards to set the culture back to the original value. If there are other tests that explicitly want to test some other culture (I think Fernando added one or two within the last 2 years, but before that I'd say NuGet has none), then this could introduce flakiness depending on whether or not the other test re-uses the same thread. We also run tests in parllel, and this method is async, which increases risk that another test could re-use the same thread.
My memory is that xunit has its own set of threads to run tests on, which means that anywhere NuGet does .ConfigureAwait(false)
(which I think we only have two or three examples of, in NuGet.Protocol, but we might end up doing more in the future), or anywhere Task.Run()
is used, code might end up running on the thread pool, which is still using the default UI culture.
There's always a case of "don't let perfect be the enemy of good", so we don't have to change the test code to work correctly when using the default system culture. Maybe this "set current thread UI culture to invariant" is good enough. But how difficult is it to "properly fix" tests instead? I've been meaning to try myself, but I don't want to change my system locale on a machine I really use, and creating a new VM, installing all the dev tools, and cloning the repo has been too much effort for me so far.
This PR has been automatically marked as stale because it has no activity for 7 days. It will be closed if no further activity occurs within another 90 days of this comment. If it is closed, you may reopen it anytime when you're ready again, as long as you don't delete the branch. |
…\ drive Test name: `PerformUpToDateCheck_WhenNonBuildIntegratedProjectIsAParentOfADirtySpec_ReturnsAListWithoutNonBuildIntegratedProjects`
…th non-English locales renamed test to align with the tested behaviour
a1f55b7
to
c621d6a
Compare
I've pushed updated version that uses |
This PR has been automatically marked as stale because it has no activity for 7 days. It will be closed if no further activity occurs within another 90 days of this comment. If it is closed, you may reopen it anytime when you're ready again, as long as you don't delete the branch. |
Bug
Fixes: NuGet/Home#12820
Regression? Last working version:
Description
Fixed tests that were failing when run on systems with non-English language/locale settings
Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture;
.
)Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
where the above was not viablePerformUpToDateCheck_WhenNonBuildIntegratedProjectIsAParentOfADirtySpec_ReturnsAListWithoutNonBuildIntegratedProjects
to useTestDirectory
instead of creating test files inC:\
driveToReadableTimeFormat_Localized_AssumesEnglishLocale_ContainsTimeNumber_Succeeds
toToReadableTimeFormat_Localized_AssumesCurrentCulture_ContainsTimeNumber_Succeeds
so that the name corresponds to the behaviour of method under test (after verifying the way it is being used)PR Checklist
PR has a meaningful title
PR has a linked issue.
Described changes
Tests
Documentation