Skip to content

Commit

Permalink
Add debugging to the MTU size test (#21463)
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesWTruher committed May 21, 2024
1 parent fab4bf2 commit 0be73f1
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,8 @@ private void ProcessMTUSize(string targetNameOrAddress)
int LowMTUSize = targetAddress.AddressFamily == AddressFamily.InterNetworkV6 ? 1280 : 68;
int timeout = TimeoutSeconds * 1000;

PingReply? timeoutReply = null;

try
{
PingOptions pingOptions = new(MaxHops, true);
Expand All @@ -585,6 +587,7 @@ private void ProcessMTUSize(string targetNameOrAddress)
if (reply.Status == IPStatus.PacketTooBig || reply.Status == IPStatus.TimedOut)
{
HighMTUSize = CurrentMTUSize;
timeoutReply = reply;
retry = 1;
}
else if (reply.Status == IPStatus.Success)
Expand Down Expand Up @@ -643,13 +646,32 @@ private void ProcessMTUSize(string targetNameOrAddress)
}
else
{
ArgumentNullException.ThrowIfNull(replyResult);
if (replyResult is null)
{
if (timeoutReply is not null)
{
Exception timeoutException = new TimeoutException(targetAddress.ToString());
ErrorRecord errorRecord = new(
timeoutException,
TestConnectionExceptionId,
ErrorCategory.ResourceUnavailable,
timeoutReply);
WriteError(errorRecord);
}
else
{
ArgumentNullException.ThrowIfNull(replyResult);
}
}
else
{
WriteObject(new PingMtuStatus(
Source,
resolvedTargetName,
replyResult,
CurrentMTUSize));
}

WriteObject(new PingMtuStatus(
Source,
resolvedTargetName,
replyResult,
CurrentMTUSize));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,12 +271,18 @@ Describe "Test-Connection" -tags "CI", "RequireSudoOnUnix" {
return
}

$result = Test-Connection $testAddress -MtuSize
# if we time out, that's a terminating exception, so set erroraction to continue
$result = Test-Connection $testAddress -MtuSize -ErrorVariable eVar -ErrorAction Continue

$result | Should -BeOfType Microsoft.PowerShell.Commands.TestConnectionCommand+PingMtuStatus
$result.Destination | Should -BeExactly $testAddress
$result.Status | Should -BeExactly "Success"
$result.MtuSize | Should -BeGreaterThan 0
if ($eVar.TargetObject.Status -eq "TimedOut") {
Set-ItResult -skipped -because "timed out"
}
else {
$result | Should -BeOfType Microsoft.PowerShell.Commands.TestConnectionCommand+PingMtuStatus
$result.Destination | Should -BeExactly $testAddress
$result.Status | Should -BeExactly "Success"
$result.MtuSize | Should -BeGreaterThan 0
}
}

It "Quiet works" {
Expand Down
8 changes: 6 additions & 2 deletions test/tools/Modules/HelpersCommon/HelpersCommon.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ function Get-RandomFileName
$SCRIPT:TesthookType = [system.management.automation.internal.internaltesthooks]
function Test-TesthookIsSet
{
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingEmptyCatchBlock", '')] # , Justification = "an error message is not appropriate for this function")]
param (
[ValidateNotNullOrEmpty()]
[Parameter(Mandatory=$true)]
Expand Down Expand Up @@ -196,6 +197,7 @@ public class TestDynamic : DynamicObject
# Upload an artifact in VSTS
# On other systems will just log where the file was placed
function Send-VstsLogFile {
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingWriteHost', '', Justification = "needed for VSO")]
param (
[parameter(Mandatory,ParameterSetName='contents')]
[string[]]
Expand Down Expand Up @@ -322,6 +324,8 @@ function New-RandomHexString
$script:CanWriteToPsHome = $null
function Test-CanWriteToPsHome
{
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingEmptyCatchBlock', '', Justification = "an error message is not appropriate for this function")]
param ()
if ($null -ne $script:CanWriteToPsHome) {
return $script:CanWriteToPsHome
}
Expand Down Expand Up @@ -366,7 +370,7 @@ function Get-PlatformInfo {
return @{Platform = "windows"; Version = '' }
}
if ( $IsMacOS ) {
return @{Platform = "macos"; Version = '' }
return @{Platform = "macos"; Version = sw_vers -productversion }
}
if ( $IsLinux ) {
$osrelease = Get-Content /etc/os-release | ConvertFrom-StringData
Expand All @@ -382,7 +386,7 @@ function Get-PlatformInfo {

return @{Platform = $platform; Version = $versionId }
}
return "unknown"
return @{ Platform = "linux"; version = "unknown" }
}
}

Expand Down

0 comments on commit 0be73f1

Please sign in to comment.