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

Microsoft.CodeAnalysis.CSharp.CommandLine.UnitTests.CommandLineTests.ArgumentParsing is flaky #58077

Open
runfoapp bot opened this issue Dec 2, 2021 · 10 comments

Comments

@runfoapp
Copy link

runfoapp bot commented Dec 2, 2021

Note: the test is skipped in some legs, so the runinfo count below isn't representative of whether it was fixed.

Runfo Tracking Issue: Microsoft.CodeAnalysis.CSharp.CommandLine.UnitTests.CommandLineTests.ArgumentParsing is flaky

Build Definition Kind Run Name

Build Result Summary

Day Hit Count Week Hit Count Month Hit Count
0 0 0
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels Dec 2, 2021
@jasonmalinowski jasonmalinowski changed the title microsoft.codeanalysis.csharp.commandline.unittests.commandlinetests.argumentparsing Microsoft.CodeAnalysis.CSharp.CommandLine.UnitTests.CommandLineTests.ArgumentParsing is flaky Dec 2, 2021
@Youssef1313
Copy link
Member

Youssef1313 commented Dec 3, 2021

I took a quick look at the code. The try/finally block looks suspicious to me. An exception could have been thrown causing the flow to silently go into the finally block. My guess is that an exception was thrown before the part of the code that reports the expected diagnostics.

try
{
bool yielded = false;
// NOTE: Directory.EnumerateFiles(...) surprisingly treats pattern "." the
// same way as "*"; as we don't expect anything to be found by this
// pattern, let's just not search in this case
pattern = pattern.Trim(s_searchPatternTrimChars);
bool singleDotPattern = string.Equals(pattern, ".", StringComparison.Ordinal);
if (!singleDotPattern)
{
while (true)
{
string? resolvedPath = null;
try
{
if (enumerator == null)
{
enumerator = EnumerateFiles(resolvedDirectoryPath, pattern, searchOption).GetEnumerator();
}
if (!enumerator.MoveNext())
{
break;
}
resolvedPath = enumerator.Current;
}
catch
{
resolvedPath = null;
}
if (resolvedPath != null)
{
// just in case EnumerateFiles returned a relative path
resolvedPath = FileUtilities.ResolveRelativePath(resolvedPath, baseDirectory);
}
if (resolvedPath == null)
{
errors.Add(Diagnostic.Create(MessageProvider, (int)MessageProvider.FTL_InvalidInputFileName, path));
break;
}
yielded = true;
yield return resolvedPath;
}
}
// the pattern didn't match any files:
if (!yielded)
{
if (searchOption == SearchOption.AllDirectories)
{
// handling /recurse
GenerateErrorForNoFilesFoundInRecurse(path, errors);
}
else
{
// handling wildcard in file spec
errors.Add(Diagnostic.Create(MessageProvider, (int)MessageProvider.ERR_FileNotFound, path));
}
}
}
finally
{
if (enumerator != null)
{
enumerator.Dispose();
}
}

Specifically, the FileUtilities.ResolveRelativePath(resolvedPath, baseDirectory); call.

Note that this is almost only guesses. May or may not be correct.

@Youssef1313
Copy link
Member

It seems like my guess isn't correct. I removed the try/finally and the test still fails with the same failure (not crashing with an exception as I was expecting)

JoeRobich added a commit that referenced this issue Dec 3, 2021
Skip flaky CommandLine.ArgumentParsing test

See #58077 for more details
JoeRobich added a commit that referenced this issue Dec 6, 2021
* Remove IDE0051 suppression

* Add LayoutKind

* LayoutKind.Sequential

Co-authored-by: Sam Harwell <sam@tunnelvisionlabs.com>

* Create azure-pipelines-integration-dartlab.yml

* Update azure-pipelines-integration-dartlab.yml

* [Async lightbulb] Move suppression fixes to 'Low' priority bucket

Addresses second item in #56843

Prior to this change, all the analyzers that are not high-pri are added to the normal priority bucket and executed at once. This PR further breaks down the normal priority bucket into two buckets as follow:

1. `Normal`: Analyzers that produce at least one fixable diagnostic, i.e. have a corresponding code fixer.
2. `Low`: Analyzers without any fixable diagnostics, i.e. have no corresponding code fixer. These diagnostics will only have Suppression/Configuration quick actions, which are lower priority and always show up at the bottom of the light bulb.

This new bucketing allows us to reduce the number of analyzers that are executed in the Normal priority bucket and hence generate all the non-suppression/configuration code fixes faster in async light bulb.

* Cache last project and compilationWithAnalyzers

* Update test as normal priority bucket has one lesser code action

* Make shallow checkout optional for integration test CI

* Move pipeline checkout skips up a layer.

* Look up VS bootstrapper from build

* Revert skipPipelinesCheckout change

* Comment out checkout: none for now

* Added matrix

* Target topic branch in DartLab.Templates

* Update number of machines to 4

* Run test agent elevated

* Update pipeline description

* Default VS branch to main

* Address feedback

* Exclude unnecessary sqlite assemblies

* Convert namespace to file scoped when typing semicolon

* Working on tests

* Add tests

* Add comments

* Add comments

* Revert

* Revert

* Make static

* Add tests

* Pass AnalysisKind instead of int

* Honor option, and also improve formatting with comment

* Fix comment

