fix(templates): replace Test-NetConnection with TcpClient in Prepare scripts

Test-NetConnection is Windows-only. Replace with cross-platform TcpClient
async-connect helper (same pattern as Measure-CIBenchmark.ps1) so the
Prepare scripts run on the Linux host under PowerShell.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-24 00:46:19 +02:00
parent 41a0a113df
commit de33e9f723
2 changed files with 28 additions and 6 deletions
+14 -3
View File
@@ -163,7 +163,19 @@ param(
Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'
$ProgressPreference = 'SilentlyContinue' # suppress Write-Progress (Test-NetConnection, IWR, etc.)
$ProgressPreference = 'SilentlyContinue' # suppress Write-Progress (IWR, etc.)
function Test-TcpPort {
param([string]$ComputerName, [int]$Port, [int]$TimeoutMs = 3000)
try {
$tcp = [System.Net.Sockets.TcpClient]::new()
$ar = $tcp.BeginConnect($ComputerName, $Port, $null, $null)
$ok = $ar.AsyncWaitHandle.WaitOne($TimeoutMs, $false)
$connected = $ok -and $tcp.Connected
$tcp.Close()
return $connected
} catch { return $false }
}
# ── Locate vmrun.exe ──────────────────────────────────────────────────────────
$vmrunCandidates = @(
@@ -247,8 +259,7 @@ Write-Host "[Prepare] Waiting for WinRM on $VMIPAddress`:5986 (timeout ${winrmTi
$winrmDeadline = [datetime]::UtcNow.AddSeconds($winrmTimeoutSec)
$winrmReady = $false
while ([datetime]::UtcNow -lt $winrmDeadline) {
if (Test-NetConnection -ComputerName $VMIPAddress -Port 5986 `
-InformationLevel Quiet -WarningAction SilentlyContinue -ErrorAction SilentlyContinue) {
if (Test-TcpPort -ComputerName $VMIPAddress -Port 5986 -TimeoutMs 5000) {
$winrmReady = $true; break
}
Start-Sleep -Seconds 5