Skip to content

Instantly share code, notes, and snippets.

@mago0
Created October 4, 2018 20:52
Show Gist options
  • Save mago0/f7846e6638eb9f0f3fc22e1e9c9b70fb to your computer and use it in GitHub Desktop.
Save mago0/f7846e6638eb9f0f3fc22e1e9c9b70fb to your computer and use it in GitHub Desktop.
# Check we have the jq binary to make parsing JSON responses a bit easier
command -v jq >/dev/null 2>&1 || \
{ echo >&2 "Please install http://stedolan.github.io/jq/download/ Aborting."; exit 1; }
# Look for an existing grid
grid_uuid=$(curl --silent --user $FLOOD_API_TOKEN: https://api.flood.io/grids \
| jq 'if ._embedded.grids[] > 0 then ._embedded.grids[0].uuid else empty end' | tr -d '"' || true)
if [[ $grid_uuid == '' ]]; then
# Start grid
echo
echo "[$(date +%FT%T)+00:00] Starting grid"
grid_uuid=$(curl -u ${FLOOD_API_TOKEN}: -X POST https://api.flood.io/grids \
-H "Accept: application/vnd.flood.v2+json" \
-F "grid[region]=us-west-2" \
-F "grid[infrastructure]=hosted" \
-F "grid[aws_platform]=ec2_default_vpc" \
-F "grid[aws_vpc_identifier]=vpc-f85a4590" \
-F "grid[aws_tags]=project=flood-io,env=lt" \
-F "grid[instance_quantity]=1" \
-F "grid[stop_after]=20" \
-F "grid[instance_type]=m5.12xlarge" \
-F "grid[credential_id]=xGKl8x" | jq -r '.uuid')
# Wait for grid to finish
echo "[$(date +%FT%T)+00:00] Waiting for grid $grid_uuid"
while [ $(curl --silent --user $FLOOD_API_TOKEN: https://api.flood.io/grids/$grid_uuid | \
jq -r '.status == "started"') == "false" ]; do
echo -n "."
sleep 3
done
fi
# Start a flood
echo
echo "[$(date +%FT%T)+00:00] Starting flood"
flood_uuid=$(curl --user $FLOOD_API_TOKEN: -X POST https://api.flood.io/floods \
-H "Accept: application/vnd.flood.v2+json" \
-F "flood[tool]=flood-chrome" \
-F "flood[browser-count]=200" \
-F "flood[browser-density]=200" \
-F "flood[threads]=200" \
-F "flood[rampup]=900" \
-F "flood[duration]=60" \
-F "flood_files[]=@tests/visit_live_page_with_login.ts" \
-F "flood_files[]=@tests/emails.csv" \
-F "flood[grids][][uuid]=${grid_uuid}" \
-F "flood[name]=view_live_via_login" | jq -r '.uuid')
# Wait for flood to finish
echo "[$(date +%FT%T)+00:00] Waiting for flood $flood_uuid"
while [ $(curl --silent --user $FLOOD_API_TOKEN: https://api.flood.io/floods/$flood_uuid | \
jq -r '.status == "finished"') = "false" ]; do
echo -n "."
sleep 3
done
# Get the summary report
flood_report=$(curl --silent --user $FLOOD_API_TOKEN: https://api.flood.io/floods/$flood_uuid/report | \
jq -r ".summary")
echo
echo "[$(date +%FT%T)+00:00] Detailed results at https://flood.io/$flood_uuid"
echo "$flood_report"
# Optionally store the CSV results
echo
echo "[$(date +%FT%T)+00:00] Storing CSV results at results.csv"
curl --silent --user $FLOOD_API_TOKEN: https://api.flood.io/floods/$flood_uuid/results.csv > results.csv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment