-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Test-Connection
- Improve Logic and Output
#10697
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
Test-Connection
- Improve Logic and Output
#10697
Conversation
Rather than instantiate a new Ping() every time, we can store it in a readonly field and just call Send() as needed.
This uses the SendAsync() method with a manual reset shim, allowing us to cancel the ping if needed. For example, in the case of StopProcessing() being called, the cmdlet can properly process the request and halt processing, throwing the correct errors as needed.
All output is provided as soon as the PingReply is received, using a new class to format the output (PingStatus). Also added a FormatView for PingStatus.
🎨 Update formatview definitions to include traceroutes ♻️ move formatviewdefintions to proper location in file
♻️ Small amount of cleanup
Errors out when trying to SendPingAsync() too quickly in succession
@SteveL-MSFT Samples of output: Default -Ping Output-Traceroute Output-Traceroute -ResolveDestination Output-MtuSize Output-IPv6 (with IPv4 address)-IPv4 (with IPv6 address) |
src/Microsoft.PowerShell.Commands.Management/commands/management/TestConnectionCommand.cs
Show resolved
Hide resolved
6fbafa7
to
cf7d523
Compare
src/Microsoft.PowerShell.Commands.Management/commands/management/TestConnectionCommand.cs
Show resolved
Hide resolved
src/Microsoft.PowerShell.Commands.Management/commands/management/TestConnectionCommand.cs
Show resolved
Hide resolved
@SteveL-MSFT @iSazonov @TravisEz13 I checked https://github.com/dotnet/corefx/issues/28934 recently and saw they pushed it back to 5.0 for now. Can we make a judgement call on the way forward here? This implementation, while doing more work than it should need to, is at least (in my opinion) more usable and functional on every platform than the existing implementation, and makes use of the most effective parts of the API surface currently available. In my opinion, having this in PS7 to have a more user-friendly cmdlet would be better than waiting until .NET 5 for the API to be fixed. 🙂 I'm more than happy to do the later rewrite when the .NET Core team (finally) fix their Ping APIs. 😁 |
@vexx32 I don't think we should hold this waiting on .NET (should open a new issue linked to corefx, I can tag it for vNext). I'll spend some time reviewing this today. |
Went back through ping / test-connection issues and found this one: I think this PR addresses that as well 🤔 |
@SteveL-MSFT looks like we've been tracking this in #4240; I think we can continue to track this there. 🙂 |
src/Microsoft.PowerShell.Commands.Management/commands/management/TestConnectionCommand.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.PowerShell.Commands.Management/commands/management/TestConnectionCommand.cs
Outdated
Show resolved
Hide resolved
.AddHeader(Alignment.Right, label: "Latency(ms)", width: 7) | ||
.AddHeader(Alignment.Right, label: "BufferSize(B)", width: 10) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is formatting, we can make changes in the future based on user feedback
@PoshChan please retry windows |
@vexx32, successfully started retry of |
/// <summary> | ||
/// Gets the target address of the ping. | ||
/// </summary> | ||
public IPAddress? Address { get => Reply.Status == IPStatus.Success ? Reply.Address : null; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting. Querying the Reply.Address in the latest build I got from CI appears to be... broken.
PS> $a.Reply.Address
OverloadDefinitions
-------------------
System.Object&, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e Address(int )
I'll have to make sure I rebase this PR and see if this is resolved in a later .NET core preview. Querying the address in different ways does work, but something is a bit screwy with the auto-property. Gonna look into this probably this evening, should hopefully not be a complex fix. 🤞
(This is a bit of an oddity because this actually causes it to be hidden in the formatter, which is just super odd.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FIgured it out. Pushing a fix.
@@ -1,8 +1,12 @@ | |||
// Copyright (c) Microsoft Corporation. All rights reserved. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vexx32, your last commit had 1 failures in PowerShell-CI-windows
Test-Connection.Ping.Force IPv4 with explicit PingOptions
Expected $true, but got $false.
at <ScriptBlock>, D:\a\1\s\test\powershell\Modules\Microsoft.PowerShell.Management\Test-Connection.Tests.ps1: line 103
103: $result1.Reply.Options.DontFragment | Should -BeTrue
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@SteveL-MSFT I have confirmed with a manual test that this regression comes from .NET Core itself -- a manual use of the Ping.Send() or SendAsync() exhibits this behaviour where a DontFragment setting is ignored (or at least not returned as set from the ping reply).
This appears to be a new regression since the 3.0 release.
This API is... getting more fragile. 😕
Marking this test as pending until this gets fixed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did someone file an issue?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a note on the existing tracking issue in coreFX for the Ping APIs.
One of the coreFX folx asked if I could set breakpoints and check what's going on. I may give it a stab, but I'm not really sure what I'm doing there tbh. CoreFX is a very large project, and I'm not familiar with how to work with it in a debugging context, or even build it at all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should I create an additional tracking issue here as well? We already have a tracking issue for the APIs used by this cmdlet in general I think I can add a note to.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm good as long as it's tracked somehow.
PingOptions are not returned from .NET Core api as expected. Test marked as pending for now.
Test-Connection
- Improve Logic and Output
Should we document anything (the check box is set)? |
Yeah, we changed quite a bit in terms of the shape of the output in pretty much all the cases here. Doc issue is MicrosoftDocs/PowerShell-Docs#4987 - I'll link it in the PR description as well. Thanks for the reminder! 💖 |
🎉 Handy links: |
PR Summary
Refactor Test-Connection to provide unit-based output with clearer formatting and more useful traceroute timing information.
-Traceroute
methodology to use 4 pings instead of 3:TtlExpired
is used to target the rest of the pings.TtlExpired
is never reported, so we skip this step completely and just target all pings at the final destination.MtuSize
detection to allow it to work correctly on Unix.ValidateSet
attribute on-MaxHops
to reflect underlying API limitations (0 is not a valid argument for PingOptions' TTL)-Traceroute
where-MaxHops
is a valid input parameter, but is completely ignored. New behaviour is to write an error if the destination cannot be reached within the set value for-MaxHops
, or return$false
if also specifying-Quiet
.-IPv4
and-IPv6
were completely ignored if you supplied a valid address from the other family. Resolution is to check the AddressFamily, and if it doesn't match the provided switch, pull the host entry and find an address matching the requested family to use.-Continues
=>-Repeat
(Alias applied to maintain compatibility)-MtuSizeDetect
=>-MtuSize
(Alias applied here also)PR Context
RFC: PowerShell/PowerShell-RFC#172
Resolves #9235
Resolves #7685
PR Checklist
.h
,.cpp
,.cs
,.ps1
and.psm1
files have the correct copyright headerWIP:
or[ WIP ]
to the beginning of the title (theWIP
bot will keep its status check atPending
while the prefix is present) and remove the prefix when the PR is ready.