lab4 - оценка 4

This commit is contained in:
2026-10-26 16:10:22 +03:00
parent ec540a1a72
commit e4704a76d0
49 changed files with 5390 additions and 27 deletions
+14
View File
@@ -0,0 +1,14 @@
@echo off
setlocal
cd /d "%~dp0.."
powershell -NoProfile -ExecutionPolicy Bypass -Command "$ErrorActionPreference='Stop'; $Base='http://localhost:8080'; $Pass='Example-only-not-a-real-secret-123'; $Fixture='tests\fixtures\sample.png'; $u='load'+[guid]::NewGuid().ToString('N').Substring(0,8); $userBody=@{username=$u;display_name='Load';password=$Pass}|ConvertTo-Json -Compress; Invoke-RestMethod -Method Post -Uri ($Base+'/api/v1/users') -ContentType 'application/json' -Body $userBody|Out-Null; $basic=[Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes($u+':'+$Pass)); $sess=Invoke-RestMethod -Method Post -Uri ($Base+'/api/v1/auth/sessions') -Headers @{Authorization='Basic '+$basic}; $tok=$sess.token; $hdr=@{Authorization='Bearer '+$tok}; $chatBody=@{title='Concurrent';member_ids=@($sess.user.id)}|ConvertTo-Json -Compress; $chat=Invoke-RestMethod -Method Post -Uri ($Base+'/api/v1/chats') -Headers $hdr -ContentType 'application/json' -Body $chatBody; $jobs=1..10 | ForEach-Object { $i=$_; Start-Job -ScriptBlock { param($B,$C,$T,$F,$I) $h=@{Authorization='Bearer '+$T}; try { $r=Invoke-WebRequest -Method Post -Uri ($B+'/api/v1/chats/'+$C+'/attachments?filename=c'+$I+'.png') -Headers $h -ContentType 'image/png' -Body ([IO.File]::ReadAllBytes($F)) -UseBasicParsing; return [pscustomobject]@{I=$I;Status=[int]$r.StatusCode;Ok=($r.StatusCode -eq 201)} } catch { return [pscustomobject]@{I=$I;Status=$_.Exception.Response.StatusCode.value__;Ok=$false} } } -ArgumentList $Base,$chat.id,$tok,$Fixture,$i }; $jobs | Wait-Job | Out-Null; $res=$jobs | Receive-Job; $jobs | Remove-Job; $res | Format-Table -AutoSize; $ok=($res | Where-Object Ok).Count; if ($ok -ne 10) { throw ('Only '+$ok+' uploads succeeded') }; Write-Host 'PASS: 10 concurrent uploads succeeded' -ForegroundColor Green"
set RC=%ERRORLEVEL%
if not "%RC%"=="0" exit /b %RC%
echo.
echo Memory stats after concurrent uploads:
docker stats --no-stream --format "table {{.Name}}\t{{.CPUPerc}}\t{{.MemUsage}}\t{{.MemPerc}}"
exit /b 0
+162
View File
@@ -0,0 +1,162 @@
@echo off
setlocal EnableDelayedExpansion
cd /d "%~dp0.."
set BASE=http://localhost:8080
set PASS=Example-only-not-a-real-secret-123
set FIXTURE=tests\fixtures\sample.png
set TMP=%TEMP%\lab4-failover-attachment
if not exist "%TMP%" mkdir "%TMP%"
call :guid
set RND=%GUIDVAL%
set FUSER=fo%RND%
echo === Register failover user ===
call :register "%FUSER%" "Failover" fo
if errorlevel 1 exit /b 1
set FUSER_ID=!fo_ID!
call :login "%FUSER%" fo
if errorlevel 1 exit /b 1
set TOKEN=!fo_TOKEN!
echo === Create chat ===
curl.exe -s -X POST "%BASE%/api/v1/chats" ^
-H "Authorization: Bearer %TOKEN%" ^
-H "Content-Type: application/json" ^
-d "{\"title\":\"Failover attachment\",\"member_ids\":[\"%FUSER_ID%\"]}" ^
-o "%TMP%\chat.json" ^
-w "%%{http_code}" > "%TMP%\chat.code"
call :check_code chat.code 201 "create chat"
if errorlevel 1 exit /b 1
for /f "delims=" %%a in ('powershell -NoProfile -Command "(Get-Content '%TMP%\chat.json' -Raw | ConvertFrom-Json).id"') do set CHAT_ID=%%a
echo === Upload attachment ===
for /f "delims=" %%a in ('powershell -NoProfile -Command "(Get-FileHash -Algorithm SHA256 -Path '%FIXTURE%').Hash.ToLower()"') do set ORIG_SHA=%%a
curl.exe -s -X POST "%BASE%/api/v1/chats/%CHAT_ID%/attachments?filename=failover.png" ^
-H "Authorization: Bearer %TOKEN%" ^
-H "Content-Type: image/png" ^
--data-binary "@%FIXTURE%" ^
-D "%TMP%\upload.headers" ^
-o "%TMP%\att.json" ^
-w "%%{http_code}" > "%TMP%\att.code"
call :check_code att.code 201 "upload attachment"
if errorlevel 1 exit /b 1
for /f "delims=" %%a in ('powershell -NoProfile -Command "(Get-Content '%TMP%\att.json' -Raw | ConvertFrom-Json).id"') do set ATT_ID=%%a
for /f "tokens=1,* delims=:" %%a in ('findstr /i "X-Instance-Id" "%TMP%\upload.headers"') do set UPLOAD_INSTANCE=%%b
echo Uploaded by:%UPLOAD_INSTANCE%
echo attachment=%ATT_ID%
echo === Stop one API replica ===
set STOP_ID=
for /f "delims=" %%i in ('docker compose ps -q api') do if not defined STOP_ID set STOP_ID=%%i
if "%STOP_ID%"=="" (
echo FAIL: no api containers found
exit /b 1
)
echo Stopping container %STOP_ID%
docker stop --time 10 %STOP_ID% >nul
timeout /t 5 /nobreak >nul
echo === Download attachment after replica stop ===
set TRY=0
:download_retry
set /a TRY+=1
if %TRY% GTR 10 (
echo FAIL: download did not recover
docker compose --compatibility up -d api >nul
exit /b 1
)
curl.exe -s -X GET "%BASE%/api/v1/attachments/%ATT_ID%/content" ^
-H "Authorization: Bearer %TOKEN%" ^
-D "%TMP%\download.headers" ^
-o "%TMP%\download.png" ^
-w "%%{http_code}" > "%TMP%\download.code"
set /p RC=<"%TMP%\download.code"
if "%RC%"=="200" goto download_ok
echo Download attempt %TRY% got HTTP %RC%, retrying...
timeout /t 1 /nobreak >nul
goto download_retry
:download_ok
for /f "tokens=1,* delims=:" %%a in ('findstr /i "X-Instance-Id" "%TMP%\download.headers"') do set DOWNLOAD_INSTANCE=%%b
echo Downloaded by:%DOWNLOAD_INSTANCE%
for /f "delims=" %%a in ('powershell -NoProfile -Command "(Get-FileHash -Algorithm SHA256 -Path '%TMP%\download.png').Hash.ToLower()"') do set DL_SHA=%%a
if not "%DL_SHA%"=="%ORIG_SHA%" (
echo FAIL: downloaded sha256 mismatch after failover
docker compose --compatibility up -d api >nul
exit /b 1
)
echo PASS: attachment bytes available after stopping one replica
echo === Restore API replicas ===
docker compose --compatibility up -d api
timeout /t 15 /nobreak >nul
docker compose ps
exit /b 0
:guid
for /f "delims=" %%a in ('powershell -NoProfile -Command "[guid]::NewGuid().ToString('N').Substring(0,8)"') do set GUIDVAL=%%a
exit /b 0
:register
rem %1 username, %2 display_name, %3 prefix
curl.exe -s -X POST "%BASE%/api/v1/users" ^
-H "Content-Type: application/json" ^
-d "{\"username\":\"%~1\",\"display_name\":\"%~2\",\"password\":\"%PASS%\"}" ^
-o "%TMP%\%~3.json" ^
-w "%%{http_code}" > "%TMP%\%~3.code"
set /p RC=<"%TMP%\%~3.code"
if not "%RC%"=="201" (
echo FAIL: register %~1, HTTP %RC%
type "%TMP%\%~3.json"
exit /b 1
)
for /f "delims=" %%a in ('powershell -NoProfile -Command "(Get-Content '%TMP%\%~3.json' -Raw | ConvertFrom-Json).id"') do set "%~3_ID=%%a"
exit /b 0
:login
rem %1 username, %2 prefix
curl.exe -s -X POST "%BASE%/api/v1/auth/sessions" ^
-u "%~1:%PASS%" ^
-o "%TMP%\%~2.json" ^
-w "%%{http_code}" > "%TMP%\%~2.code"
set /p RC=<"%TMP%\%~2.code"
if not "%RC%"=="201" (
echo FAIL: login %~1, HTTP %RC%
type "%TMP%\%~2.json"
exit /b 1
)
for /f "delims=" %%a in ('powershell -NoProfile -Command "(Get-Content '%TMP%\%~2.json' -Raw | ConvertFrom-Json).token"') do set "%~2_TOKEN=%%a"
for /f "delims=" %%a in ('powershell -NoProfile -Command "(Get-Content '%TMP%\%~2.json' -Raw | ConvertFrom-Json).user.id"') do set "%~2_UID=%%a"
exit /b 0
:check_code
rem %1 code file, %2 expected status, %3 label
set /p RC=<"%TMP%\%~1"
if not "%RC%"=="%~2" (
echo FAIL: %~3 expected %~2, got %RC%
exit /b 1
)
exit /b 0
+184
View File
@@ -0,0 +1,184 @@
@echo off
setlocal EnableDelayedExpansion
cd /d "%~dp0.."
set BASE=http://localhost:8080
set PASS=Example-only-not-a-real-secret-123
set FIXTURE=tests\fixtures\sample.png
set TMP=%TEMP%\lab4-manual
if not exist "%TMP%" mkdir "%TMP%"
call :guid
set RND=%GUIDVAL%
set ALICE=alice%RND%
set BOB=bob%RND%
set EVE=eve%RND%
echo === Register users ===
call :register "%ALICE%" "Alice" alice
if errorlevel 1 exit /b 1
set ALICE_ID=!alice_ID!
call :register "%BOB%" "Bob" bob
if errorlevel 1 exit /b 1
set BOB_ID=!bob_ID!
call :register "%EVE%" "Eve" eve
if errorlevel 1 exit /b 1
echo === Login users ===
call :login "%ALICE%" alice
if errorlevel 1 exit /b 1
set ALICE_TOKEN=!alice_TOKEN!
call :login "%BOB%" bob
if errorlevel 1 exit /b 1
set BOB_TOKEN=!bob_TOKEN!
call :login "%EVE%" eve
if errorlevel 1 exit /b 1
set EVE_TOKEN=!eve_TOKEN!
echo === Create chat alice+bob ===
curl.exe -s -X POST "%BASE%/api/v1/chats" ^
-H "Authorization: Bearer %ALICE_TOKEN%" ^
-H "Content-Type: application/json" ^
-d "{\"title\":\"Lab4 manual bat\",\"member_ids\":[\"%ALICE_ID%\",\"%BOB_ID%\"]}" ^
-o "%TMP%\chat.json" ^
-w "%%{http_code}" > "%TMP%\chat.code"
call :check_code chat.code 201 "create chat"
if errorlevel 1 exit /b 1
for /f "delims=" %%a in ('powershell -NoProfile -Command "(Get-Content '%TMP%\chat.json' -Raw | ConvertFrom-Json).id"') do set CHAT_ID=%%a
echo chat=%CHAT_ID%
echo === Upload attachment as alice ===
for /f "delims=" %%a in ('powershell -NoProfile -Command "(Get-FileHash -Algorithm SHA256 -Path '%FIXTURE%').Hash.ToLower()"') do set ORIG_SHA=%%a
echo original sha256=%ORIG_SHA%
curl.exe -s -X POST "%BASE%/api/v1/chats/%CHAT_ID%/attachments?filename=sample.png" ^
-H "Authorization: Bearer %ALICE_TOKEN%" ^
-H "Content-Type: image/png" ^
--data-binary "@%FIXTURE%" ^
-o "%TMP%\att.json" ^
-w "%%{http_code}" > "%TMP%\att.code"
call :check_code att.code 201 "upload attachment"
if errorlevel 1 exit /b 1
for /f "delims=" %%a in ('powershell -NoProfile -Command "(Get-Content '%TMP%\att.json' -Raw | ConvertFrom-Json).id"') do set ATT_ID=%%a
for /f "delims=" %%a in ('powershell -NoProfile -Command "(Get-Content '%TMP%\att.json' -Raw | ConvertFrom-Json).sha256"') do set ATT_SHA=%%a
echo attachment=%ATT_ID%
echo attachment sha256=%ATT_SHA%
if not "%ATT_SHA%"=="%ORIG_SHA%" (
echo FAIL: attachment sha256 mismatch
exit /b 1
)
echo === Create message with empty text and attachment_ids ===
call :guid
set KEY=%GUIDVAL%
curl.exe -s -X POST "%BASE%/api/v1/chats/%CHAT_ID%/messages" ^
-H "Authorization: Bearer %ALICE_TOKEN%" ^
-H "Idempotency-Key: %KEY%" ^
-H "Content-Type: application/json" ^
-d "{\"text\":\"\",\"attachment_ids\":[\"%ATT_ID%\"]}" ^
-o "%TMP%\msg.json" ^
-w "%%{http_code}" > "%TMP%\msg.code"
call :check_code msg.code 201 "create message"
if errorlevel 1 exit /b 1
for /f "delims=" %%a in ('powershell -NoProfile -Command "(Get-Content '%TMP%\msg.json' -Raw | ConvertFrom-Json).id"') do set MSG_ID=%%a
echo message=%MSG_ID%
echo === Bob downloads attachment content ===
curl.exe -s -X GET "%BASE%/api/v1/attachments/%ATT_ID%/content" ^
-H "Authorization: Bearer %BOB_TOKEN%" ^
-o "%TMP%\download.png" ^
-w "%%{http_code}" > "%TMP%\dl.code"
call :check_code dl.code 200 "download content"
if errorlevel 1 exit /b 1
for /f "delims=" %%a in ('powershell -NoProfile -Command "(Get-FileHash -Algorithm SHA256 -Path '%TMP%\download.png').Hash.ToLower()"') do set DL_SHA=%%a
echo downloaded sha256=%DL_SHA%
if not "%DL_SHA%"=="%ORIG_SHA%" (
echo FAIL: downloaded sha256 mismatch
exit /b 1
)
echo === Eve must get 404 on metadata ===
curl.exe -s -o nul ^
-H "Authorization: Bearer %EVE_TOKEN%" ^
-w "%%{http_code}" "%BASE%/api/v1/attachments/%ATT_ID%" > "%TMP%\eve_meta.code"
call :check_code eve_meta.code 404 "eve metadata"
if errorlevel 1 exit /b 1
echo === Eve must get 404 on content ===
curl.exe -s -o nul ^
-H "Authorization: Bearer %EVE_TOKEN%" ^
-w "%%{http_code}" "%BASE%/api/v1/attachments/%ATT_ID%/content" > "%TMP%\eve_content.code"
call :check_code eve_content.code 404 "eve content"
if errorlevel 1 exit /b 1
echo.
echo ALL MANUAL ATTACHMENT CHECKS PASSED
exit /b 0
:guid
for /f "delims=" %%a in ('powershell -NoProfile -Command "[guid]::NewGuid().ToString('N').Substring(0,8)"') do set GUIDVAL=%%a
exit /b 0
:register
rem %1 username, %2 display_name, %3 prefix
curl.exe -s -X POST "%BASE%/api/v1/users" ^
-H "Content-Type: application/json" ^
-d "{\"username\":\"%~1\",\"display_name\":\"%~2\",\"password\":\"%PASS%\"}" ^
-o "%TMP%\%~3.json" ^
-w "%%{http_code}" > "%TMP%\%~3.code"
set /p RC=<"%TMP%\%~3.code"
if not "%RC%"=="201" (
echo FAIL: register %~1, HTTP %RC%
type "%TMP%\%~3.json"
exit /b 1
)
for /f "delims=" %%a in ('powershell -NoProfile -Command "(Get-Content '%TMP%\%~3.json' -Raw | ConvertFrom-Json).id"') do set "%~3_ID=%%a"
exit /b 0
:login
rem %1 username, %2 prefix
curl.exe -s -X POST "%BASE%/api/v1/auth/sessions" ^
-u "%~1:%PASS%" ^
-o "%TMP%\%~2.json" ^
-w "%%{http_code}" > "%TMP%\%~2.code"
set /p RC=<"%TMP%\%~2.code"
if not "%RC%"=="201" (
echo FAIL: login %~1, HTTP %RC%
type "%TMP%\%~2.json"
exit /b 1
)
for /f "delims=" %%a in ('powershell -NoProfile -Command "(Get-Content '%TMP%\%~2.json' -Raw | ConvertFrom-Json).token"') do set "%~2_TOKEN=%%a"
for /f "delims=" %%a in ('powershell -NoProfile -Command "(Get-Content '%TMP%\%~2.json' -Raw | ConvertFrom-Json).user.id"') do set "%~2_UID=%%a"
exit /b 0
:check_code
rem %1 code file, %2 expected status, %3 label
set /p RC=<"%TMP%\%~1"
if not "%RC%"=="%~2" (
echo FAIL: %~3 expected %~2, got %RC%
exit /b 1
)
exit /b 0
+10
View File
@@ -0,0 +1,10 @@
@echo off
rem Пик памяти API ВО ВРЕМЯ 10 одновременных загрузок (уровень 4).
rem Монитор и загрузки — фоновые PowerShell-джобы; пик пишется в файл,
rem главный поток читает его после остановки монитора.
setlocal
cd /d "%~dp0.."
powershell -NoProfile -ExecutionPolicy Bypass -Command "$ErrorActionPreference='Stop'; $Base='http://localhost:8080'; $Pass='Example-only-not-a-real-secret-123'; $Fixture='tests\fixtures\sample.png'; $Tmp=Join-Path $env:TEMP 'lab4-mempeak'; New-Item -ItemType Directory -Force $Tmp | Out-Null; $u='mp'+[guid]::NewGuid().ToString('N').Substring(0,8); $ub=@{username=$u;display_name='MemPeak';password=$Pass}|ConvertTo-Json -Compress; Invoke-RestMethod -Method Post -Uri ($Base+'/api/v1/users') -ContentType 'application/json' -Body $ub | Out-Null; $basic=[Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes($u+':'+$Pass)); $sess=Invoke-RestMethod -Method Post -Uri ($Base+'/api/v1/auth/sessions') -Headers @{Authorization='Basic '+$basic}; $tok=$sess.token; $hdr=@{Authorization='Bearer '+$tok}; $cb=@{title='MemPeak';member_ids=@($sess.user.id)}|ConvertTo-Json -Compress; $chat=Invoke-RestMethod -Method Post -Uri ($Base+'/api/v1/chats') -Headers $hdr -ContentType 'application/json' -Body $cb; Write-Host ('chat='+$chat.id); $peakFile=Join-Path $Tmp 'peak.txt'; $stopFile=Join-Path $Tmp 'stop.flag'; Remove-Item $peakFile,$stopFile -ErrorAction SilentlyContinue; $mon=Start-Job -ScriptBlock { param($pf,$sf); $max=0.0; while(-not (Test-Path $sf)){ $s = docker stats --no-stream --format '{{.Name}} {{.MemUsage}}' mtusi2026lab4_api_1 mtusi2026lab4_api_2 2>$null; foreach($l in $s){ if($l -match '(\d+(?:\.\d+)?)MiB /'){ $v=[double]$Matches[1]; if($v -gt $max){$max=$v} } }; Start-Sleep -Milliseconds 200 }; Set-Content -Path $pf -Value $max } -ArgumentList $peakFile,$stopFile; $bytes=[IO.File]::ReadAllBytes($Fixture); $jobs=1..10 | ForEach-Object { $i=$_; Start-Job -ScriptBlock { param($B,$C,$T,$By,$I) $h=@{Authorization='Bearer '+$T}; try { $r=Invoke-WebRequest -Method Post -Uri ($B+'/api/v1/chats/'+$C+'/attachments?filename=mp'+$I+'.png') -Headers $h -ContentType 'image/png' -Body $By -UseBasicParsing; return [pscustomobject]@{I=$I;Status=[int]$r.StatusCode;Ok=($r.StatusCode -eq 201)} } catch { return [pscustomobject]@{I=$I;Status=$_.Exception.Response.StatusCode.value__;Ok=$false} } } -ArgumentList $Base,$chat.id,$tok,$bytes,$i }; $jobs | Wait-Job | Out-Null; $res=$jobs | Receive-Job; $jobs | Remove-Job; $res | Format-Table -AutoSize; $ok=($res | Where-Object Ok).Count; Write-Host ('Successful uploads: '+$ok+' / 10'); if($ok -ne 10){ throw 'not all uploads succeeded' }; New-Item -ItemType File -Path $stopFile | Out-Null; $mon | Wait-Job | Out-Null; $peak=Get-Content $peakFile; $mon | Remove-Job; Write-Host ''; Write-Host ('Peak API memory during 10 concurrent uploads: '+$peak+' MiB (limit 256 MiB per replica)') -ForegroundColor Green; docker stats --no-stream --format 'table {{.Name}}\t{{.CPUPerc}}\t{{.MemUsage}}\t{{.MemPerc}}'"
exit /b %ERRORLEVEL%
+223
View File
@@ -0,0 +1,223 @@
@echo off
setlocal EnableDelayedExpansion
cd /d "%~dp0.."
set BASE=http://localhost:8080
set PASS=Example-only-not-a-real-secret-123
set FIXTURE=tests\fixtures\sample.png
set TMP=%TEMP%\lab4-negative
if not exist "%TMP%" mkdir "%TMP%"
call :guid
set RND=%GUIDVAL%
set ALICE=alice%RND%
set BOB=bob%RND%
set EVE=eve%RND%
echo === Setup users ===
call :register "%ALICE%" "Alice" alice
if errorlevel 1 exit /b 1
set ALICE_ID=!alice_ID!
call :register "%BOB%" "Bob" bob
if errorlevel 1 exit /b 1
set BOB_ID=!bob_ID!
call :register "%EVE%" "Eve" eve
if errorlevel 1 exit /b 1
call :login "%ALICE%" alice
if errorlevel 1 exit /b 1
set ALICE_TOKEN=!alice_TOKEN!
call :login "%BOB%" bob
if errorlevel 1 exit /b 1
set BOB_TOKEN=!bob_TOKEN!
call :login "%EVE%" eve
if errorlevel 1 exit /b 1
set EVE_TOKEN=!eve_TOKEN!
echo === Create chat1 alice+bob ===
curl.exe -s -X POST "%BASE%/api/v1/chats" ^
-H "Authorization: Bearer %ALICE_TOKEN%" ^
-H "Content-Type: application/json" ^
-d "{\"title\":\"Negative chat1\",\"member_ids\":[\"%ALICE_ID%\",\"%BOB_ID%\"]}" ^
-o "%TMP%\chat1.json" ^
-w "%%{http_code}" > "%TMP%\chat1.code"
call :check_code chat1.code 201 "create chat1"
if errorlevel 1 exit /b 1
for /f "delims=" %%a in ('powershell -NoProfile -Command "(Get-Content '%TMP%\chat1.json' -Raw | ConvertFrom-Json).id"') do set CHAT1_ID=%%a
echo === Create chat2 alice+eve ===
curl.exe -s -X POST "%BASE%/api/v1/chats" ^
-H "Authorization: Bearer %ALICE_TOKEN%" ^
-H "Content-Type: application/json" ^
-d "{\"title\":\"Negative chat2\",\"member_ids\":[\"%ALICE_ID%\",\"%EVE_ID%\"]}" ^
-o "%TMP%\chat2.json" ^
-w "%%{http_code}" > "%TMP%\chat2.code"
call :check_code chat2.code 201 "create chat2"
if errorlevel 1 exit /b 1
for /f "delims=" %%a in ('powershell -NoProfile -Command "(Get-Content '%TMP%\chat2.json' -Raw | ConvertFrom-Json).id"') do set CHAT2_ID=%%a
echo === 1. Too large file must return 413 ===
powershell -NoProfile -Command "$path='%TMP%\large.png'; $sig=[byte[]](0x89,0x50,0x4E,0x47,0x0D,0x0A,0x1A,0x0A); $pad=New-Object byte[] (11534336-8); [IO.File]::WriteAllBytes($path, $sig + $pad)"
curl.exe -s -o nul ^
-X POST "%BASE%/api/v1/chats/%CHAT1_ID%/attachments?filename=large.png" ^
-H "Authorization: Bearer %ALICE_TOKEN%" ^
-H "Content-Type: image/png" ^
--data-binary "@%TMP%\large.png" ^
-w "%%{http_code}" > "%TMP%\large.code"
call :check_code large.code 413 "too large upload"
if errorlevel 1 exit /b 1
echo === 2. Broken image must return 415 ===
powershell -NoProfile -Command "[IO.File]::WriteAllBytes('%TMP%\broken.png',[byte[]](0x89,0x50,0x4E,0x47,0x0D,0x0A,0x1A,0x0A,0xFF,0xFF,0xFF,0xFF))"
curl.exe -s -o nul ^
-X POST "%BASE%/api/v1/chats/%CHAT1_ID%/attachments?filename=broken.png" ^
-H "Authorization: Bearer %ALICE_TOKEN%" ^
-H "Content-Type: image/png" ^
--data-binary "@%TMP%\broken.png" ^
-w "%%{http_code}" > "%TMP%\broken.code"
call :check_code broken.code 415 "broken png"
if errorlevel 1 exit /b 1
echo === 3. MIME mismatch must return 415 ===
curl.exe -s -o nul ^
-X POST "%BASE%/api/v1/chats/%CHAT1_ID%/attachments?filename=fake.png" ^
-H "Authorization: Bearer %ALICE_TOKEN%" ^
-H "Content-Type: image/jpeg" ^
--data-binary "@%FIXTURE%" ^
-w "%%{http_code}" > "%TMP%\mime.code"
call :check_code mime.code 415 "jpeg disguised as png"
if errorlevel 1 exit /b 1
echo === 4. Dangerous filename must return 400 ===
curl.exe -s -o nul ^
-X POST "%BASE%/api/v1/chats/%CHAT1_ID%/attachments?filename=..%%2Fevil.png" ^
-H "Authorization: Bearer %ALICE_TOKEN%" ^
-H "Content-Type: image/png" ^
--data-binary "@%FIXTURE%" ^
-w "%%{http_code}" > "%TMP%\filename.code"
call :check_code filename.code 400 "path traversal filename"
if errorlevel 1 exit /b 1
echo === 5. Valid upload into chat1 ===
curl.exe -s -X POST "%BASE%/api/v1/chats/%CHAT1_ID%/attachments?filename=sample.png" ^
-H "Authorization: Bearer %ALICE_TOKEN%" ^
-H "Content-Type: image/png" ^
--data-binary "@%FIXTURE%" ^
-o "%TMP%\att.json" ^
-w "%%{http_code}" > "%TMP%\att.code"
call :check_code att.code 201 "valid upload"
if errorlevel 1 exit /b 1
for /f "delims=" %%a in ('powershell -NoProfile -Command "(Get-Content '%TMP%\att.json' -Raw | ConvertFrom-Json).id"') do set ATT_ID=%%a
echo attachment=%ATT_ID% in chat1=%CHAT1_ID%
echo === 6. Cross-chat attachment reference must return 404 ===
call :guid
set KEY1=%GUIDVAL%
curl.exe -s -o nul ^
-X POST "%BASE%/api/v1/chats/%CHAT2_ID%/messages" ^
-H "Authorization: Bearer %ALICE_TOKEN%" ^
-H "Idempotency-Key: %KEY1%" ^
-H "Content-Type: application/json" ^
-d "{\"text\":\"\",\"attachment_ids\":[\"%ATT_ID%\"]}" ^
-w "%%{http_code}" > "%TMP%\crosschat.code"
call :check_code crosschat.code 404 "cross-chat attachment reference"
if errorlevel 1 exit /b 1
echo === 7. Unknown attachment id must return 404 ===
call :guid
set UNKNOWN=%%a
for /f "delims=" %%a in ('powershell -NoProfile -Command "[guid]::NewGuid().ToString()"') do set UNKNOWN=%%a
call :guid
set KEY2=%GUIDVAL%
curl.exe -s -o nul ^
-X POST "%BASE%/api/v1/chats/%CHAT1_ID%/messages" ^
-H "Authorization: Bearer %ALICE_TOKEN%" ^
-H "Idempotency-Key: %KEY2%" ^
-H "Content-Type: application/json" ^
-d "{\"text\":\"\",\"attachment_ids\":[\"%UNKNOWN%\"]}" ^
-w "%%{http_code}" > "%TMP%\unknown.code"
call :check_code unknown.code 404 "unknown attachment id"
if errorlevel 1 exit /b 1
echo === 8. Eve cannot download chat1 attachment ===
curl.exe -s -o nul ^
-H "Authorization: Bearer %EVE_TOKEN%" ^
-w "%%{http_code}" "%BASE%/api/v1/attachments/%ATT_ID%/content" > "%TMP%\eve_dl.code"
call :check_code eve_dl.code 404 "eve download"
if errorlevel 1 exit /b 1
echo.
echo ALL NEGATIVE CHECKS PASSED
exit /b 0
:guid
for /f "delims=" %%a in ('powershell -NoProfile -Command "[guid]::NewGuid().ToString('N').Substring(0,8)"') do set GUIDVAL=%%a
exit /b 0
:register
rem %1 username, %2 display_name, %3 prefix
curl.exe -s -X POST "%BASE%/api/v1/users" ^
-H "Content-Type: application/json" ^
-d "{\"username\":\"%~1\",\"display_name\":\"%~2\",\"password\":\"%PASS%\"}" ^
-o "%TMP%\%~3.json" ^
-w "%%{http_code}" > "%TMP%\%~3.code"
set /p RC=<"%TMP%\%~3.code"
if not "%RC%"=="201" (
echo FAIL: register %~1, HTTP %RC%
type "%TMP%\%~3.json"
exit /b 1
)
for /f "delims=" %%a in ('powershell -NoProfile -Command "(Get-Content '%TMP%\%~3.json' -Raw | ConvertFrom-Json).id"') do set "%~3_ID=%%a"
exit /b 0
:login
rem %1 username, %2 prefix
curl.exe -s -X POST "%BASE%/api/v1/auth/sessions" ^
-u "%~1:%PASS%" ^
-o "%TMP%\%~2.json" ^
-w "%%{http_code}" > "%TMP%\%~2.code"
set /p RC=<"%TMP%\%~2.code"
if not "%RC%"=="201" (
echo FAIL: login %~1, HTTP %RC%
type "%TMP%\%~2.json"
exit /b 1
)
for /f "delims=" %%a in ('powershell -NoProfile -Command "(Get-Content '%TMP%\%~2.json' -Raw | ConvertFrom-Json).token"') do set "%~2_TOKEN=%%a"
for /f "delims=" %%a in ('powershell -NoProfile -Command "(Get-Content '%TMP%\%~2.json' -Raw | ConvertFrom-Json).user.id"') do set "%~2_UID=%%a"
exit /b 0
:check_code
rem %1 code file, %2 expected status, %3 label
set /p RC=<"%TMP%\%~1"
if not "%RC%"=="%~2" (
echo FAIL: %~3 expected %~2, got %RC%
exit /b 1
)
exit /b 0
+133
View File
@@ -0,0 +1,133 @@
@echo off
setlocal EnableDelayedExpansion
cd /d "%~dp0.."
set BASE=http://localhost:8080
set PASS=Example-only-not-a-real-secret-123
set FIXTURE=tests\fixtures\sample.png
set TMP=%TEMP%\lab4-persistence
if not exist "%TMP%" mkdir "%TMP%"
call :guid
set RND=%GUIDVAL%
set PUSER=pers%RND%
echo === Register persistence user ===
call :register "%PUSER%" "Persistence" pers
if errorlevel 1 exit /b 1
set PUSER_ID=!pers_ID!
call :login "%PUSER%" pers
if errorlevel 1 exit /b 1
set TOKEN=!pers_TOKEN!
echo === Create chat ===
curl.exe -s -X POST "%BASE%/api/v1/chats" ^
-H "Authorization: Bearer %TOKEN%" ^
-H "Content-Type: application/json" ^
-d "{\"title\":\"Persistence attachment\",\"member_ids\":[\"%PUSER_ID%\"]}" ^
-o "%TMP%\chat.json" ^
-w "%%{http_code}" > "%TMP%\chat.code"
call :check_code chat.code 201 "create chat"
if errorlevel 1 exit /b 1
for /f "delims=" %%a in ('powershell -NoProfile -Command "(Get-Content '%TMP%\chat.json' -Raw | ConvertFrom-Json).id"') do set CHAT_ID=%%a
echo === Upload attachment ===
for /f "delims=" %%a in ('powershell -NoProfile -Command "(Get-FileHash -Algorithm SHA256 -Path '%FIXTURE%').Hash.ToLower()"') do set ORIG_SHA=%%a
curl.exe -s -X POST "%BASE%/api/v1/chats/%CHAT_ID%/attachments?filename=persistence.png" ^
-H "Authorization: Bearer %TOKEN%" ^
-H "Content-Type: image/png" ^
--data-binary "@%FIXTURE%" ^
-o "%TMP%\att.json" ^
-w "%%{http_code}" > "%TMP%\att.code"
call :check_code att.code 201 "upload attachment"
if errorlevel 1 exit /b 1
for /f "delims=" %%a in ('powershell -NoProfile -Command "(Get-Content '%TMP%\att.json' -Raw | ConvertFrom-Json).id"') do set ATT_ID=%%a
echo === Create message with attachment ===
call :guid
set KEY=%GUIDVAL%
curl.exe -s -X POST "%BASE%/api/v1/chats/%CHAT_ID%/messages" ^
-H "Authorization: Bearer %TOKEN%" ^
-H "Idempotency-Key: %KEY%" ^
-H "Content-Type: application/json" ^
-d "{\"text\":\"\",\"attachment_ids\":[\"%ATT_ID%\"]}" ^
-o "%TMP%\msg.json" ^
-w "%%{http_code}" > "%TMP%\msg.code"
call :check_code msg.code 201 "create message"
if errorlevel 1 exit /b 1
for /f "delims=" %%a in ('powershell -NoProfile -Command "(Get-Content '%TMP%\msg.json' -Raw | ConvertFrom-Json).id"') do set MSG_ID=%%a
echo === Save state ===
>"%TMP%\username.txt" echo %PUSER%
>"%TMP%\token.txt" echo %TOKEN%
>"%TMP%\chat_id.txt" echo %CHAT_ID%
>"%TMP%\att_id.txt" echo %ATT_ID%
>"%TMP%\msg_id.txt" echo %MSG_ID%
>"%TMP%\sha256.txt" echo %ORIG_SHA%
echo State saved to %TMP%
echo attachment=%ATT_ID%
echo message=%MSG_ID%
echo.
echo Now run:
echo scripts\restart-stack.bat
echo scripts\persistence-verify.bat
exit /b 0
:guid
for /f "delims=" %%a in ('powershell -NoProfile -Command "[guid]::NewGuid().ToString('N').Substring(0,8)"') do set GUIDVAL=%%a
exit /b 0
:register
rem %1 username, %2 display_name, %3 prefix
curl.exe -s -X POST "%BASE%/api/v1/users" ^
-H "Content-Type: application/json" ^
-d "{\"username\":\"%~1\",\"display_name\":\"%~2\",\"password\":\"%PASS%\"}" ^
-o "%TMP%\%~3.json" ^
-w "%%{http_code}" > "%TMP%\%~3.code"
set /p RC=<"%TMP%\%~3.code"
if not "%RC%"=="201" (
echo FAIL: register %~1, HTTP %RC%
type "%TMP%\%~3.json"
exit /b 1
)
for /f "delims=" %%a in ('powershell -NoProfile -Command "(Get-Content '%TMP%\%~3.json' -Raw | ConvertFrom-Json).id"') do set "%~3_ID=%%a"
exit /b 0
:login
rem %1 username, %2 prefix
curl.exe -s -X POST "%BASE%/api/v1/auth/sessions" ^
-u "%~1:%PASS%" ^
-o "%TMP%\%~2.json" ^
-w "%%{http_code}" > "%TMP%\%~2.code"
set /p RC=<"%TMP%\%~2.code"
if not "%RC%"=="201" (
echo FAIL: login %~1, HTTP %RC%
type "%TMP%\%~2.json"
exit /b 1
)
for /f "delims=" %%a in ('powershell -NoProfile -Command "(Get-Content '%TMP%\%~2.json' -Raw | ConvertFrom-Json).token"') do set "%~2_TOKEN=%%a"
for /f "delims=" %%a in ('powershell -NoProfile -Command "(Get-Content '%TMP%\%~2.json' -Raw | ConvertFrom-Json).user.id"') do set "%~2_UID=%%a"
exit /b 0
:check_code
rem %1 code file, %2 expected status, %3 label
set /p RC=<"%TMP%\%~1"
if not "%RC%"=="%~2" (
echo FAIL: %~3 expected %~2, got %RC%
exit /b 1
)
exit /b 0
+92
View File
@@ -0,0 +1,92 @@
@echo off
setlocal EnableDelayedExpansion
cd /d "%~dp0.."
set BASE=http://localhost:8080
set TMP=%TEMP%\lab4-persistence
if not exist "%TMP%\token.txt" (
echo FAIL: state not found. Run scripts\persistence-attachment.bat first.
exit /b 1
)
set /p TOKEN=<"%TMP%\token.txt"
set /p CHAT_ID=<"%TMP%\chat_id.txt"
set /p ATT_ID=<"%TMP%\att_id.txt"
set /p MSG_ID=<"%TMP%\msg_id.txt"
set /p EXPECTED_SHA=<"%TMP%\sha256.txt"
echo === Persistence verify after restart ===
echo chat=%CHAT_ID%
echo attachment=%ATT_ID%
echo message=%MSG_ID%
echo expected sha256=%EXPECTED_SHA%
echo === Check metadata ===
curl.exe -s -X GET "%BASE%/api/v1/attachments/%ATT_ID%" ^
-H "Authorization: Bearer %TOKEN%" ^
-o "%TMP%\meta.json" ^
-w "%%{http_code}" > "%TMP%\meta.code"
set /p RC=<"%TMP%\meta.code"
if not "%RC%"=="200" (
echo FAIL: metadata HTTP %RC%
type "%TMP%\meta.json"
exit /b 1
)
for /f "delims=" %%a in ('powershell -NoProfile -Command "(Get-Content '%TMP%\meta.json' -Raw | ConvertFrom-Json).sha256"') do set META_SHA=%%a
if not "%META_SHA%"=="%EXPECTED_SHA%" (
echo FAIL: metadata sha256 mismatch
exit /b 1
)
echo PASS: attachment metadata survived restart
echo === Check content ===
curl.exe -s -X GET "%BASE%/api/v1/attachments/%ATT_ID%/content" ^
-H "Authorization: Bearer %TOKEN%" ^
-o "%TMP%\download.png" ^
-w "%%{http_code}" > "%TMP%\content.code"
set /p RC=<"%TMP%\content.code"
if not "%RC%"=="200" (
echo FAIL: content HTTP %RC%
exit /b 1
)
for /f "delims=" %%a in ('powershell -NoProfile -Command "(Get-FileHash -Algorithm SHA256 -Path '%TMP%\download.png').Hash.ToLower()"') do set DL_SHA=%%a
if not "%DL_SHA%"=="%EXPECTED_SHA%" (
echo FAIL: downloaded sha256 mismatch
exit /b 1
)
echo PASS: attachment bytes survived restart
echo === Check message history ===
curl.exe -s -X GET "%BASE%/api/v1/chats/%CHAT_ID%/messages?limit=100" ^
-H "Authorization: Bearer %TOKEN%" ^
-o "%TMP%\history.json" ^
-w "%%{http_code}" > "%TMP%\history.code"
set /p RC=<"%TMP%\history.code"
if not "%RC%"=="200" (
echo FAIL: history HTTP %RC%
type "%TMP%\history.json"
exit /b 1
)
powershell -NoProfile -Command "$h=Get-Content '%TMP%\history.json' -Raw | ConvertFrom-Json; if (-not ($h.items | Where-Object { $_.id -eq '%MSG_ID%' -and $_.attachment_ids -contains '%ATT_ID%' })) { exit 1 }"
if errorlevel 1 (
echo FAIL: message with attachment not found after restart
exit /b 1
)
echo PASS: message with attachment survived restart
echo PASS: old session token still works
echo.
echo ALL PERSISTENCE CHECKS PASSED
exit /b 0
+39
View File
@@ -0,0 +1,39 @@
@echo off
setlocal EnableDelayedExpansion
cd /d "%~dp0.."
set TMP=%TEMP%\lab4-private
if not exist "%TMP%" mkdir "%TMP%"
echo === Private bucket check ===
for /f "delims=" %%a in ('docker compose exec -T postgres psql -U messenger -d messenger -tAc "SELECT s3_key FROM attachments ORDER BY created_at DESC LIMIT 1"') do set KEY=%%a
if "%KEY%"=="" (
echo FAIL: no attachments found. Run scripts\manual-attachments.bat first.
exit /b 1
)
echo Latest s3_key: %KEY%
docker compose exec -T api sh -lc "wget -S -O /dev/null http://rustfs:9000/messenger/%KEY% 2>&1" > "%TMP%\out.txt" 2>&1
echo.
echo Direct unauthenticated response:
type "%TMP%\out.txt"
echo.
findstr /c:"HTTP/1.1 200" "%TMP%\out.txt" >nul
if not errorlevel 1 (
echo FAIL: bucket appears public, direct GET returned 200
exit /b 1
)
findstr /c:"HTTP/" "%TMP%\out.txt" >nul
if errorlevel 1 (
echo WARN: could not parse HTTP status from wget output
exit /b 2
)
echo PASS: direct unauthenticated access is not 200
exit /b 0
+88
View File
@@ -0,0 +1,88 @@
@echo off
setlocal EnableDelayedExpansion
cd /d "%~dp0.."
set BASE=http://localhost:8080
set PASS=Example-only-not-a-real-secret-123
set FIXTURE=tests\fixtures\sample.png
set TMP=%TEMP%\lab4-reconcile
if not exist "%TMP%" mkdir "%TMP%"
call :guid
set RND=%GUIDVAL%
set RUSER=rec%RND%
echo === Register + login ===
call :register "%RUSER%" "Reconcile" rec
if errorlevel 1 exit /b 1
set RID=!rec_ID!
call :login "%RUSER%" rec
if errorlevel 1 exit /b 1
set TOKEN=!rec_TOKEN!
echo === Create chat ===
curl.exe -s -X POST "%BASE%/api/v1/chats" ^
-H "Authorization: Bearer %TOKEN%" ^
-H "Content-Type: application/json" ^
-d "{\"title\":\"Reconcile demo\",\"member_ids\":[\"%RID%\"]}" ^
-o "%TMP%\chat.json" -w "%%{http_code}" > "%TMP%\chat.code"
call :check_code chat.code 201 "create chat"
if errorlevel 1 exit /b 1
for /f "delims=" %%a in ('powershell -NoProfile -Command "(Get-Content '%TMP%\chat.json' -Raw | ConvertFrom-Json).id"') do set CHAT_ID=%%a
echo === Upload attachment (creates S3 object + DB metadata) ===
curl.exe -s -X POST "%BASE%/api/v1/chats/%CHAT_ID%/attachments?filename=orphan.png" ^
-H "Authorization: Bearer %TOKEN%" ^
-H "Content-Type: image/png" ^
--data-binary "@%FIXTURE%" ^
-o "%TMP%\att.json" -w "%%{http_code}" > "%TMP%\att.code"
call :check_code att.code 201 "upload attachment"
if errorlevel 1 exit /b 1
for /f "delims=" %%a in ('powershell -NoProfile -Command "(Get-Content '%TMP%\att.json' -Raw | ConvertFrom-Json).id"') do set ATT_ID=%%a
echo attachment=%ATT_ID%
echo === Simulate crash: delete DB metadata, leave S3 object orphaned ===
docker compose exec -T postgres psql -U messenger -d messenger -c "DELETE FROM attachments WHERE id='%ATT_ID%';"
echo === Run reconcile with grace=0 (must delete the orphan) ===
docker compose --compatibility --profile tools run -e RECONCILE_GRACE_PERIOD_SECONDS=0 --rm reconcile
if errorlevel 1 (
echo FAIL: reconcile exited non-zero
exit /b 1
)
echo === Run reconcile again (idempotent: 0 orphans deleted) ===
docker compose --compatibility --profile tools run -e RECONCILE_GRACE_PERIOD_SECONDS=0 --rm reconcile
if errorlevel 1 exit /b 1
echo.
echo RECONCILE DEMO COMPLETE: inspect logs above for "reconcile deleted orphan" then "orphans_deleted 0".
exit /b 0
:guid
for /f "delims=" %%a in ('powershell -NoProfile -Command "[guid]::NewGuid().ToString('N').Substring(0,8)"') do set GUIDVAL=%%a
exit /b 0
:register
curl.exe -s -X POST "%BASE%/api/v1/users" ^
-H "Content-Type: application/json" ^
-d "{\"username\":\"%~1\",\"display_name\":\"%~2\",\"password\":\"%PASS%\"}" ^
-o "%TMP%\%~3.json" -w "%%{http_code}" > "%TMP%\%~3.code"
set /p RC=<"%TMP%\%~3.code"
if not "%RC%"=="201" ( echo FAIL: register %~1, HTTP %RC% & type "%TMP%\%~3.json" & exit /b 1 )
for /f "delims=" %%a in ('powershell -NoProfile -Command "(Get-Content '%TMP%\%~3.json' -Raw | ConvertFrom-Json).id"') do set "%~3_ID=%%a"
exit /b 0
:login
curl.exe -s -X POST "%BASE%/api/v1/auth/sessions" ^
-u "%~1:%PASS%" ^
-o "%TMP%\%~2.json" -w "%%{http_code}" > "%TMP%\%~2.code"
set /p RC=<"%TMP%\%~2.code"
if not "%RC%"=="201" ( echo FAIL: login %~1, HTTP %RC% & type "%TMP%\%~2.json" & exit /b 1 )
for /f "delims=" %%a in ('powershell -NoProfile -Command "(Get-Content '%TMP%\%~2.json' -Raw | ConvertFrom-Json).token"') do set "%~2_TOKEN=%%a"
exit /b 0
:check_code
set /p RC=<"%TMP%\%~1"
if not "%RC%"=="%~2" ( echo FAIL: %~3 expected %~2, got %RC% & exit /b 1 )
exit /b 0
+5
View File
@@ -0,0 +1,5 @@
@echo off
setlocal
cd /d "%~dp0.."
docker compose --compatibility --profile tools run --rm reconcile
exit /b %ERRORLEVEL%
+29
View File
@@ -0,0 +1,29 @@
@echo off
setlocal EnableDelayedExpansion
cd /d "%~dp0.."
set TMP=%TEMP%\lab4-restart
if not exist "%TMP%" mkdir "%TMP%"
echo Restarting stack without removing volumes...
docker compose --compatibility restart
set COUNT=0
:wait
set /a COUNT+=1
if %COUNT% GTR 90 (
echo FAIL: stack did not become ready in time
exit /b 1
)
curl.exe -s -o nul -w "%%{http_code}" http://localhost:8080/health/ready > "%TMP%\code.txt"
set /p C=<"%TMP%\code.txt"
if "%C%"=="200" (
echo Stack is ready.
exit /b 0
)
timeout /t 1 /nobreak >nul
goto wait
+8
View File
@@ -0,0 +1,8 @@
@echo off
setlocal
cd /d "%~dp0.."
set PYTHONUTF8=1
python -X utf8 tests\smoke.py --base-url http://localhost:8080
exit /b %ERRORLEVEL%
+28
View File
@@ -0,0 +1,28 @@
@echo off
setlocal EnableDelayedExpansion
cd /d "%~dp0.."
if "%TARGET_INSTANCE_ID%"=="" (
echo FAIL: TARGET_INSTANCE_ID is not set
exit /b 1
)
for /f "tokens=1 delims=-" %%a in ("%TARGET_INSTANCE_ID%") do set PREFIX=%%a
echo Target instance: %TARGET_INSTANCE_ID%
echo Hostname prefix: %PREFIX%
for /f "delims=" %%i in ('docker ps --filter "label=com.docker.compose.service=api" --format "{{.ID}}"') do (
for /f "delims=" %%h in ('docker inspect --format "{{.Config.Hostname}}" %%i') do (
set "H=%%h"
echo !H! | findstr /b /c:"%PREFIX%" >nul
if not errorlevel 1 (
echo Stopping container %%i with hostname !H!
docker stop --time 10 %%i >nul
exit /b 0
)
)
)
echo FAIL: target replica not found
exit /b 1
+12
View File
@@ -0,0 +1,12 @@
@echo off
setlocal
cd /d "%~dp0.."
set PYTHONUTF8=1
python -X utf8 tests\resilience.py ^
--base-url http://localhost:8080 ^
--mode failover ^
--action-script scripts\stop-one.bat
exit /b %ERRORLEVEL%
+12
View File
@@ -0,0 +1,12 @@
@echo off
setlocal
cd /d "%~dp0.."
set PYTHONUTF8=1
python -X utf8 tests\resilience.py ^
--base-url http://localhost:8080 ^
--mode persistence ^
--action-script scripts\restart-stack.bat
exit /b %ERRORLEVEL%