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

Handle correctly waiting for process exit on Unix systems #3410

Merged
merged 8 commits into from
Feb 24, 2022

Conversation

Evangelink
Copy link
Member

Description

Handle correctly waiting for process exit on Unix systems.

Related issue

Fixes #3375

The default failure 'System.ComponentModel.Win32Exception: No such file or directory' is not really helpful to understand what's going-on.
@@ -599,6 +599,11 @@ protected static void ExecuteApplication(string path, string args, out string st
throw new ArgumentException("Executable path must not be null or whitespace.", nameof(path));
}

if (!File.Exists(path))
Copy link
Member Author

@Evangelink Evangelink Feb 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated to this PR, but when trying to debug I noticed that without this check we end up with error like System.ComponentModel.Win32Exception: No such file or directory which isn't really helpful.

@Evangelink Evangelink marked this pull request as ready for review February 23, 2022 14:25
namespace Microsoft.TestPlatform.AcceptanceTests;

[TestClass]
public class ProcessTests : AcceptanceTestBase
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't really find in which existing type this would fit best so I created this one, feel free to suggest alternative.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ProcessesInteractionTests?


[TestClass]
public class ProcessTests : AcceptanceTestBase
{
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that it would be nice to add one more test where we have a specific test adapter (not sure if that's the right "level") that would be hanging so we can prove that the cancellation are correctly done.

If you share the feeling, I'd be happy to be helped to add it.

}
catch (Exception ex) when (ex is InvalidOperationException or TaskCanceledException)
{
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can be useful a log here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe yes. I will have two separate logs depending on the exception type.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I can't because this project references no other project (so no access to EqtTrace). The signature is public so I can't even take some extra parameter.

var runtimeConfigJson = Path.Combine(Path.GetDirectoryName(assemblyPath), "SimpleTestProjectMessedUpTargetFramework.runtimeconfig.json");
var fileContent = File.ReadAllText(runtimeConfigJson);
var updatedContent = fileContent.Replace("\"version\": \"2.1.0\"", "\"version\": \"42\"");
File.WriteAllText(runtimeConfigJson, updatedContent);
Copy link
Contributor

@MarcoRossignoli MarcoRossignoli Feb 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

q: this test is modifying the assets right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes that's why I created a new test asset. I originally thought that we were doing a local copy of the asset for each test but we don't so I wasn't sure how to best do this.

Given the question, I should probably put a comment in the code to explain what/why.

Thanks for pointing it out!

// flush its output and error streams).See https://github.com/microsoft/vstest/issues/3375
var runtimeConfigJson = Path.Combine(Path.GetDirectoryName(assemblyPath), testAssetProjectName + ".runtimeconfig.json");
var fileContent = File.ReadAllText(runtimeConfigJson);
var updatedContent = fileContent.Replace("\"version\": \"2.1.0\"", "\"version\": \"42\"");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe use some version that is lower than when is current, or that we know was not published, I think 2.8.0 was my original proposal? Or 0.0.0?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went with 0.0.0, it seems easier to notice this is invalid version.

{
[TestMethod]
[NetCoreTargetFrameworkDataSource]
public void MissingFrameworkTextIsCorrectlyDisplayed(RunnerInfo runnerInfo)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public void MissingFrameworkTextIsCorrectlyDisplayed(RunnerInfo runnerInfo)
public void WhenTestHostProcessExitsBecauseTheTargetedRuntimeIsNoFoundThenTheMessageIsCapturedFromTheErrorOutput(RunnerInfo runnerInfo)

Might be also worth adding some more info about the problem we were solving.

@Evangelink Evangelink enabled auto-merge (squash) February 24, 2022 17:01
@Evangelink Evangelink merged commit f77ec07 into microsoft:main Feb 24, 2022
@Evangelink Evangelink deleted the process-wait-unix branch February 24, 2022 17:52
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.

Process error and exit callbacks are received in incorrect order for Linux
3 participants