#!/bin/sh
set -e
sed -i -e 's|api_url:.*$|api_url: "https://qa-cypress-director.theorchard.io/"|g' /var/lib/jenkins/.cache/Cypress/*/Cypress/resources/app/packages/server/config/app.yml

echo "api_url changed to point to https://qa-cypress-director.theorchard.io/"
echo "running parallel cypress processes:$1"

# run processes and wait
for (( c=1; c<= $1; c++ ))
do
  Xvfb -screen 0 1024x768x24 :${c} &
  export DISPLAY=:${c}
  THREAD_ID=${c} npm run test:integration:parallel &
  pids[${c}]=$!
done

# wait for all pids
for pid in ${pids[*]}; do
    wait $pid
done
