-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Error on duplicate test output dirs #16521
Conversation
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. |
7308958
to
3d30dcb
Compare
@@ -128,14 +130,20 @@ public string GetAndValidateTestProjectDirectory(string testProjectName, string | |||
using (var sha256 = SHA256.Create()) | |||
{ | |||
var hash = sha256.ComputeHash(Encoding.UTF8.GetBytes(directoryName.ToString())); | |||
var rand = Guid.NewGuid().ToString("N").Substring(0, 5); |
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.
Path.GetRandomFileName perhaps, or do you need a shorter random string?
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 would prefer not to use random paths. If we have to, I'd prefer to do it only in CI runs so that you have a predictable path locally, and so that you don't have to keep cleaning up your test folder to stop it from growing without bounds.
Alternatively, could we have a mode that makes it an error if the test folder already exists when we try to create it? Then that would help us find all of the tests that have overlapping test folders.
Per #16425 (comment). We've been trying to get a stable path without conflict for years but we still cannot get it right. And I think it is good enough that the test can print out the temp directory, |
So you'd prefer we make it random and print out the directory name? Or print the name that's already being generated? |
We've just been playing whack-a-mole, when we have a test failing that looks like it might be due to this we look for another test that would use the same folder. We should be able to deterministically find all the conflicts by adding logic to error out if the test folder already exists when we try to create it, and running that with an empty test folder. |
Note there is a middle path, which is deterministic + a random suffix. Eg., c:\foo\bar......\mytestmethod.ASD2435SDF ... that avoids collisions, but still leaves a hint as to which test. I have no preference. |
I did a test run with this error and there are quite a lot of individual cases we'll have to handle with this approach. Do we want to allow theories to use the same test folders? |
Yes, ideally each instance of a theory would use a separate test folder. The It's possible that a theory not using different test folders for each instance is less likely to cause flaky failures than an entirely separate test case, as I believe unrelated test cases can be run concurrently while instances of theories are run sequentially. |
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.
Thanks a bunch for fixing all of these!
if (Directory.Exists(directoryPath)) | ||
{ | ||
throw new Exception($"Test dir {directoryPath} already exists"); | ||
} |
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.
By default, we should only error out when running in CI. Otherwise rerunning tests locally will fail by default unless you delete the test directory manually each time.
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.
Do we have a flag for if the tests are running in CI already?
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 there is an MSBuild property or environment variable. Try downloading a binlog from a CI run. Also when the tests are run in helix there may be something that tells us about that. @wli3
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 we can make it an error on default. And add an extra "set environment" and a new env in .\artifacts\sdk-build-env.bat and .\artifacts\sdk-build-env.sh
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.
we need to run .\artifacts\sdk-build-env.bat to build sdk anyway
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.
we need to run .\artifacts\sdk-build-env.bat to build sdk anyway
I basically always run it but a lot of the time it's not necessary. I imagine most people that try to use our repo will just open the .sln in Visual Studio and they'll want the tests to work.
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.
Agreed, I'm went ahead and conditioned it based on the ContinuousIntegrationBuild
property.
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.
will just open the .sln in Visual Studio and they'll want the tests to work.
nothing will work by just open .sln in visual studio
@dsplaisted @wli3 is this good to go? |
Port 'Error on duplicate test output dirs #16521'
Fixes #16490