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

Add debugging to MTUSize test. #21463

Merged
merged 5 commits into from May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
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
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