* Add tests

* Fix await completion for expression body lambda

* Add new parser/lexer to the StackTraceAnalyzer (#57598)

No functional changes, just moving to the new API and cleaning up unused code

* Add comments

* Make it possible to analyze the dataflow of `ConstructorInitializerSyntax` and `PrimaryConstructorBaseTypeSyntax` (#57576)

Fixes #57577.

* Snap 17.1 P2 (#58041)

* Add new parser/lexer to the StackTraceAnalyzer (#57598) (#58050)

No functional changes, just moving to the new API and cleaning up unused code

* Read SourceLink info and call service to retrieve source from there (#57978)

* Merge pull request #58100 from dotnet/dev/jorobich/skip-test

Skip flaky CommandLine.ArgumentParsing test

See #58077 for more details

Co-authored-by: Youssef Victor <31348972+Youssef1313@users.noreply.github.com>
Co-authored-by: Sam Harwell <sam@tunnelvisionlabs.com>
Co-authored-by: Brad White <4261702+bradselw@users.noreply.github.com>
Co-authored-by: Manish Vasani <mavasani@microsoft.com>
Co-authored-by: Joey Robichaud <jorobich@microsoft.com>
Co-authored-by: Brad White <bradwhit@microsoft.com>
Co-authored-by: gel@microsoft.com <gel@microsoft.com>
Co-authored-by: Cyrus Najmabadi <cyrusn@microsoft.com>
Co-authored-by: Sam Harwell <Sam.Harwell@microsoft.com>
Co-authored-by: Andrew Hall <andrha@microsoft.com>
Co-authored-by: Bernd Baumanns <baumannsbernd@gmail.com>
Co-authored-by: Allison Chou <allichou@microsoft.com>
Co-authored-by: CyrusNajmabadi <cyrus.najmabadi@gmail.com>
Co-authored-by: David Wengier <david.wengier@microsoft.com>
Co-authored-by: Gen Lu <genlu@users.noreply.github.com>
@Youssef1313
Copy link
Member

Youssef1313 commented Dec 8, 2021

My investigations:

string? directory = PathUtilities.GetDirectoryName(path);
string pattern = PathUtilities.GetFileName(path);
var resolvedDirectoryPath = string.IsNullOrEmpty(directory) ?
baseDirectory :
FileUtilities.ResolveRelativePath(directory, baseDirectory);

there are the following variables and their values:

Variable Value
directory "/"
baseDirectory "/tmp/RoslynTests"
resolvedDirectoryPath "/"
  • I'm not sure if resolvedDirectoryPath is supposed to be "/" or not. This comes from FileUtilities.ResolveRelativePath(directory, baseDirectory).
  • There is an empty file named "1" in "/" directory. I don't think this is something expected (but I don't know for sure). I don't know what's writing this file. (If this file didn't exist, then the expected ERR_FileNotFound diagnostic is supposed to be reported)

I hope this provides some entry point for more investigation.

@jaredpar jaredpar removed the untriaged Issues and PRs which have not yet been triaged by a lead label Jan 4, 2022
@jcouv
Copy link
Member

jcouv commented Mar 17, 2022

@Youssef1313 Have you been able to repro this by any chance? What does the failure look like?
OP doesn't provide much info especially since the CI legs that failed are now out of range of the tracking tool...

@jcouv jcouv added this to the Compiler.Next milestone Mar 17, 2022
@jcouv jcouv added the untriaged Issues and PRs which have not yet been triaged by a lead label Mar 17, 2022
@Youssef1313
Copy link
Member

@jcouv I couldn't reproduce locally, but I'd expect a repro to be like:

  • Create an empty file named 1 in / (Linux root directory)
  • Run the test. It should fail.

The questions are:

  • Does the existence of such a file expected to affect the test?
  • Why it existed on CI in the first place?

@Youssef1313
Copy link
Member

@jcouv The test no longer fails on CI. Whatever thing was created the /1 file has gone away. But it would be good to try to reproduce on a Linux machine locally and see if it should have failed with the /1 file in the first place.

@jcouv
Copy link
Member

jcouv commented Mar 18, 2022

@333fred Are you still set up on linux? Could you try the repro provided above to see if we still have a bug?

@jcouv
Copy link
Member

jcouv commented Mar 25, 2022

@333fred Are you still set up on linux? Could you try the #58077 (comment) provided above to see if we still have a bug?

@333fred
Copy link
Member

333fred commented Mar 25, 2022

That does indeed reproduce the bug. Steps:

  1. Change ArgumentParsing to Fact
  2. sudo touch /1 && sudo chown <your_username>:<your_username> /1
  3. dotnet test src/Compilers/CSharp/Test/CommandLine --filter "DisplayName~ArgumentParsing"

@jcouv jcouv self-assigned this Apr 12, 2022
@jcouv jcouv modified the milestones: Compiler.Next, 17.3 Apr 12, 2022
@jcouv jcouv removed the untriaged Issues and PRs which have not yet been triaged by a lead label Apr 12, 2022
@jcouv
Copy link
Member

jcouv commented Apr 12, 2022

Thanks @333fred for the additional linux repro details. I was able to repro and have a fix pending.

@jcouv jcouv modified the milestones: 17.3, Backlog May 27, 2022
@jcouv jcouv removed their assignment May 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants