From 12b78084192f1606c9c568fb5ffd7d88c2eb5b6f Mon Sep 17 00:00:00 2001 From: Kat Date: Wed, 11 Sep 2024 15:36:36 +0100 Subject: [PATCH] Run more tests against staging --- lib/tasks/performance_test.sh | 99 ++++++++++++++++++++++++++++++----- 1 file changed, 87 insertions(+), 12 deletions(-) diff --git a/lib/tasks/performance_test.sh b/lib/tasks/performance_test.sh index 4292ef18c..f7962c2eb 100644 --- a/lib/tasks/performance_test.sh +++ b/lib/tasks/performance_test.sh @@ -1,19 +1,55 @@ cd performance_test + +# Lettings logs page echo "Get token" -TOKEN=$(curl -c token_cookies.txt -s https://review.submit-social-housing-data.levellingup.gov.uk/2623/account/sign-in | grep ' performance_test_results.txt -file="performance_test_results.txt" +echo "Running lettings logs page performance test..." +ab -n 50 -c 50 -C "$COOKIES" 'https://staging.submit-social-housing-data.levellingup.gov.uk/lettings-logs?years[]=2024&status[]=completed' > performance_lettings_test_results.txt +file="performance_lettings_test_results.txt" + +failed_requests=$(grep "Failed requests:" "$file" | awk '{print $3}') +non_2xx_responses=$(grep "Non-2xx responses:" "$file" | awk '{print $3}') +time_per_request_all=$(grep "Time per request:" "$file" | awk 'NR==2{print $4}') +requests_per_second=$(grep "Requests per second:" "$file" | awk '{print $4}') + + +if [ "$failed_requests" -gt 0 ]; then + echo "Lettings logs: Performance test failed - $failed_requests failed requests" + exit 1 +fi + +if [ "$non_2xx_responses" -ne 0 ] && [ -n "$non_2xx_responses" ]; then + echo "Lettings logs: Performance test failed: There were $non_2xx_responses non-2xx responses." + exit 1 +fi + +if (( $(echo "$time_per_request_all > 250" | bc -l) )); then + echo "Lettings logs: Performance test failed - Time per request across all concurrent requests is more than 250 ms: $time_per_request_all ms" + exit 1 +fi + +if (( $(echo "$requests_per_second < 5" | bc -l) )); then + echo "Lettings logs: Performance test failed - Requests per second is less than 5: $requests_per_second" + exit 1 +fi + +echo "Lettings logs page test passed: No failed requests and no non-2xx responses." + + +# Sales logs page +echo "Running sales logs page performance test..." +ab -n 50 -c 50 -C "$COOKIES" 'https://staging.submit-social-housing-data.levellingup.gov.uk/sales-logs?years[]=2024&status[]=completed' > performance_sales_test_results.txt +file="performance_sales_test_results.txt" failed_requests=$(grep "Failed requests:" "$file" | awk '{print $3}') non_2xx_responses=$(grep "Non-2xx responses:" "$file" | awk '{print $3}') @@ -22,24 +58,63 @@ requests_per_second=$(grep "Requests per second:" "$file" | awk '{print $4}') if [ "$failed_requests" -gt 0 ]; then - echo "Performance test failed - $failed_requests failed requests" + echo "Sales logs: Performance test failed - $failed_requests failed requests" exit 1 fi if [ "$non_2xx_responses" -ne 0 ] && [ -n "$non_2xx_responses" ]; then - echo "Test failed: There were $non_2xx_responses non-2xx responses." + echo "Sales logs: Performance test failed: There were $non_2xx_responses non-2xx responses." exit 1 fi -if (( $(echo "$time_per_request_all > 45" | bc -l) )); then - echo "Performance test failed - Time per request across all concurrent requests is more than 25 ms: $time_per_request_all ms" +if (( $(echo "$time_per_request_all > 250" | bc -l) )); then + echo "Sales logs: Performance test failed - Time per request across all concurrent requests is more than 250 ms: $time_per_request_all ms" exit 1 fi -if (( $(echo "$requests_per_second < 20" | bc -l) )); then - echo "Performance test failed - Requests per second is less than 20: $requests_per_second" +if (( $(echo "$requests_per_second < 5" | bc -l) )); then + echo "Sales logs: Performance test failed - Requests per second is less than 5: $requests_per_second" exit 1 fi -echo "Test passed: No failed requests and no non-2xx responses." +echo "Sales logs page test passed: No failed requests and no non-2xx responses." + + +# Post data to a log test +TOKEN=$(curl -L -b login_cookies.txt -c login_cookies.txt https://staging.submit-social-housing-data.levellingup.gov.uk/lettings-logs/2510815/tenant-code | grep ' performance_post_test_results.txt + +file="performance_post_test_results.txt" +failed_requests=$(grep "Failed requests:" "$file" | awk '{print $3}') +time_per_request_all=$(grep "Time per request:" "$file" | awk 'NR==2{print $4}') +requests_per_second=$(grep "Requests per second:" "$file" | awk '{print $4}') + + +if [ "$failed_requests" -gt 0 ]; then + echo "Update logs: Performance test failed - $failed_requests failed requests" + exit 1 +fi + +if (( $(echo "$time_per_request_all > 500" | bc -l) )); then + echo "Update logs: Performance test failed - Time per request across all concurrent requests is more than 500 ms: $time_per_request_all ms" + exit 1 +fi + +if (( $(echo "$requests_per_second < 5" | bc -l) )); then + echo "Update logs: Performance test failed - Requests per second is less than 5: $requests_per_second" + exit 1 +fi + +echo "Update logs test passed: No failed requests and request times as expected." + +echo "All tests passed" exit 0