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

Added support for debugging external test processes #2325

Conversation

cvpoienaru
Copy link
Member

@cvpoienaru cvpoienaru commented Feb 11, 2020

@cvpoienaru cvpoienaru requested review from shyamnamboodiripad, jakubch1 and AbhitejJohn and removed request for jakubch1 February 11, 2020 21:24
@cvpoienaru cvpoienaru changed the title [WIP] Initial support for debugging external test processes Added support for debugging external test processes Feb 26, 2020
Copy link
Member

@nohwnd nohwnd 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 look into using default implementation for interfaces, which was introduced in c# 8, that should avoid adding a new 2 interfaces, and the change propagating through the other interfaces that consume the original interface. This feature was made for this exact purpose (from what I understood), to allow extending published interfaces with new functionality.

@cvpoienaru cvpoienaru self-assigned this Mar 2, 2020
@cvpoienaru cvpoienaru added this to the 16.6.0 milestone Mar 2, 2020
/// Creates a new instance of this class.
/// </summary>
/// <param name="pid">The process id the debugger should attach to.</param>
public TestProcessAttachDebuggerPayload(int pid)
Copy link
Contributor

Choose a reason for hiding this comment

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

int pid [](start = 48, length = 7)

Well the other comment got me asking this - What is our plan for attaching to a process on another compute resource(docker container/remote VM)? Would we need to add anything else in this structure to avoid creating a TestProcessAttachDebuggerPayload2?

Copy link
Contributor

Choose a reason for hiding this comment

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

I believe so far the remote debugger does supports attaching to process by PID in the docker case and that would not require any API changes here. There is a bug with the old launch and attach workflow where the debugger APIs were not returning the PID - @drognanar is working with the docker / debugger folks on a fix for that.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see, would a property bag still be useful in this case? In case Attach needs additional information.

Copy link
Contributor

@shyamnamboodiripad shyamnamboodiripad May 12, 2020

Choose a reason for hiding this comment

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

Do you mean an open-ended dictionary of string-object or something else? I'd hate to add something to the API without understanding the scenario. Its probably ok to rev the API again if we need to - but I don't think we should create an API without fully understanding how it will be used.

Copy link
Contributor

Choose a reason for hiding this comment

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

So one of the things that came up for the LaunchProcessWithDebuggerAttached was to be able to pass back DebuggerGuids. With Attach though, I'm thinking off something like remote machine details for instance. A string-string would just do given the content can be serialized.

Copy link
Member

Choose a reason for hiding this comment

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

Right now I'm definitely taking a dependency on us using vsdbg to start a debugger and passing a JSON specifically for .NET. My original thought was to link the debugger choice back to the containers. If we would want to have a C# project launch a debugger for a node.exe, then we would need to have additional parameters in this method.

Also, I've been passing back RemoteEnvironment from the request back to VS, so we don't need to specify that again in the testhost (unless the testhost would start a test process on another machine than where the testhost lives).

Copy link
Member

Choose a reason for hiding this comment

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

In short currently we're using the information from the test container, the runtime provider and the pid in order to create an appropriate attach request.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, non-managed workflows was what I was thinking off as well. I'm not sure what other parameters would be required there.

Copy link
Contributor

Choose a reason for hiding this comment

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

Adding in a string-string property bag and terming it as options wouldn't hurt much I'd think.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think if we have to do that we'd also need to add it to the LaunchAndAttach API for completeness - including to the IFrameworkHandle APIs that are exposed to adapter.

I'm a bit loath to do all that as part of the current change as its not required for this change + we haven't really proved that we need it (as far as I can tell we don't have a real need for it for Docker so far). We may discover that we need something else / different API shape when we actually get to implementing remote debugging support where additional data is required (for example SSH / remote VM).

So I feel it may be best to wait and introduce those APIs as and when the need arises.

@cvpoienaru
Copy link
Member Author

I agree, that sounds like something we could benefit from here. This did come up earlier too but I'm not sure why we couldn't move. Is anything blocking vstest from moving to C# 8?

In reply to: 364763134 [](ancestors = 364763134)

I got really excited when this was first proposed. It would've saved us a lot of headaches down the road, but unfortunately won't work on today's implementation and that's kind of a bummer :(

Quoting @shyamnamboodiripad reply: (#2325 (comment)) "Unfortunately, default interface implementation depends on CLR features that are not available when targeting net472 (requires netcoreapp3.0). Since VS and many test adapters still run atop net472 I don't believe we can use default interface implementation yet."

@cvpoienaru cvpoienaru closed this May 13, 2020
@cvpoienaru cvpoienaru reopened this May 13, 2020
this.testPlatformEventSource.AdapterExecutionStop(this.testRunCache.TotalExecutedTests - currentTotalTests);
attachedToTestHost = true;
var pid = Process.GetCurrentProcess().Id;
if (!this.frameworkHandle.AttachDebuggerToProcess(pid))
Copy link
Contributor

Choose a reason for hiding this comment

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

AttachDebuggerToProcess [](start = 46, length = 23)

Do we already have telemetry that logs the protocol versions across vstest.console, testhost and in this case how many adapters implement ITestExecutor2? It would be useful for us to understand usage stats.

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'll open another follow-up task to add telemetry.

@AbhitejJohn
Copy link
Contributor

public interface ITestRequestHandler : IDisposable

So this interface could be made internal too?


Refers to: src/Microsoft.TestPlatform.CommunicationUtilities/Interfaces/ITestRequestHandler.cs:17 in 234a53c. [](commit_id = 234a53c, deletion_comment = False)

@AbhitejJohn
Copy link
Contributor

AbhitejJohn commented May 18, 2020

public interface IDesignModeClient : IDisposable

can be made internal?


Refers to: src/Microsoft.TestPlatform.Client/DesignMode/IDesignModeClient.cs:15 in 234a53c. [](commit_id = 234a53c, deletion_comment = False)

Copy link
Contributor

@AbhitejJohn AbhitejJohn left a comment

Choose a reason for hiding this comment

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

:shipit:

@AbhitejJohn
Copy link
Contributor

How are we tracking the documentation update and filling in the test matrix we discussed?

@cvpoienaru
Copy link
Member Author

cvpoienaru commented May 18, 2020

ITestRequestHandler and IDesignModeClient cannot be made internal without significant work outside the scope of this PR. I already opened an issue here to track this change: #2362

I'll also open another issue to keep track of the documentation task.

@cvpoienaru cvpoienaru changed the title WIP: Added support for debugging external test processes Added support for debugging external test processes May 18, 2020
@cvpoienaru cvpoienaru merged commit 3f18c87 into microsoft:master May 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants