test optimizations

This commit is contained in:
Flowseal
2026-08-24 01:08:09 +03:00
parent f6525045b7
commit 64c2550f78
+30 -22
View File
@@ -10,20 +10,20 @@ if (-not (Test-Path $resultsDir)) { New-Item -ItemType Directory -Path $resultsD
function Get-IpsetStatus { function Get-IpsetStatus {
$listFile = Join-Path $listsDir "ipset-all.txt" $listFile = Join-Path $listsDir "ipset-all.txt"
if (-not (Test-Path $listFile)) { return "none" } if (-not (Test-Path $listFile)) { return "none" }
$lineCount = (Get-Content $listFile | Measure-Object -Line).Lines $raw = [IO.File]::ReadAllText($listFile)
if ($lineCount -eq 0) { return "any" } if ([string]::IsNullOrWhiteSpace($raw)) { return "any" }
$hasDummy = Get-Content $listFile | Select-String -Pattern "203\.0\.113\.113/32" -Quiet if ($raw -match '203\.0\.113\.113/32') { return "none" }
if ($hasDummy) { return "none" } else { return "loaded" } return "loaded"
} }
function Wait-WinwsReady { function Wait-WinwsReady {
$timer = [Diagnostics.Stopwatch]::StartNew() $timer = [Diagnostics.Stopwatch]::StartNew()
while ($timer.ElapsedMilliseconds -lt 5000) { while ($timer.ElapsedMilliseconds -lt 5000) {
if (Get-Process -Name "winws" -ErrorAction SilentlyContinue) { if (Get-Process -Name "winws" -ErrorAction SilentlyContinue) {
Start-Sleep -Milliseconds 400 Start-Sleep -Milliseconds 300
return return
} }
Start-Sleep -Milliseconds 80 Start-Sleep -Milliseconds 200
} }
} }
@@ -89,13 +89,14 @@ function Convert-Target {
# DPI checker defaults (override via MONITOR_* env vars like in monitor.ps1) # DPI checker defaults (override via MONITOR_* env vars like in monitor.ps1)
$dpiTimeoutSeconds = 5 $dpiTimeoutSeconds = 5
$dpiRangeBytes = 65536 $dpiRangeBytes = 65536
$dpiMaxParallel = 8 $defaultMaxParallel = [Math]::Min(16, [Math]::Max(8, [Environment]::ProcessorCount * 2))
$dpiMaxParallel = $defaultMaxParallel
$dpiCustomHost = $env:MONITOR_HOST $dpiCustomHost = $env:MONITOR_HOST
if ($env:MONITOR_TIMEOUT) { [int]$dpiTimeoutSeconds = $env:MONITOR_TIMEOUT } if ($env:MONITOR_TIMEOUT) { [int]$dpiTimeoutSeconds = $env:MONITOR_TIMEOUT }
if ($env:MONITOR_RANGE) { [int]$dpiRangeBytes = $env:MONITOR_RANGE } if ($env:MONITOR_RANGE) { [int]$dpiRangeBytes = $env:MONITOR_RANGE }
if ($env:MONITOR_MAX_PARALLEL) { [int]$dpiMaxParallel = $env:MONITOR_MAX_PARALLEL } if ($env:MONITOR_MAX_PARALLEL) { [int]$dpiMaxParallel = $env:MONITOR_MAX_PARALLEL }
$standardCurlTimeout = 4 $standardCurlTimeout = 4
$standardMaxParallel = 8 $standardMaxParallel = $defaultMaxParallel
if ($env:TEST_CURL_TIMEOUT) { [int]$standardCurlTimeout = $env:TEST_CURL_TIMEOUT } if ($env:TEST_CURL_TIMEOUT) { [int]$standardCurlTimeout = $env:TEST_CURL_TIMEOUT }
if ($env:TEST_MAX_PARALLEL) { [int]$standardMaxParallel = $env:TEST_MAX_PARALLEL } if ($env:TEST_MAX_PARALLEL) { [int]$standardMaxParallel = $env:TEST_MAX_PARALLEL }
@@ -712,12 +713,19 @@ try {
$pingResult = "n/a" $pingResult = "n/a"
if ($t.PingTarget) { if ($t.PingTarget) {
$ping = $null
try { try {
$pings = Test-Connection -ComputerName $t.PingTarget -Count 1 -ErrorAction Stop $ping = New-Object System.Net.NetworkInformation.Ping
$avg = ($pings | Measure-Object -Property ResponseTime -Average).Average $reply = $ping.Send($t.PingTarget, 1000)
$pingResult = "{0:N0} ms" -f $avg if ($reply.Status -eq [System.Net.NetworkInformation.IPStatus]::Success) {
$pingResult = "{0:N0} ms" -f $reply.RoundtripTime
} else {
$pingResult = "Timeout"
}
} catch { } catch {
$pingResult = "Timeout" $pingResult = "Timeout"
} finally {
if ($ping) { $ping.Dispose() }
} }
} }
@@ -902,19 +910,18 @@ try {
# Save to file # Save to file
$dateStr = Get-Date -Format "yyyy-MM-dd_HH-mm-ss" $dateStr = Get-Date -Format "yyyy-MM-dd_HH-mm-ss"
$resultFile = Join-Path $resultsDir "test_results_$dateStr.txt" $resultFile = Join-Path $resultsDir "test_results_$dateStr.txt"
# Clear file $resultLines = New-Object System.Collections.Generic.List[string]
"" | Out-File $resultFile -Encoding UTF8
foreach ($res in $globalResults) { foreach ($res in $globalResults) {
$config = $res.Config $config = $res.Config
$type = $res.Type $type = $res.Type
$results = $res.Results $results = $res.Results
Add-Content $resultFile "Config: $config (Type: $type)" [void]$resultLines.Add("Config: $config (Type: $type)")
if ($type -eq 'standard') { if ($type -eq 'standard') {
foreach ($targetRes in $results) { foreach ($targetRes in $results) {
$name = $targetRes.Name $name = $targetRes.Name
$http = $targetRes.HttpTokens -join ' ' $http = $targetRes.HttpTokens -join ' '
$ping = $targetRes.PingResult $ping = $targetRes.PingResult
Add-Content $resultFile " $name : $http | Ping: $ping" [void]$resultLines.Add(" $name : $http | Ping: $ping")
} }
} elseif ($type -eq 'dpi') { } elseif ($type -eq 'dpi') {
foreach ($targetRes in $results) { foreach ($targetRes in $results) {
@@ -922,9 +929,9 @@ try {
$provider = $targetRes.Provider $provider = $targetRes.Provider
$country = $targetRes.Country $country = $targetRes.Country
if ($country) { if ($country) {
Add-Content $resultFile " Target: [$country] $id ($provider)" [void]$resultLines.Add(" Target: [$country] $id ($provider)")
} else { } else {
Add-Content $resultFile " Target: $id ($provider)" [void]$resultLines.Add(" Target: $id ($provider)")
} }
foreach ($line in $targetRes.Lines) { foreach ($line in $targetRes.Lines) {
$test = $line.TestLabel $test = $line.TestLabel
@@ -933,15 +940,15 @@ try {
$down = $line.DownKB $down = $line.DownKB
$time = $line.Time $time = $line.Time
$status = $line.Status $status = $line.Status
Add-Content $resultFile " ${test}: code=${code} up=${up} KB down=${down} KB time=${time}s status=${status}" [void]$resultLines.Add(" ${test}: code=${code} up=${up} KB down=${down} KB time=${time}s status=${status}")
} }
} }
} }
Add-Content $resultFile "" [void]$resultLines.Add("")
} }
# Add analytics # Add analytics
Add-Content $resultFile "=== ANALYTICS ===" [void]$resultLines.Add("=== ANALYTICS ===")
$maxConfigLen = ($analytics.Keys | ForEach-Object { $_.Length } | Measure-Object -Maximum).Maximum $maxConfigLen = ($analytics.Keys | ForEach-Object { $_.Length } | Measure-Object -Maximum).Maximum
foreach ($config in $analytics.Keys) { foreach ($config in $analytics.Keys) {
$a = $analytics[$config] $a = $analytics[$config]
@@ -953,10 +960,11 @@ try {
$line = "{0} : OK: {1,3}, FAIL: {2,3}, UNSUP: {3,3}, BLOCKED: {4,3}" -f ` $line = "{0} : OK: {1,3}, FAIL: {2,3}, UNSUP: {3,3}, BLOCKED: {4,3}" -f `
$configPadded, $a.OK, $a.FAIL, $a.UNSUPPORTED, $a.LIKELY_BLOCKED $configPadded, $a.OK, $a.FAIL, $a.UNSUPPORTED, $a.LIKELY_BLOCKED
} }
Add-Content $resultFile $line [void]$resultLines.Add($line)
} }
Add-Content $resultFile "Best strategy: $bestConfig" [void]$resultLines.Add("Best strategy: $bestConfig")
$resultLines | Set-Content $resultFile -Encoding UTF8
Write-Host "Results saved to $resultFile" -ForegroundColor Green Write-Host "Results saved to $resultFile" -ForegroundColor Green