Pre-download socat to avoid test failing due to connectivity issues (#41035)
* Pre-download socat to avoid test failings due to connectivity issues * Cleanup diff * Apply PR feedback * Apply PR feedback * Apply PR feedback
Blue committed
Jul 10, 2026 at 11:30 UTC
40d5f8ff2c80bc0cfef24dac0f5be94ccbd3558d
3 files changed
+87
-6
packages.config
+1
-1
@@ -22,7 +22,7 @@
22
<package id="Microsoft.WSL.DeviceHost" version="1.2.48-0" />
23
<package id="Microsoft.WSL.Kernel" version="6.18.35.2-1" targetFramework="native" />
24
<package id="Microsoft.WSL.LinuxSdk" version="1.20.0" targetFramework="native" />
25
- <package id="Microsoft.WSL.TestData" version="0.4.0" />
25
+ <package id="Microsoft.WSL.TestData" version="0.5.0" />
26
<package id="Microsoft.WSL.TestDistro" version="2.7.1-1" />
27
<package id="Microsoft.WSLg" version="1.0.79" />
28
<package id="Microsoft.Xaml.Behaviors.WinUI.Managed" version="3.0.0" />
test/windows/WSLCTests.cpp
+13
-5
@@ -3532,11 +3532,19 @@ class WSLCTests
3532
auto createNewSession = networkingMode != m_defaultSessionSettings.NetworkingMode;
3533
auto session = createNewSession ? CreateSession(settings) : m_defaultSession;
3534
3535
- // Install socat in the container.
3536
- //
3537
- // TODO: revisit this in the future to avoid pulling packages from the network.
3538
- auto installSocat = WSLCProcessLauncher("/bin/sh", {"/bin/sh", "-c", "tdnf install socat -y"}).Launch(*session);
3539
- ValidateProcessOutput(installSocat, {}, 0, 300 * 1000);
3535
+ // Install socat in the VM.
3536
+ {
3537
+ constexpr auto c_mountPoint = "/testdata";
3538
+ auto mountSource = std::filesystem::absolute(g_testDataPath);
3539
+
3540
+ VERIFY_SUCCEEDED(session->MountWindowsFolder(mountSource.c_str(), c_mountPoint, true));
3541
+ auto unmount =
3542
+ wil::scope_exit_log(WI_DIAGNOSTICS_INFO, [&]() { LOG_IF_FAILED(session->UnmountWindowsFolder(c_mountPoint)); });
3543
+
3544
+ const auto installCommand = std::format("tdnf install -y --disablerepo='*' --nogpgcheck {}/packages/*.rpm", c_mountPoint);
3545
+ auto installSocat = WSLCProcessLauncher("/bin/sh", {"/bin/sh", "-c", installCommand}).Launch(*session);
3546
+ ValidateProcessOutput(installSocat, {}, 0, 120 * 1000);
3547
+ }
3548
3549
auto listen = [&](short port, const char* content, bool ipv6) {
3550
auto cmd = std::format("echo -n '{}' | /usr/bin/socat -dd TCP{}-LISTEN:{},reuseaddr -", content, ipv6 ? "6" : "", port);
tools/test/download-test-data-rpms.ps1
new
+73
@@ -0,0 +1,73 @@
1
+
2
+[CmdletBinding(PositionalBinding = $False)]
3
+param (
4
+ [Parameter(Mandatory = $true)][string]$Target,
5
+ [string]$BaseUrl = "https://packages.microsoft.com/azurelinux/3.0/prod/base"
6
+)
7
+
8
+$ErrorActionPreference = "Stop"
9
+Set-StrictMode -Version Latest
10
+$ProgressPreference = "SilentlyContinue"
11
+
12
+$archMap = @{
13
+ "x64" = "x86_64"
14
+ "arm64" = "aarch64"
15
+}
16
+
17
+$packages = @("socat", "readline", "ncurses-libs")
18
+
19
+function Get-LatestRpmUrl {
20
+ param (
21
+ [string]$RepoUrl,
22
+ [string]$Arch,
23
+ [string]$Package
24
+ )
25
+
26
+ $letter = $Package.Substring(0, 1).ToLowerInvariant()
27
+ $listingUrl = "$RepoUrl/$Arch/Packages/$letter/"
28
+
29
+ $listing = curl.exe --fail -sSL $listingUrl
30
+ if ($LASTEXITCODE -ne 0) {
31
+ throw "Failed to list packages at $listingUrl"
32
+ }
33
+
34
+ $pattern = 'href="(?<file>' + [regex]::Escape($Package) + '-(?<ver>[0-9][0-9.]*)-(?<rel>[0-9]+)\.azl[0-9]+\.' + $Arch + '\.rpm)"'
35
+ $matches = [regex]::Matches($listing, $pattern)
36
+ if ($matches.Count -eq 0) {
37
+ throw "No '$Package' rpm found for '$Arch' at $listingUrl"
38
+ }
39
+
40
+ $latest = $matches |
41
+ Sort-Object -Property `
42
+ @{ Expression = { [version]$_.Groups["ver"].Value } }, `
43
+ @{ Expression = { [int]$_.Groups["rel"].Value } } |
44
+ Select-Object -Last 1
45
+
46
+ return "$listingUrl$($latest.Groups['file'].Value)"
47
+}
48
+
49
+foreach ($archEntry in $archMap.GetEnumerator()) {
50
+ $nugetArch = $archEntry.Key
51
+ $repoArch = $archEntry.Value
52
+
53
+ $archInput = Join-Path $Target $nugetArch
54
+ if (-not (Test-Path -Path $archInput -PathType Container)) {
55
+ Write-Warning "Skipping '$nugetArch': '$archInput' does not exist."
56
+ continue
57
+ }
58
+
59
+ $packagesDir = Join-Path $archInput "packages"
60
+ New-Item -ItemType Directory -Path $packagesDir -Force | Out-Null
61
+
62
+ foreach ($package in $packages) {
63
+ $url = Get-LatestRpmUrl -RepoUrl $BaseUrl -Arch $repoArch -Package $package
64
+ $fileName = Split-Path -Path $url -Leaf
65
+ $destination = Join-Path $packagesDir $fileName
66
+
67
+ Write-Output "[$nugetArch] Downloading $url"
68
+ curl.exe --fail -sSL -o $destination $url
69
+ if ($LASTEXITCODE -ne 0) {
70
+ throw "Failed to download $url"
71
+ }
72
+ }
73
+}
\ No newline at end of file