-
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathtest-load.ps1
More file actions
56 lines (44 loc) · 1.32 KB
/
Copy pathtest-load.ps1
File metadata and controls
56 lines (44 loc) · 1.32 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
Add-Type -AssemblyName System.Net.Http
$url = "http://localhost:8801/g3pix-cms/"
#$url = "http://localhost:8801/manual/"
$totalRequests = 2000 # Simultaneous requests
Write-Host "Starting requests $totalRequests for $url..." -ForegroundColor Cyan
$client = New-Object System.Net.Http.HttpClient
$stopwatch = [System.Diagnostics.Stopwatch]::StartNew()
$tasks = foreach ($i in 1..$totalRequests) {
$client.GetAsync($url)
}
try {
[System.Threading.Tasks.Task]::WaitAll($tasks)
}
catch {
Write-Host "Some requests failed." -ForegroundColor Yellow
}
$stopwatch.Stop()
$successCount = 0
$errorCount = 0
# Check HTTP status for tasks
foreach ($task in $tasks) {
if ($task.Status -eq 'RanToCompletion') {
if ($task.Result.IsSuccessStatusCode) {
$successCount++
}
else {
$errorCount++
}
$task.Result.Dispose()
}
else {
$errorCount++
}
}
$client.Dispose()
Write-Host "`n--- Tests results ---" -ForegroundColor White
Write-Host "Total time: $($stopwatch.ElapsedMilliseconds) ms" -ForegroundColor White
Write-Host "Success requests (HTTP 200): $successCount" -ForegroundColor Green
if ($errorCount -gt 0) {
Write-Host "Failed requests: $errorCount" -ForegroundColor Red
}
else {
Write-Host "Failed requests: $errorCount" -ForegroundColor Green
}