|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +set +e # Disable exit on error, we want to clean up after an error |
| 4 | + |
| 5 | +export AWS_ACCESS_KEY_ID="test" |
| 6 | +export AWS_SECRET_ACCESS_KEY="test" |
| 7 | +export AWS_DEFAULT_REGION="eu-west-1" |
| 8 | +export AWS_ENDPOINT_URL="http://localhost:4566" |
| 9 | + |
| 10 | +uuid=$(uuidgen) |
| 11 | + |
| 12 | +# get the queue URL |
| 13 | +queue_url=$(aws sqs get-queue-url --queue-name result-queue | jq -r '.QueueUrl') |
| 14 | +echo "Queue URL: $queue_url" |
| 15 | + |
| 16 | +# Background process: posts item to SQS queue to trigger the response |
| 17 | +( |
| 18 | + # Generate random number between 1-5 |
| 19 | + sleep_time=$(( (RANDOM % 5) + 1 )) |
| 20 | + echo "Will execute AWS command after ${sleep_time} seconds..." |
| 21 | + sleep ${sleep_time} |
| 22 | + aws sqs send-message \ |
| 23 | + --endpoint-url http://localhost:4566 \ |
| 24 | + --queue-url http://localhost:4566/000000000000/result-queue \ |
| 25 | + --message-body "{\"uuid\": \"$uuid\", \"payload\": {\"name\": \"response payload from service\"}}" |
| 26 | + echo "AWS command executed." |
| 27 | +) & |
| 28 | +background_pid=$! |
| 29 | + |
| 30 | +echo "Request UUID: $uuid" |
| 31 | + |
| 32 | +curl -XPOST --retry 5 --fail-with-body \ |
| 33 | + localhost:8080/api/process \ |
| 34 | + -H "Content-Type: application/json" \ |
| 35 | + -d "{\"uuid\": \"$uuid\", \"payload\": {\"name\": \"default\", \"timeout\": 20}}" |
| 36 | +curl_exit_status=$? |
| 37 | + |
| 38 | +if [ $curl_exit_status -ne 0 ]; then |
| 39 | + echo "\nCurl failed with status $curl_exit_status. Killing background process..." |
| 40 | + kill $background_pid |
| 41 | + wait $background_pid 2>/dev/null || true |
| 42 | + echo "Background process terminated." |
| 43 | + echo "Test failed." |
| 44 | + exit $curl_exit_status |
| 45 | +fi |
| 46 | + |
| 47 | +echo "\nWaiting for AWS command to complete..." |
| 48 | +wait $background_pid |
| 49 | +echo "Test successful." |
0 commit comments