Refactor load testing scripts to support Bash and PowerShell
- Updated README.md to reflect changes in load testing commands and added usage examples for Bash scripts. - Converted PowerShell load testing scripts to Bash equivalents for better cross-platform compatibility. - Added new Bash scripts: run-loadtests.sh, summarize-artillery.sh, and summarize-k6.sh to mirror existing PowerShell functionality. - Updated admin-api.js and ws-chat.yml for consistency and improved performance metrics reporting. - Enhanced error handling and output formatting in summary scripts for better readability.
This commit is contained in:
1 parent
9f60087a4c
commit
33b6296c5e
82 files changed
+19682
-21133
No files matched your search
@@ -1,99 +1,99 @@
|
||||
#!/usr/bin/env pwsh
|
||||
param(
|
||||
[ValidateSet('ws', 'admin', 'all')]
|
||||
[string]$Scenario = 'all',
|
||||
[string]$ArtifactRoot = 'artifacts',
|
||||
[string]$WsUrl = $env:WS_URL,
|
||||
[string]$AdminBaseUrl = $env:ADMIN_BASE_URL,
|
||||
[string]$AdminSessionCookie = $env:ADMIN_SESSION_COOKIE
|
||||
)
|
||||
|
||||
$ErrorActionPreference = 'Stop'
|
||||
|
||||
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
|
||||
$repoRoot = Resolve-Path (Join-Path $scriptDir '..\..')
|
||||
$wsScenarioPath = Join-Path $scriptDir 'ws-chat.yml'
|
||||
$wsSummaryScriptPath = Join-Path $scriptDir 'summarize-artillery.ps1'
|
||||
$adminScriptPath = Join-Path $scriptDir 'admin-api.js'
|
||||
$adminSummaryScriptPath = Join-Path $scriptDir 'summarize-k6.ps1'
|
||||
|
||||
if ([System.IO.Path]::IsPathRooted($ArtifactRoot)) {
|
||||
$artifactBase = $ArtifactRoot
|
||||
} else {
|
||||
$artifactBase = Join-Path $repoRoot $ArtifactRoot
|
||||
}
|
||||
|
||||
if ($Scenario -in @('ws', 'all')) {
|
||||
if (-not (Get-Command npx -ErrorAction SilentlyContinue)) {
|
||||
throw 'npx is required for ws scenario but was not found in PATH.'
|
||||
}
|
||||
}
|
||||
|
||||
if ($Scenario -in @('admin', 'all')) {
|
||||
if (-not (Get-Command k6 -ErrorAction SilentlyContinue)) {
|
||||
throw 'k6 is required for admin scenario but was not found in PATH.'
|
||||
}
|
||||
}
|
||||
|
||||
$timestamp = Get-Date -Format 'yyyy-MM-dd_HHmmss'
|
||||
$artifactDir = Join-Path $artifactBase $timestamp
|
||||
New-Item -ItemType Directory -Force -Path $artifactDir | Out-Null
|
||||
|
||||
function Invoke-WebSocketLoadTest {
|
||||
param(
|
||||
[string]$TargetWsUrl,
|
||||
[string]$OutputPath
|
||||
)
|
||||
|
||||
if ([string]::IsNullOrWhiteSpace($TargetWsUrl)) {
|
||||
throw 'WS_URL is required for ws scenario. Pass -WsUrl or set $env:WS_URL.'
|
||||
}
|
||||
|
||||
$env:WS_URL = $TargetWsUrl
|
||||
& npx artillery run $wsScenarioPath --output $OutputPath
|
||||
}
|
||||
|
||||
function Invoke-AdminApiLoadTest {
|
||||
param(
|
||||
[string]$BaseUrl,
|
||||
[string]$SessionCookie,
|
||||
[string]$SummaryPath,
|
||||
[string]$OutputPath
|
||||
)
|
||||
|
||||
if ([string]::IsNullOrWhiteSpace($BaseUrl)) {
|
||||
throw 'ADMIN_BASE_URL is required for admin scenario. Pass -AdminBaseUrl or set $env:ADMIN_BASE_URL.'
|
||||
}
|
||||
if ([string]::IsNullOrWhiteSpace($SessionCookie)) {
|
||||
throw 'ADMIN_SESSION_COOKIE is required for admin scenario. Pass -AdminSessionCookie or set $env:ADMIN_SESSION_COOKIE.'
|
||||
}
|
||||
|
||||
$env:ADMIN_BASE_URL = $BaseUrl
|
||||
$env:ADMIN_SESSION_COOKIE = $SessionCookie
|
||||
& k6 run --summary-export $SummaryPath $adminScriptPath | Tee-Object -FilePath $OutputPath
|
||||
}
|
||||
|
||||
if ($Scenario -in @('ws', 'all')) {
|
||||
if (-not (Test-Path $wsSummaryScriptPath)) {
|
||||
throw "Missing summary helper: $wsSummaryScriptPath"
|
||||
}
|
||||
|
||||
$wsOutput = Join-Path $artifactDir 'ws-chat-report.json'
|
||||
$wsSummary = Join-Path $artifactDir 'ws-chat-summary.txt'
|
||||
Invoke-WebSocketLoadTest -TargetWsUrl $WsUrl -OutputPath $wsOutput
|
||||
& pwsh -File $wsSummaryScriptPath -ReportFile $wsOutput | Tee-Object -FilePath $wsSummary
|
||||
}
|
||||
|
||||
if ($Scenario -in @('admin', 'all')) {
|
||||
if (-not (Test-Path $adminSummaryScriptPath)) {
|
||||
throw "Missing summary helper: $adminSummaryScriptPath"
|
||||
}
|
||||
|
||||
$adminSummary = Join-Path $artifactDir 'admin-api-summary.json'
|
||||
$adminOutput = Join-Path $artifactDir 'admin-api-output.txt'
|
||||
$adminEndpointSummary = Join-Path $artifactDir 'admin-api-endpoint-summary.txt'
|
||||
Invoke-AdminApiLoadTest -BaseUrl $AdminBaseUrl -SessionCookie $AdminSessionCookie -SummaryPath $adminSummary -OutputPath $adminOutput
|
||||
& pwsh -File $adminSummaryScriptPath -SummaryFile $adminSummary | Tee-Object -FilePath $adminEndpointSummary
|
||||
}
|
||||
|
||||
#!/usr/bin/env pwsh
|
||||
param(
|
||||
[ValidateSet('ws', 'admin', 'all')]
|
||||
[string]$Scenario = 'all',
|
||||
[string]$ArtifactRoot = 'artifacts',
|
||||
[string]$WsUrl = $env:WS_URL,
|
||||
[string]$AdminBaseUrl = $env:ADMIN_BASE_URL,
|
||||
[string]$AdminSessionCookie = $env:ADMIN_SESSION_COOKIE
|
||||
)
|
||||
|
||||
$ErrorActionPreference = 'Stop'
|
||||
|
||||
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
|
||||
$repoRoot = Resolve-Path (Join-Path $scriptDir '..\..')
|
||||
$wsScenarioPath = Join-Path $scriptDir 'ws-chat.yml'
|
||||
$wsSummaryScriptPath = Join-Path $scriptDir 'summarize-artillery.ps1'
|
||||
$adminScriptPath = Join-Path $scriptDir 'admin-api.js'
|
||||
$adminSummaryScriptPath = Join-Path $scriptDir 'summarize-k6.ps1'
|
||||
|
||||
if ([System.IO.Path]::IsPathRooted($ArtifactRoot)) {
|
||||
$artifactBase = $ArtifactRoot
|
||||
} else {
|
||||
$artifactBase = Join-Path $repoRoot $ArtifactRoot
|
||||
}
|
||||
|
||||
if ($Scenario -in @('ws', 'all')) {
|
||||
if (-not (Get-Command npx -ErrorAction SilentlyContinue)) {
|
||||
throw 'npx is required for ws scenario but was not found in PATH.'
|
||||
}
|
||||
}
|
||||
|
||||
if ($Scenario -in @('admin', 'all')) {
|
||||
if (-not (Get-Command k6 -ErrorAction SilentlyContinue)) {
|
||||
throw 'k6 is required for admin scenario but was not found in PATH.'
|
||||
}
|
||||
}
|
||||
|
||||
$timestamp = Get-Date -Format 'yyyy-MM-dd_HHmmss'
|
||||
$artifactDir = Join-Path $artifactBase $timestamp
|
||||
New-Item -ItemType Directory -Force -Path $artifactDir | Out-Null
|
||||
|
||||
function Invoke-WebSocketLoadTest {
|
||||
param(
|
||||
[string]$TargetWsUrl,
|
||||
[string]$OutputPath
|
||||
)
|
||||
|
||||
if ([string]::IsNullOrWhiteSpace($TargetWsUrl)) {
|
||||
throw 'WS_URL is required for ws scenario. Pass -WsUrl or set $env:WS_URL.'
|
||||
}
|
||||
|
||||
$env:WS_URL = $TargetWsUrl
|
||||
& npx artillery run $wsScenarioPath --output $OutputPath
|
||||
}
|
||||
|
||||
function Invoke-AdminApiLoadTest {
|
||||
param(
|
||||
[string]$BaseUrl,
|
||||
[string]$SessionCookie,
|
||||
[string]$SummaryPath,
|
||||
[string]$OutputPath
|
||||
)
|
||||
|
||||
if ([string]::IsNullOrWhiteSpace($BaseUrl)) {
|
||||
throw 'ADMIN_BASE_URL is required for admin scenario. Pass -AdminBaseUrl or set $env:ADMIN_BASE_URL.'
|
||||
}
|
||||
if ([string]::IsNullOrWhiteSpace($SessionCookie)) {
|
||||
throw 'ADMIN_SESSION_COOKIE is required for admin scenario. Pass -AdminSessionCookie or set $env:ADMIN_SESSION_COOKIE.'
|
||||
}
|
||||
|
||||
$env:ADMIN_BASE_URL = $BaseUrl
|
||||
$env:ADMIN_SESSION_COOKIE = $SessionCookie
|
||||
& k6 run --summary-export $SummaryPath $adminScriptPath | Tee-Object -FilePath $OutputPath
|
||||
}
|
||||
|
||||
if ($Scenario -in @('ws', 'all')) {
|
||||
if (-not (Test-Path $wsSummaryScriptPath)) {
|
||||
throw "Missing summary helper: $wsSummaryScriptPath"
|
||||
}
|
||||
|
||||
$wsOutput = Join-Path $artifactDir 'ws-chat-report.json'
|
||||
$wsSummary = Join-Path $artifactDir 'ws-chat-summary.txt'
|
||||
Invoke-WebSocketLoadTest -TargetWsUrl $WsUrl -OutputPath $wsOutput
|
||||
& pwsh -File $wsSummaryScriptPath -ReportFile $wsOutput | Tee-Object -FilePath $wsSummary
|
||||
}
|
||||
|
||||
if ($Scenario -in @('admin', 'all')) {
|
||||
if (-not (Test-Path $adminSummaryScriptPath)) {
|
||||
throw "Missing summary helper: $adminSummaryScriptPath"
|
||||
}
|
||||
|
||||
$adminSummary = Join-Path $artifactDir 'admin-api-summary.json'
|
||||
$adminOutput = Join-Path $artifactDir 'admin-api-output.txt'
|
||||
$adminEndpointSummary = Join-Path $artifactDir 'admin-api-endpoint-summary.txt'
|
||||
Invoke-AdminApiLoadTest -BaseUrl $AdminBaseUrl -SessionCookie $AdminSessionCookie -SummaryPath $adminSummary -OutputPath $adminOutput
|
||||
& pwsh -File $adminSummaryScriptPath -SummaryFile $adminSummary | Tee-Object -FilePath $adminEndpointSummary
|
||||
}
|
||||
|
||||
Write-Host "Artifacts written to $artifactDir"
|
||||
Reference in new issue
Block a user