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

Error on duplicate test output dirs #16521

Merged
merged 2 commits into from
Apr 5, 2021
Merged

Conversation

sfoslund
Copy link
Member

@sfoslund sfoslund commented Mar 25, 2021

Fixes #16490

@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.

@sfoslund sfoslund force-pushed the TestOutput branch 2 times, most recently from 7308958 to 3d30dcb Compare March 25, 2021 21:31
@sfoslund sfoslund requested review from wli3, dsplaisted and joeloff March 25, 2021 23:04
@@ -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);
Copy link
Member

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?

Copy link
Member

@dsplaisted dsplaisted left a 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.

@wli3
Copy link

wli3 commented Mar 26, 2021

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,

@sfoslund
Copy link
Member Author

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?

@dsplaisted
Copy link
Member

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,

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.

@danmoseley
Copy link
Member

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.

@sfoslund
Copy link
Member Author

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.

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?

@dsplaisted
Copy link
Member

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.

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 identifier parameter to CreateTestProject or similar methods can be used for this.

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.

@sfoslund sfoslund changed the title Adding random string to test directory generation Error on duplicate test output dirs Mar 30, 2021
Copy link
Member

@dsplaisted dsplaisted left a 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!

Comment on lines +144 to +147
if (Directory.Exists(directoryPath))
{
throw new Exception($"Test dir {directoryPath} already exists");
}
Copy link
Member

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.

Copy link
Member Author

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?

Copy link
Member

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

Copy link

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

Copy link

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

Copy link
Member

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.

Copy link
Member Author

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.

Copy link

@wli3 wli3 Apr 3, 2021

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

@sfoslund
Copy link
Member Author

sfoslund commented Apr 5, 2021

@dsplaisted @wli3 is this good to go?

@sfoslund sfoslund merged commit e4655fd into dotnet:main Apr 5, 2021
@sfoslund sfoslund deleted the TestOutput branch April 5, 2021 20:01
sfoslund added a commit to sfoslund/sdk that referenced this pull request Apr 7, 2021
sfoslund added a commit to sfoslund/sdk that referenced this pull request Apr 7, 2021
sfoslund added a commit that referenced this pull request Apr 12, 2021
Port 'Error on duplicate test output dirs #16521'
TanayParikh added a commit that referenced this pull request Nov 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ensure tests write to separate output directories
5 participants