Skip to content

Commit 0be73f1

Browse files
authored
Add debugging to the MTU size test (#21463)
1 parent fab4bf2 commit 0be73f1

File tree

3 files changed

+45
-13
lines changed

3 files changed

+45
-13
lines changed

src/Microsoft.PowerShell.Commands.Management/commands/management/TestConnectionCommand.cs

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,8 @@ private void ProcessMTUSize(string targetNameOrAddress)
565565
int LowMTUSize = targetAddress.AddressFamily == AddressFamily.InterNetworkV6 ? 1280 : 68;
566566
int timeout = TimeoutSeconds * 1000;
567567

568+
PingReply? timeoutReply = null;
569+
568570
try
569571
{
570572
PingOptions pingOptions = new(MaxHops, true);
@@ -585,6 +587,7 @@ private void ProcessMTUSize(string targetNameOrAddress)
585587
if (reply.Status == IPStatus.PacketTooBig || reply.Status == IPStatus.TimedOut)
586588
{
587589
HighMTUSize = CurrentMTUSize;
590+
timeoutReply = reply;
588591
retry = 1;
589592
}
590593
else if (reply.Status == IPStatus.Success)
@@ -643,13 +646,32 @@ private void ProcessMTUSize(string targetNameOrAddress)
643646
}
644647
else
645648
{
646-
ArgumentNullException.ThrowIfNull(replyResult);
649+
if (replyResult is null)
650+
{
651+
if (timeoutReply is not null)
652+
{
653+
Exception timeoutException = new TimeoutException(targetAddress.ToString());
654+
ErrorRecord errorRecord = new(
655+
timeoutException,
656+
TestConnectionExceptionId,
657+
ErrorCategory.ResourceUnavailable,
658+
timeoutReply);
659+
WriteError(errorRecord);
660+
}
661+
else
662+
{
663+
ArgumentNullException.ThrowIfNull(replyResult);
664+
}
665+
}
666+
else
667+
{
668+
WriteObject(new PingMtuStatus(
669+
Source,
670+
resolvedTargetName,
671+
replyResult,
672+
CurrentMTUSize));
673+
}
647674

648-
WriteObject(new PingMtuStatus(
649-
Source,
650-
resolvedTargetName,
651-
replyResult,
652-
CurrentMTUSize));
653675
}
654676
}
655677

test/powershell/Modules/Microsoft.PowerShell.Management/Test-Connection.Tests.ps1

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -271,12 +271,18 @@ Describe "Test-Connection" -tags "CI", "RequireSudoOnUnix" {
271271
return
272272
}
273273

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

276-
$result | Should -BeOfType Microsoft.PowerShell.Commands.TestConnectionCommand+PingMtuStatus
277-
$result.Destination | Should -BeExactly $testAddress
278-
$result.Status | Should -BeExactly "Success"
279-
$result.MtuSize | Should -BeGreaterThan 0
277+
if ($eVar.TargetObject.Status -eq "TimedOut") {
278+
Set-ItResult -skipped -because "timed out"
279+
}
280+
else {
281+
$result | Should -BeOfType Microsoft.PowerShell.Commands.TestConnectionCommand+PingMtuStatus
282+
$result.Destination | Should -BeExactly $testAddress
283+
$result.Status | Should -BeExactly "Success"
284+
$result.MtuSize | Should -BeGreaterThan 0
285+
}
280286
}
281287

282288
It "Quiet works" {

test/tools/Modules/HelpersCommon/HelpersCommon.psm1

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ function Get-RandomFileName
6969
$SCRIPT:TesthookType = [system.management.automation.internal.internaltesthooks]
7070
function Test-TesthookIsSet
7171
{
72+
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingEmptyCatchBlock", '')] # , Justification = "an error message is not appropriate for this function")]
7273
param (
7374
[ValidateNotNullOrEmpty()]
7475
[Parameter(Mandatory=$true)]
@@ -196,6 +197,7 @@ public class TestDynamic : DynamicObject
196197
# Upload an artifact in VSTS
197198
# On other systems will just log where the file was placed
198199
function Send-VstsLogFile {
200+
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingWriteHost', '', Justification = "needed for VSO")]
199201
param (
200202
[parameter(Mandatory,ParameterSetName='contents')]
201203
[string[]]
@@ -322,6 +324,8 @@ function New-RandomHexString
322324
$script:CanWriteToPsHome = $null
323325
function Test-CanWriteToPsHome
324326
{
327+
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingEmptyCatchBlock', '', Justification = "an error message is not appropriate for this function")]
328+
param ()
325329
if ($null -ne $script:CanWriteToPsHome) {
326330
return $script:CanWriteToPsHome
327331
}
@@ -366,7 +370,7 @@ function Get-PlatformInfo {
366370
return @{Platform = "windows"; Version = '' }
367371
}
368372
if ( $IsMacOS ) {
369-
return @{Platform = "macos"; Version = '' }
373+
return @{Platform = "macos"; Version = sw_vers -productversion }
370374
}
371375
if ( $IsLinux ) {
372376
$osrelease = Get-Content /etc/os-release | ConvertFrom-StringData
@@ -382,7 +386,7 @@ function Get-PlatformInfo {
382386

383387
return @{Platform = $platform; Version = $versionId }
384388
}
385-
return "unknown"
389+
return @{ Platform = "linux"; version = "unknown" }
386390
}
387391
}
388392

0 commit comments

Comments
 (0)