Skip to content

Commit 7e9237f

Browse files
committed
add debugging logs for hanging issue
1 parent aee464d commit 7e9237f

File tree

1 file changed

+241
-5
lines changed

1 file changed

+241
-5
lines changed

.github/workflows/test-scripts.yml

Lines changed: 241 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,8 @@ jobs:
177177
runs-on: windows-latest
178178
timeout-minutes: 25
179179
environment: BrowserStack
180+
env:
181+
ACTIONS_STEP_DEBUG: true
180182
defaults:
181183
run:
182184
shell: powershell
@@ -200,6 +202,16 @@ jobs:
200202
$PSVersionTable.PSVersion
201203
Write-Host "✅ PowerShell version check complete"
202204
205+
- name: Enable PowerShell debug logging
206+
run: |
207+
Write-Host "Enabling PowerShell debug and verbose logging..."
208+
$DebugPreference = "Continue"
209+
$VerbosePreference = "Continue"
210+
$ErrorActionPreference = "Continue"
211+
Write-Host "✅ Debug logging enabled"
212+
Write-Debug "Debug logging is now active"
213+
Write-Verbose "Verbose logging is now active"
214+
203215
- name: Validate PowerShell script syntax
204216
run: |
205217
Write-Host "Validating win/run.ps1 syntax..."
@@ -225,13 +237,15 @@ jobs:
225237
226238
- name: Run PSScriptAnalyzer
227239
run: |
240+
$DebugPreference = "Continue"
241+
$VerbosePreference = "Continue"
228242
Write-Host "Installing PSScriptAnalyzer if needed..."
229243
if (-not (Get-Module -ListAvailable -Name PSScriptAnalyzer)) {
230-
Install-Module -Name PSScriptAnalyzer -Force -SkipPublisherCheck -Scope CurrentUser
244+
Install-Module -Name PSScriptAnalyzer -Force -SkipPublisherCheck -Scope CurrentUser -Verbose
231245
}
232246
233247
Write-Host "Running PSScriptAnalyzer..."
234-
Invoke-ScriptAnalyzer -Path "win" -Recurse -ReportSummary -ErrorAction Continue
248+
Invoke-ScriptAnalyzer -Path "win" -Recurse -ReportSummary -ErrorAction Continue -Verbose
235249
Write-Host "✅ PSScriptAnalyzer analysis complete (continuing even if issues are found)"
236250
237251
- name: Check script file encoding
@@ -259,26 +273,76 @@ jobs:
259273
if (Get-Command git.exe -ErrorAction SilentlyContinue) { Write-Host "✅ git found" } else { Write-Host "⚠️ git not found" }
260274
Write-Host "✅ PowerShell dependencies verified"
261275
276+
- name: Check initial system resources
277+
run: |
278+
Write-Host "=== Initial System Resources ==="
279+
280+
# Get system memory info
281+
$os = Get-CimInstance Win32_OperatingSystem
282+
$totalMemoryGB = [math]::Round($os.TotalVisibleMemorySize / 1MB, 2)
283+
$freeMemoryGB = [math]::Round($os.FreePhysicalMemory / 1MB, 2)
284+
$usedMemoryGB = [math]::Round(($os.TotalVisibleMemorySize - $os.FreePhysicalMemory) / 1MB, 2)
285+
$memoryPercent = [math]::Round(($usedMemoryGB / $totalMemoryGB) * 100, 2)
286+
287+
Write-Host "Total Physical Memory: $totalMemoryGB GB"
288+
Write-Host "Free Physical Memory: $freeMemoryGB GB"
289+
Write-Host "Used Physical Memory: $usedMemoryGB GB ($memoryPercent%)"
290+
291+
# Get CPU info
292+
$cpu = Get-CimInstance Win32_Processor
293+
Write-Host "CPU Name: $($cpu.Name)"
294+
Write-Host "CPU Cores: $($cpu.NumberOfCores)"
295+
Write-Host "CPU Logical Processors: $($cpu.NumberOfLogicalProcessors)"
296+
297+
# Get current CPU usage (average over 3 samples)
298+
Write-Host "Measuring CPU usage..."
299+
$cpuSamples = @()
300+
for ($i = 0; $i -lt 3; $i++) {
301+
$cpuSample = (Get-Counter '\Processor(_Total)\% Processor Time').CounterSamples[0].CookedValue
302+
$cpuSamples += $cpuSample
303+
Start-Sleep -Seconds 1
304+
}
305+
$avgCpu = [math]::Round(($cpuSamples | Measure-Object -Average).Average, 2)
306+
Write-Host "Current CPU Usage: $avgCpu%"
307+
308+
# Get disk space
309+
$disk = Get-CimInstance Win32_LogicalDisk -Filter "DeviceID='C:'"
310+
$freeDiskGB = [math]::Round($disk.FreeSpace / 1GB, 2)
311+
$totalDiskGB = [math]::Round($disk.Size / 1GB, 2)
312+
$usedDiskGB = [math]::Round(($disk.Size - $disk.FreeSpace) / 1GB, 2)
313+
Write-Host "C: Drive Free Space: $freeDiskGB GB / $totalDiskGB GB"
314+
315+
Write-Host "✅ Initial resource check complete"
316+
262317
- name: Integration Test - Silent Mode Execution
263318
if: success()
264319
env:
265320
BROWSERSTACK_USERNAME: ${{ secrets.BROWSERSTACK_USERNAME }}
266321
BROWSERSTACK_ACCESS_KEY: ${{ secrets.BROWSERSTACK_ACCESS_KEY }}
267322
TURL: https://bstackdemo.com
268323
run: |
324+
$DebugPreference = "Continue"
325+
$VerbosePreference = "Continue"
326+
$ErrorActionPreference = "Continue"
269327
Write-Host "Running integration tests in silent mode..."
328+
Write-Debug "Debug logging enabled for integration tests"
329+
Write-Verbose "Verbose logging enabled for integration tests"
270330
271331
# Use defaults if secrets are missing (for local / dry runs)
272332
$BrowserStackUsername = if ($env:BROWSERSTACK_USERNAME) { $env:BROWSERSTACK_USERNAME } else { "test_user" }
273333
$BrowserStackAccessKey = if ($env:BROWSERSTACK_ACCESS_KEY) { $env:BROWSERSTACK_ACCESS_KEY } else { "test_key" }
274334
$TestUrl = $env:TURL
275335
336+
Write-Debug "BrowserStack Username: $BrowserStackUsername"
337+
Write-Verbose "Test URL: $TestUrl"
338+
276339
$env:BROWSERSTACK_USERNAME = $BrowserStackUsername
277340
$env:BROWSERSTACK_ACCESS_KEY = $BrowserStackAccessKey
278341
$env:TURL = $TestUrl
279342
280343
# Absolute path is safer in CI
281344
$scriptPath = Join-Path $env:GITHUB_WORKSPACE "win\run.ps1"
345+
Write-Debug "Script path: $scriptPath"
282346
283347
$testConfigs = @(
284348
@("web", "java"),
@@ -289,9 +353,43 @@ jobs:
289353
@("app", "nodejs")
290354
)
291355
356+
# Function to get system resources
357+
function Get-SystemResources {
358+
$os = Get-CimInstance Win32_OperatingSystem
359+
$totalMemoryGB = [math]::Round($os.TotalVisibleMemorySize / 1MB, 2)
360+
$freeMemoryGB = [math]::Round($os.FreePhysicalMemory / 1MB, 2)
361+
$usedMemoryGB = [math]::Round(($os.TotalVisibleMemorySize - $os.FreePhysicalMemory) / 1MB, 2)
362+
$memoryPercent = [math]::Round(($usedMemoryGB / $totalMemoryGB) * 100, 2)
363+
364+
$cpuSample = (Get-Counter '\Processor(_Total)\% Processor Time' -ErrorAction SilentlyContinue).CounterSamples[0].CookedValue
365+
$cpuUsage = [math]::Round($cpuSample, 2)
366+
367+
# Get PowerShell process memory
368+
$pwshProcess = Get-Process -Id $PID -ErrorAction SilentlyContinue
369+
$pwshMemoryMB = if ($pwshProcess) { [math]::Round($pwshProcess.WorkingSet64 / 1MB, 2) } else { 0 }
370+
371+
return @{
372+
TotalMemoryGB = $totalMemoryGB
373+
FreeMemoryGB = $freeMemoryGB
374+
UsedMemoryGB = $usedMemoryGB
375+
MemoryPercent = $memoryPercent
376+
CpuUsage = $cpuUsage
377+
PwshMemoryMB = $pwshMemoryMB
378+
}
379+
}
380+
292381
$overallFailed = $false
293382
$logRoot = Join-Path $env:TEMP "now-tests"
383+
$resourceLogPath = Join-Path $logRoot "resource_usage.log"
294384
New-Item -ItemType Directory -Force -Path $logRoot | Out-Null
385+
386+
# Log initial resources
387+
$initialResources = Get-SystemResources
388+
Write-Host "=== Initial Resources Before Tests ==="
389+
Write-Host "Memory: $($initialResources.UsedMemoryGB) GB / $($initialResources.TotalMemoryGB) GB ($($initialResources.MemoryPercent)%)"
390+
Write-Host "CPU: $($initialResources.CpuUsage)%"
391+
Write-Host "PowerShell Memory: $($initialResources.PwshMemoryMB) MB"
392+
"$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') - INITIAL - Memory: $($initialResources.UsedMemoryGB)GB/$($initialResources.TotalMemoryGB)GB ($($initialResources.MemoryPercent)%), CPU: $($initialResources.CpuUsage)%, Pwsh: $($initialResources.PwshMemoryMB)MB" | Out-File -FilePath $resourceLogPath -Append
295393
296394
foreach ($config in $testConfigs) {
297395
$testType = $config[0]
@@ -300,11 +398,66 @@ jobs:
300398
Write-Host "================================"
301399
Write-Host "Testing: $scriptPath --silent $testType $techStack"
302400
Write-Host "================================"
401+
Write-Debug "Test type: $testType, Tech stack: $techStack"
402+
403+
# Get resources before test
404+
$resourcesBefore = Get-SystemResources
405+
Write-Host "--- Resources Before Test ---"
406+
Write-Host "Memory: $($resourcesBefore.UsedMemoryGB) GB / $($resourcesBefore.TotalMemoryGB) GB ($($resourcesBefore.MemoryPercent)%)"
407+
Write-Host "CPU: $($resourcesBefore.CpuUsage)%"
408+
Write-Host "PowerShell Memory: $($resourcesBefore.PwshMemoryMB) MB"
409+
"$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') - BEFORE [$testType/$techStack] - Memory: $($resourcesBefore.UsedMemoryGB)GB/$($resourcesBefore.TotalMemoryGB)GB ($($resourcesBefore.MemoryPercent)%), CPU: $($resourcesBefore.CpuUsage)%, Pwsh: $($resourcesBefore.PwshMemoryMB)MB" | Out-File -FilePath $resourceLogPath -Append
303410
304411
$logPath = Join-Path $logRoot "run_test_${testType}_${techStack}.log"
412+
Write-Verbose "Log path: $logPath"
413+
414+
# Start background resource monitoring
415+
$monitorJob = Start-Job -ScriptBlock {
416+
param($logFile, $testName)
417+
$endTime = (Get-Date).AddMinutes(10) # Monitor for max 10 minutes
418+
while ((Get-Date) -lt $endTime) {
419+
try {
420+
$os = Get-CimInstance Win32_OperatingSystem
421+
$usedMemoryGB = [math]::Round(($os.TotalVisibleMemorySize - $os.FreePhysicalMemory) / 1MB, 2)
422+
$totalMemoryGB = [math]::Round($os.TotalVisibleMemorySize / 1MB, 2)
423+
$memoryPercent = [math]::Round(($usedMemoryGB / $totalMemoryGB) * 100, 2)
424+
$cpuSample = (Get-Counter '\Processor(_Total)\% Processor Time' -ErrorAction SilentlyContinue).CounterSamples[0].CookedValue
425+
$cpuUsage = [math]::Round($cpuSample, 2)
426+
"$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') - MONITOR [$testName] - Memory: $usedMemoryGB GB/$totalMemoryGB GB ($memoryPercent%), CPU: $cpuUsage%" | Out-File -FilePath $logFile -Append
427+
} catch {
428+
# Ignore errors in monitoring
429+
}
430+
Start-Sleep -Seconds 30 # Sample every 30 seconds
431+
}
432+
} -ArgumentList $resourceLogPath, "${testType}_${techStack}"
305433
434+
Write-Debug "Executing script: $scriptPath --silent $testType $techStack"
435+
$startTime = Get-Date
306436
& $scriptPath --silent $testType $techStack 2>&1 | Tee-Object -FilePath $logPath -Append
307437
$exitCode = $LASTEXITCODE
438+
$endTime = Get-Date
439+
$duration = $endTime - $startTime
440+
Write-Debug "Script exit code: $exitCode"
441+
442+
# Stop monitoring job
443+
Stop-Job -Job $monitorJob -ErrorAction SilentlyContinue
444+
Remove-Job -Job $monitorJob -ErrorAction SilentlyContinue
445+
446+
# Get resources after test
447+
Start-Sleep -Seconds 2 # Brief pause to let system settle
448+
$resourcesAfter = Get-SystemResources
449+
Write-Host "--- Resources After Test ---"
450+
Write-Host "Memory: $($resourcesAfter.UsedMemoryGB) GB / $($resourcesAfter.TotalMemoryGB) GB ($($resourcesAfter.MemoryPercent)%)"
451+
Write-Host "CPU: $($resourcesAfter.CpuUsage)%"
452+
Write-Host "PowerShell Memory: $($resourcesAfter.PwshMemoryMB) MB"
453+
Write-Host "Test Duration: $($duration.TotalSeconds) seconds"
454+
455+
$memoryDelta = [math]::Round($resourcesAfter.UsedMemoryGB - $resourcesBefore.UsedMemoryGB, 2)
456+
$cpuDelta = [math]::Round($resourcesAfter.CpuUsage - $resourcesBefore.CpuUsage, 2)
457+
Write-Host "Memory Change: $memoryDelta GB"
458+
Write-Host "CPU Change: $cpuDelta%"
459+
460+
"$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') - AFTER [$testType/$techStack] - Memory: $($resourcesAfter.UsedMemoryGB)GB/$($resourcesAfter.TotalMemoryGB)GB ($($resourcesAfter.MemoryPercent)%), CPU: $($resourcesAfter.CpuUsage)%, Pwsh: $($resourcesAfter.PwshMemoryMB)MB, Duration: $([math]::Round($duration.TotalSeconds, 2))s, MemoryDelta: ${memoryDelta}GB, CpuDelta: ${cpuDelta}%" | Out-File -FilePath $resourceLogPath -Append
308461
309462
if ($exitCode -eq 0) {
310463
Write-Host "✅ $testType / $techStack completed (exit code: $exitCode)"
@@ -325,26 +478,109 @@ jobs:
325478
}
326479
327480
Write-Host "✅ All integration tests completed successfully"
481+
482+
# Log final resources
483+
$finalResources = Get-SystemResources
484+
Write-Host "=== Final Resources After All Tests ==="
485+
Write-Host "Memory: $($finalResources.UsedMemoryGB) GB / $($finalResources.TotalMemoryGB) GB ($($finalResources.MemoryPercent)%)"
486+
Write-Host "CPU: $($finalResources.CpuUsage)%"
487+
Write-Host "PowerShell Memory: $($finalResources.PwshMemoryMB) MB"
488+
489+
$totalMemoryDelta = [math]::Round($finalResources.UsedMemoryGB - $initialResources.UsedMemoryGB, 2)
490+
$totalCpuDelta = [math]::Round($finalResources.CpuUsage - $initialResources.CpuUsage, 2)
491+
Write-Host "Total Memory Change: $totalMemoryDelta GB"
492+
Write-Host "Total CPU Change: $totalCpuDelta%"
493+
494+
"$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') - FINAL - Memory: $($finalResources.UsedMemoryGB)GB/$($finalResources.TotalMemoryGB)GB ($($finalResources.MemoryPercent)%), CPU: $($finalResources.CpuUsage)%, Pwsh: $($finalResources.PwshMemoryMB)MB, TotalMemoryDelta: ${totalMemoryDelta}GB, TotalCpuDelta: ${totalCpuDelta}%" | Out-File -FilePath $resourceLogPath -Append
495+
496+
Write-Host "Resource usage log saved to: $resourceLogPath"
497+
498+
- name: Check final system resources
499+
if: always()
500+
run: |
501+
Write-Host "=== Final System Resources ==="
502+
503+
# Get system memory info
504+
$os = Get-CimInstance Win32_OperatingSystem
505+
$totalMemoryGB = [math]::Round($os.TotalVisibleMemorySize / 1MB, 2)
506+
$freeMemoryGB = [math]::Round($os.FreePhysicalMemory / 1MB, 2)
507+
$usedMemoryGB = [math]::Round(($os.TotalVisibleMemorySize - $os.FreePhysicalMemory) / 1MB, 2)
508+
$memoryPercent = [math]::Round(($usedMemoryGB / $totalMemoryGB) * 100, 2)
509+
510+
Write-Host "Total Physical Memory: $totalMemoryGB GB"
511+
Write-Host "Free Physical Memory: $freeMemoryGB GB"
512+
Write-Host "Used Physical Memory: $usedMemoryGB GB ($memoryPercent%)"
513+
514+
# Get current CPU usage
515+
Write-Host "Measuring CPU usage..."
516+
$cpuSamples = @()
517+
for ($i = 0; $i -lt 3; $i++) {
518+
$cpuSample = (Get-Counter '\Processor(_Total)\% Processor Time').CounterSamples[0].CookedValue
519+
$cpuSamples += $cpuSample
520+
Start-Sleep -Seconds 1
521+
}
522+
$avgCpu = [math]::Round(($cpuSamples | Measure-Object -Average).Average, 2)
523+
Write-Host "Current CPU Usage: $avgCpu%"
524+
525+
# Get top processes by memory
526+
Write-Host "`n=== Top 10 Processes by Memory Usage ==="
527+
Get-Process | Sort-Object WorkingSet64 -Descending | Select-Object -First 10 | Format-Table -Property Name, @{Name="Memory(MB)";Expression={[math]::Round($_.WorkingSet64 / 1MB, 2)}}, CPU, Id -AutoSize
528+
529+
# Get top processes by CPU
530+
Write-Host "=== Top 10 Processes by CPU Usage ==="
531+
Get-Process | Sort-Object CPU -Descending | Select-Object -First 10 | Format-Table -Property Name, CPU, @{Name="Memory(MB)";Expression={[math]::Round($_.WorkingSet64 / 1MB, 2)}}, Id -AutoSize
532+
533+
Write-Host "✅ Final resource check complete"
328534
329535
- name: Sync BrowserStack logs to workspace (Windows)
330536
if: always()
331537
run: |
538+
$DebugPreference = "Continue"
539+
$VerbosePreference = "Continue"
332540
$dest = Join-Path $env:GITHUB_WORKSPACE "bs-logs"
333-
New-Item -ItemType Directory -Force -Path $dest | Out-Null
541+
Write-Debug "Destination directory: $dest"
542+
New-Item -ItemType Directory -Force -Path $dest -Verbose | Out-Null
334543
335544
$bsLogPath = Join-Path $env:USERPROFILE ".browserstack\NOW\logs"
336545
$tempLogDir = Join-Path $env:TEMP "now-tests"
546+
Write-Debug "BrowserStack log path: $bsLogPath"
547+
Write-Debug "Temp log directory: $tempLogDir"
337548
338549
if (Test-Path $bsLogPath) {
339550
Write-Host "Copying logs from $bsLogPath"
340-
Copy-Item -Path (Join-Path $bsLogPath "*") -Destination $dest -Recurse -Force -ErrorAction SilentlyContinue
551+
Write-Verbose "Copying logs from $bsLogPath to $dest"
552+
Copy-Item -Path (Join-Path $bsLogPath "*") -Destination $dest -Recurse -Force -ErrorAction SilentlyContinue -Verbose
341553
} else {
342554
Write-Host "No logs found at $bsLogPath"
555+
Write-Debug "BrowserStack logs directory does not exist"
343556
}
344557
345558
if (Test-Path $tempLogDir) {
346559
Write-Host "Copying integration logs from $tempLogDir"
347-
Copy-Item -Path (Join-Path $tempLogDir "*") -Destination $dest -Recurse -Force -ErrorAction SilentlyContinue
560+
Write-Verbose "Copying integration logs from $tempLogDir to $dest"
561+
Copy-Item -Path (Join-Path $tempLogDir "*") -Destination $dest -Recurse -Force -ErrorAction SilentlyContinue -Verbose
562+
} else {
563+
Write-Debug "Temp log directory does not exist"
564+
}
565+
566+
# Copy resource usage log if it exists
567+
$resourceLogPath = Join-Path $tempLogDir "resource_usage.log"
568+
if (Test-Path $resourceLogPath) {
569+
Write-Host "Copying resource usage log"
570+
Copy-Item -Path $resourceLogPath -Destination $dest -Force -ErrorAction SilentlyContinue -Verbose
571+
}
572+
573+
- name: Display resource usage summary
574+
if: always()
575+
run: |
576+
$resourceLogPath = Join-Path $env:TEMP "now-tests\resource_usage.log"
577+
if (Test-Path $resourceLogPath) {
578+
Write-Host "=== Resource Usage Summary ==="
579+
Write-Host "`nFull resource usage log:"
580+
Get-Content -Path $resourceLogPath
581+
Write-Host "`n✅ Resource usage summary displayed"
582+
} else {
583+
Write-Host "Resource usage log not found at $resourceLogPath"
348584
}
349585
350586
- name: Upload BrowserStack Logs as Artifacts

0 commit comments

Comments
 (0)