forked from Nether404/RepoRadar
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathrun-performance-tests.ps1
More file actions
149 lines (123 loc) · 4.47 KB
/
run-performance-tests.ps1
File metadata and controls
149 lines (123 loc) · 4.47 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
#!/usr/bin/env pwsh
<#
.SYNOPSIS
Run performance and load tests for RepoRadar
.DESCRIPTION
This script starts the application server and runs comprehensive
performance and load tests including:
- 100 concurrent users
- 100 concurrent jobs
- 1000 analytics events per minute
- Multi-instance load distribution
.PARAMETER BaseUrl
Base URL of the application to test (default: http://localhost:5000)
.PARAMETER SkipBuild
Skip building the application before testing
.PARAMETER TestPattern
Run specific test pattern (e.g., "Concurrent User")
.EXAMPLE
.\scripts\run-performance-tests.ps1
Run all performance tests with default settings
.EXAMPLE
.\scripts\run-performance-tests.ps1 -BaseUrl http://localhost:8080
Run tests against a different URL
.EXAMPLE
.\scripts\run-performance-tests.ps1 -TestPattern "Concurrent User"
Run only concurrent user tests
#>
param(
[string]$BaseUrl = "http://localhost:5000",
[switch]$SkipBuild = $false,
[string]$TestPattern = ""
)
$ErrorActionPreference = "Stop"
Write-Host "🚀 RepoRadar Performance Testing Suite" -ForegroundColor Cyan
Write-Host "=" * 60
# Check if server is already running
Write-Host "`n📡 Checking if server is running at $BaseUrl..." -ForegroundColor Yellow
try {
$response = Invoke-WebRequest -Uri "$BaseUrl/health" -TimeoutSec 5 -UseBasicParsing
if ($response.StatusCode -eq 200) {
Write-Host "✅ Server is already running" -ForegroundColor Green
$serverStarted = $false
}
} catch {
Write-Host "⚠️ Server is not running, will start it..." -ForegroundColor Yellow
$serverStarted = $true
}
# Build application if needed
if (-not $SkipBuild -and $serverStarted) {
Write-Host "`n🔨 Building application..." -ForegroundColor Yellow
npm run build
if ($LASTEXITCODE -ne 0) {
Write-Host "❌ Build failed" -ForegroundColor Red
exit 1
}
Write-Host "✅ Build completed" -ForegroundColor Green
}
# Start server if needed
$serverProcess = $null
if ($serverStarted) {
Write-Host "`n🌐 Starting server..." -ForegroundColor Yellow
# Start server in background
$serverProcess = Start-Process -FilePath "npm" -ArgumentList "start" -PassThru -NoNewWindow
# Wait for server to be ready
$maxAttempts = 30
$attempt = 0
$serverReady = $false
while ($attempt -lt $maxAttempts -and -not $serverReady) {
Start-Sleep -Seconds 2
$attempt++
try {
$response = Invoke-WebRequest -Uri "$BaseUrl/health" -TimeoutSec 2 -UseBasicParsing
if ($response.StatusCode -eq 200) {
$serverReady = $true
Write-Host "✅ Server is ready" -ForegroundColor Green
}
} catch {
Write-Host " Waiting for server... ($attempt/$maxAttempts)" -ForegroundColor Gray
}
}
if (-not $serverReady) {
Write-Host "❌ Server failed to start within timeout" -ForegroundColor Red
if ($serverProcess) {
Stop-Process -Id $serverProcess.Id -Force
}
exit 1
}
}
# Run performance tests
Write-Host "`n🧪 Running performance tests..." -ForegroundColor Yellow
Write-Host " Base URL: $BaseUrl" -ForegroundColor Gray
$env:TEST_BASE_URL = $BaseUrl
try {
if ($TestPattern) {
Write-Host " Test Pattern: $TestPattern" -ForegroundColor Gray
npm test tests/PerformanceLoad.test.ts -- --run --reporter=verbose -t "$TestPattern"
} else {
npm test tests/PerformanceLoad.test.ts -- --run --reporter=verbose
}
$testExitCode = $LASTEXITCODE
if ($testExitCode -eq 0) {
Write-Host "`n✅ All performance tests passed!" -ForegroundColor Green
} else {
Write-Host "`n⚠️ Some performance tests failed" -ForegroundColor Yellow
}
} catch {
Write-Host "`n❌ Error running tests: $_" -ForegroundColor Red
$testExitCode = 1
} finally {
# Stop server if we started it
if ($serverStarted -and $serverProcess) {
Write-Host "`n🛑 Stopping server..." -ForegroundColor Yellow
Stop-Process -Id $serverProcess.Id -Force -ErrorAction SilentlyContinue
Write-Host "✅ Server stopped" -ForegroundColor Green
}
}
Write-Host "`n" + "=" * 60
if ($testExitCode -eq 0) {
Write-Host "🎉 Performance testing completed successfully!" -ForegroundColor Green
} else {
Write-Host "⚠️ Performance testing completed with issues" -ForegroundColor Yellow
}
exit $testExitCode