FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

`Test-Connection` - Improve Logic and Output by vexx32 · Pull Request #10697 · PowerShell/PowerShell · GitHub

Test-Connection - Improve Logic and Output - #10697

Merged
Travis Plunk (TravisEz13) merged 65 commits into
PowerShell:masterfrom
vexx32:TestConnection/BetterOutput
Nov 18, 2019
Merged

Test-Connection - Improve Logic and Output#10697
Travis Plunk (TravisEz13) merged 65 commits into
PowerShell:masterfrom
vexx32:TestConnection/BetterOutput

Conversation

Rain Sallow (/u/ta11ow) (vexx32) commented Oct 3, 2019
edited
Loading

Copy link
Copy Markdown
Collaborator

PR Summary

Refactor Test-Connection to provide unit-based output with clearer formatting and more useful traceroute timing information.

  • Uses SendAsync() to send pings and adds event handler to permit Ctrl+C to cancel the cmdlet operation mid-ping (great for giving up on a long timeout).
  • Refactor output; both regular -Ping and -TraceRoute actions output one object per received ping, formatted to accommodate as much information as possible.
  • Refactor -Traceroute methodology to use 4 pings instead of 3:
    • 1-3 initial "discovery" pings with low TTL to the final destination to find the router at that hop point (not displayed in output). First ping to come back with TtlExpired is used to target the rest of the pings.
      • On Unix, TtlExpired is never reported, so we skip this step completely and just target all pings at the final destination.
    • 3 followup pings to that router directly so we get proper latency and status information from the router (all rendered in output).
    • This fixes an outstanding issue where traceroutes could not provide latency information on intermediate hops.
  • Slight refactor for MtuSize detection to allow it to work correctly on Unix.
  • Use new class types for all output in order to better provide easy access to displayed information.
  • Update ValidateSet attribute on -MaxHops to reflect underlying API limitations (0 is not a valid argument for PingOptions' TTL)
  • Fix long-standing issue with -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.
  • Fixed an issue where -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.
    • Added some additional IPv6 tests. After running all the IPv6 tests in CI (including those originally marked -Pending) I think it best we leave them disabled. I've verified the features work in Windows 10 and Ubuntu under WSL, but Azures CI apparently doesn't have great IPv6 support, so it's a very mixed bag on what comes back for those tests. We can reenable them in future if there are improvements or alterations to CI config that might improve their reliability there.
  • Renamed switches:
    • -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

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
Errors out when trying to SendPingAsync() too quickly in succession

Rain Sallow (/u/ta11ow) (vexx32) commented Oct 4, 2019
edited
Loading

Copy link
Copy Markdown
Collaborator Author

Steve Lee (@SteveL-MSFT) Samples of output:

Default -Ping Output

-Traceroute Output

-Traceroute -ResolveDestination Output

-MtuSize Output

-IPv6 (with IPv4 address)

-IPv4 (with IPv6 address)

Copy link
Copy Markdown
Collaborator Author

Steve Lee (@SteveL-MSFT) Ilya (@iSazonov) Travis Plunk (@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. 😁

Copy link
Copy Markdown
Member

Rain Sallow (/u/ta11ow) (@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.

Rain Sallow (/u/ta11ow) (vexx32) commented Nov 11, 2019
edited
Loading

Copy link
Copy Markdown
Collaborator Author

Went back through ping / test-connection issues and found this one:

#7576

I think this PR addresses that as well 🤔

Copy link
Copy Markdown
Collaborator Author

Steve Lee (@SteveL-MSFT) looks like we've been tracking this in #4240; I think we can continue to track this there. 🙂

Comment on lines +1649 to +1650
.AddHeader(Alignment.Right, label: "Latency(ms)", width: 7)
.AddHeader(Alignment.Right, label: "BufferSize(B)", width: 10)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Since this is formatting, we can make changes in the future based on user feedback

ghost added Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept and removed Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept labels Nov 11, 2019

Copy link
Copy Markdown
Collaborator Author

PoshChan-Bot (@PoshChan) please retry windows

Copy link
Copy Markdown
Collaborator

Rain Sallow (/u/ta11ow) (@vexx32), successfully started retry of PowerShell-CI-Windows

/// <summary>
/// Gets the target address of the ping.
/// </summary>
public IPAddress? Address { get => Reply.Status == IPStatus.Success ? Reply.Address : null; }

Rain Sallow (/u/ta11ow) (vexx32) Nov 15, 2019
edited
Loading

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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.)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

FIgured it out. Pushing a fix.

@@ -1,8 +1,12 @@
// Copyright (c) Microsoft Corporation. All rights reserved.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Rain Sallow (/u/ta11ow) (@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

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Steve Lee (@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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Did someone file an issue?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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.
Travis Plunk (TravisEz13) changed the title Test-Connection - Improve Logic and Output Test-Connection - Improve Logic and Output Nov 18, 2019
Travis Plunk (TravisEz13) merged commit 4408379 into PowerShell:master Nov 18, 2019
Rain Sallow (/u/ta11ow) (vexx32) deleted the TestConnection/BetterOutput branch November 18, 2019 19:39

Copy link
Copy Markdown
Collaborator

Should we document anything (the check box is set)?

Copy link
Copy Markdown
Collaborator Author

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! 💖

Copy link
Copy Markdown

🎉v7.0.0-preview.6 has been released which incorporates this pull request.:tada:

Handy links:

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Breaking-Change breaking change that may affect users CL-BreakingChange Indicates that a PR should be marked as a breaking change in the Change Log CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Should Test-Connection parameter -Continues be -Continuous ? Test-Connection on PowerShell 6.1 RC-1, Does not give correct output?

6 participants


Back | FazBrowse Home | New Git URL