chore: establish local platform baseline
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
param(
|
||||
[int]$Connections=500,
|
||||
[int]$OpenRate=40,
|
||||
[int]$Reconnects=50,
|
||||
[int]$HoldSeconds=5
|
||||
)
|
||||
$ErrorActionPreference='Stop'
|
||||
$PSNativeCommandUseErrorActionPreference=$true
|
||||
if($Connections-lt1-or$Connections-gt5000-or$OpenRate-lt1-or$OpenRate-gt50-or$Reconnects-lt0-or$Reconnects-gt$Connections-or$HoldSeconds-lt1-or$HoldSeconds-gt20){throw 'SSE load parameters exceed the safe local boundary'}
|
||||
$root=Split-Path -Parent $PSScriptRoot
|
||||
Set-Location -LiteralPath $root
|
||||
$tokenUrl='http://localhost:58180/realms/voice-local/protocol/openid-connect/token'
|
||||
$eventId=$null
|
||||
|
||||
function Sql([string]$statement){
|
||||
$result=$statement|docker compose exec -T postgres psql -U voice -d voice_platform -v ON_ERROR_STOP=1 -q -t -A
|
||||
if($LASTEXITCODE-ne0){throw 'SSE load fixture SQL failed'}
|
||||
return ($result|Out-String).Trim()
|
||||
}
|
||||
|
||||
try{
|
||||
$eventId=Sql "INSERT INTO web_event(tenant_id,household_id,subject_id,event_type,resource_type,resource_public_id,status,expires_at) SELECT t.id,h.id,sp.id,'story.created','load_fixture',gen_random_uuid(),'ready',now()+interval '15 minutes' FROM tenant t JOIN household h ON h.tenant_id=t.id JOIN subject_profile sp ON sp.tenant_id=t.id AND sp.household_id=h.id WHERE t.public_id='10000000-0000-0000-0000-000000000010'::uuid ORDER BY h.created_at,sp.created_at LIMIT 1 RETURNING id;"
|
||||
if($eventId-notmatch'^\d+$'){throw "Invalid SSE fixture event id: $eventId"}
|
||||
$token=(Invoke-RestMethod -Method Post -Uri $tokenUrl -ContentType 'application/x-www-form-urlencoded' -Body @{grant_type='password';client_id='voice-platform-web';username='owner';password='LocalOnly123!';scope='openid'}).access_token
|
||||
$previous=$env:ACCESS_TOKEN
|
||||
try{
|
||||
$env:ACCESS_TOKEN=$token
|
||||
go run ./cmd/load-sse -url http://localhost:58080/api/v1/events -connections $Connections -open-rate $OpenRate -reconnects $Reconnects -hold "${HoldSeconds}s"
|
||||
if($LASTEXITCODE-ne0){throw 'SSE connection load failed'}
|
||||
}finally{
|
||||
$env:ACCESS_TOKEN=$previous
|
||||
}
|
||||
}finally{
|
||||
if($eventId-match'^\d+$'){try{Sql "DELETE FROM web_event WHERE id=$eventId;"|Out-Null}catch{Write-Warning $_}}
|
||||
}
|
||||
Reference in New Issue
Block a user