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

ToolInstallCommandTests.WhenRunWithRoot is flaky #42346

Open
akoeplinger opened this issue Jul 24, 2024 · 2 comments
Open

ToolInstallCommandTests.WhenRunWithRoot is flaky #42346

akoeplinger opened this issue Jul 24, 2024 · 2 comments
Labels

Comments

@akoeplinger
Copy link
Member

akoeplinger commented Jul 24, 2024

Build Information

Build: https://dev.azure.com/dnceng-public/cbb18261-c48f-4abb-8651-8cdcb5474649/_build/results?buildId=753617
Build error leg or test failing: Microsoft.DotNet.Tests.Commands.Tool.ToolInstallCommandTests.WhenRunWithRoot
Pull request: #42343

Error Message

Fill the error message using step by step known issues guidance.

{
  "ErrorMessage": "Microsoft.DotNet.Tests.Commands.Tool.ToolInstallCommandTests.WhenRunWithRoot [FAIL]",
  "ErrorPattern": "",
  "BuildRetry": false,
  "ExcludeConsoleLog": false
}

Known issue validation

Build: 🔎 https://dev.azure.com/dnceng-public/public/_build/results?buildId=753617
Error message validated: [Microsoft.DotNet.Tests.Commands.Tool.ToolInstallCommandTests.WhenRunWithRoot [FAIL]]
Result validation: ✅ Known issue matched with the provided build.
Validation performed at: 7/24/2024 4:34:26 PM UTC

Report

Summary

24-Hour Hit Count 7-Day Hit Count 1-Month Count
0 0 0
@akoeplinger
Copy link
Member Author

The test was added in #40800 and it fails like this:

      StdErr:
      Creating this template will make changes to existing files:
        Overwrite   ./.config/dotnet-tools.json
      
      To create the template anyway, run the command with '--force' option:
         dotnet new tool-manifest --debug:custom-hive /tmp/folder --force
      
      For details on the exit code, refer to https://aka.ms/templating-exit-codes#73
      
      Stack Trace:
           at FluentAssertions.Execution.XUnit2TestFramework.Throw(String message)
           at FluentAssertions.Execution.TestFrameworkProvider.Throw(String message)
           at FluentAssertions.Execution.DefaultAssertionStrategy.HandleFailure(String message)
           at FluentAssertions.Execution.AssertionScope.FailWith(Func`1 failReasonFunc)
           at FluentAssertions.Execution.AssertionScope.FailWith(Func`1 failReasonFunc)
           at FluentAssertions.Execution.AssertionScope.FailWith(String message)
        /_/test/Microsoft.NET.TestFramework/Assertions/CommandResultAssertions.cs(29,0): at Microsoft.NET.TestFramework.Assertions.CommandResultAssertions.Pass()
        /_/test/dotnet.Tests/CommandTests/ToolInstallCommandTests.cs(49,0): at Microsoft.DotNet.Tests.Commands.Tool.ToolInstallCommandTests.WhenRunWithRoot()
           at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
           at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)

Looking at the test code I think this is because it uses Directory.SetCurrentDirectory and if other tests run at the same time this will mess up the working directory.

[Fact]
public void WhenRunWithRoot()
{
Directory.CreateDirectory("/tmp/folder/sub");
var directory = Directory.GetCurrentDirectory();
var ridGraphPath = TestContext.GetRuntimeGraphFilePath();
try
{
Directory.SetCurrentDirectory("/tmp/folder");
new DotnetNewCommand(Log, "tool-manifest").WithCustomHive("/tmp/folder").WithWorkingDirectory("/tmp/folder").Execute().Should().Pass();
var parseResult = Parser.Instance.Parse("tool install dotnetsay");
new ToolInstallLocalCommand(parseResult, runtimeJsonPathForTests: ridGraphPath).Execute().Should().Be(0);
Directory.SetCurrentDirectory("/tmp/folder/sub");
new DotnetNewCommand(Log, "tool-manifest").WithCustomHive("/tmp/folder/sub").WithWorkingDirectory("/tmp/folder/sub").Execute().Should().Pass();
parseResult = Parser.Instance.Parse("tool install dotnetsay");
new ToolInstallLocalCommand(parseResult, runtimeJsonPathForTests: ridGraphPath).Execute().Should().Be(0);
new ToolRunCommand(Parser.Instance.Parse($"tool run dotnetsay")).Execute().Should().Be(0);
}
finally
{
Directory.SetCurrentDirectory(directory);
}
}

/cc @Forgind

@nagilson
Copy link
Member

@akoeplinger Thank you for your investigation and filing this issue. I think your summarization looks correct. @Forgind, may you please look into fixing this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants