Invoke-GlobalNavHoldQueueResumeSmoke.ps1
4.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
param(
[string]$ApiBaseUrl = "http://localhost:5000",
[string]$SendNextEndpointPath = "/api/internal/send-next-segment",
[ValidateSet("GET","POST")]
[string]$HttpMethod = "POST",
[string]$RobotManufacturer = "HUAHENG",
[string]$RobotSerialNumber = "1001",
[int]$DurationSeconds = 90,
[int]$RequestIntervalMs = 500,
[int]$TimeoutSeconds = 8,
[string]$LogPath = "",
[string[]]$Patterns = @(
"[GlobalNav] HoldEscalationCandidates",
"[GlobalNav] ResumeMetrics",
"ResumeDispatchTriggered",
"queue turn pending"
),
[string[]]$RequiredPatterns = @(
"[GlobalNav] ResumeMetrics"
)
)
Set-StrictMode -Version Latest
$ErrorActionPreference = "Stop"
if ($DurationSeconds -le 0) { throw "DurationSeconds must be > 0" }
if ($RequestIntervalMs -lt 50) { throw "RequestIntervalMs must be >= 50" }
$query = "robotManufacturer=$([uri]::EscapeDataString($RobotManufacturer))&robotSerialNumber=$([uri]::EscapeDataString($RobotSerialNumber))"
$sendUri = "$ApiBaseUrl${SendNextEndpointPath}?$query"
$patternHit = @{}
foreach ($pattern in $Patterns) {
$patternHit[$pattern] = 0
}
$requestSuccess = 0
$requestFailure = 0
$requestException = 0
$processedLogLines = 0
function Invoke-SendNextRequest {
$params = @{
Uri = $sendUri
Method = $HttpMethod
TimeoutSec = $TimeoutSeconds
}
if ($PSVersionTable.PSVersion.Major -lt 6) {
$params["UseBasicParsing"] = $true
}
return Invoke-WebRequest @params
}
function Update-PatternHit {
param(
[string[]]$Lines
)
foreach ($line in $Lines) {
foreach ($pattern in $Patterns) {
if ($line.Contains($pattern, [StringComparison]::OrdinalIgnoreCase)) {
$patternHit[$pattern] = [int]$patternHit[$pattern] + 1
}
}
}
}
function Read-NewLogLines {
if ([string]::IsNullOrWhiteSpace($LogPath) -or -not (Test-Path $LogPath)) {
return @()
}
$all = Get-Content -Path $LogPath -ErrorAction SilentlyContinue
if ($null -eq $all -or $all.Count -eq 0) {
return @()
}
if ($processedLogLines -ge $all.Count) {
return @()
}
$newLines = $all[$processedLogLines..($all.Count - 1)]
$script:processedLogLines = $all.Count
return $newLines
}
if (-not [string]::IsNullOrWhiteSpace($LogPath) -and (Test-Path $LogPath)) {
$initial = Get-Content -Path $LogPath -ErrorAction SilentlyContinue
if ($initial) {
$processedLogLines = $initial.Count
}
}
$stopwatch = [System.Diagnostics.Stopwatch]::StartNew()
$deadline = (Get-Date).AddSeconds($DurationSeconds)
Write-Host "[GlobalNavSmoke] Start"
Write-Host " Uri: $sendUri"
Write-Host " Method: $HttpMethod"
Write-Host " DurationSeconds: $DurationSeconds"
Write-Host " RequestIntervalMs: $RequestIntervalMs"
if (-not [string]::IsNullOrWhiteSpace($LogPath)) {
Write-Host " LogPath: $LogPath"
}
while ((Get-Date) -lt $deadline) {
try {
$resp = Invoke-SendNextRequest
if ($resp.StatusCode -ge 200 -and $resp.StatusCode -lt 300) {
$requestSuccess++
}
else {
$requestFailure++
}
}
catch {
$requestException++
}
$newLines = @(Read-NewLogLines)
if ($newLines.Count -gt 0) {
Update-PatternHit -Lines $newLines
}
Start-Sleep -Milliseconds $RequestIntervalMs
}
$tailLines = @(Read-NewLogLines)
if ($tailLines.Count -gt 0) {
Update-PatternHit -Lines $tailLines
}
$stopwatch.Stop()
Write-Host ""
Write-Host "GlobalNav Hold/Queue/Resume Smoke Result"
Write-Host " ElapsedMs: $($stopwatch.ElapsedMilliseconds)"
Write-Host " RequestSuccess: $requestSuccess"
Write-Host " RequestFailure: $requestFailure"
Write-Host " RequestException: $requestException"
Write-Host ""
Write-Host "Pattern Hits:"
foreach ($pattern in $Patterns) {
Write-Host (" {0} => {1}" -f $pattern, $patternHit[$pattern])
}
$missingRequired = @()
foreach ($required in $RequiredPatterns) {
if (-not $patternHit.ContainsKey($required) -or $patternHit[$required] -le 0) {
$missingRequired += $required
}
}
Write-Host ""
if ($missingRequired.Count -eq 0) {
Write-Host "[GlobalNavSmoke] PASS (required patterns observed)"
}
else {
Write-Warning ("[GlobalNavSmoke] INCOMPLETE: missing required patterns => {0}" -f ($missingRequired -join ", "))
}
Write-Host "Recommended checks:"
Write-Host " 1) Verify queue order evolves (position x/y shrinks over time)."
Write-Host " 2) Verify resume trigger appears after hold window."
Write-Host " 3) Correlate with [PathCAS] metrics under contention."