[CYPRESS_FRAMEWORK] Run Cypress tests in parallel
Description:
Cypress tests are resource intensive and consume a lot of memory and power. But that should not stop us from running them in parallel even if they consume a lot of resources. At present, Cypress tests here at Hyperswitch is run in sequential and consumes a lot of time given that each connector consumes at least 10+ mins and we've 10+ connector to run tests for.
With that said, the task is to parallelize the tests that are run and with that said, the consumption can be reduced drastically (1+ hour(s) to mere 15 mins).
[!IMPORTANT] Cypress cloud is a no go
Below is the shell script that runs helps run the test in both sequential and parallel ways:
#!/bin/bash
CONNECTORS=("adyen" "bankofamerica" "bluesnap" "cybersource" "iatapay" "nmi" "paypal" "stripe" "trustpay")
# Function to run tests
run_tests() {
mkdir -p results
local pids=()
for connector in "${CONNECTORS[@]}"; do
if [[ $parallel == true ]]; then
CYPRESS_CONNECTOR="${connector}" npm run cypress:ci > results/${connector}.txt 2>&1 &
pids+=($!)
else
printf "\rRunning Cypress tests against the connector: ${connector}"
CYPRESS_CONNECTOR="${connector}" npm run cypress:ci > results/${connector}.txt 2>&1
local exit_code=$?
if [[ $exit_code -ne 0 && $exit_code -ge 128 ]]; then
exit 1
fi
sleep 3
fi
done
if [[ $parallel == true ]]; then
for pid in "${pids[@]}"; do
wait $pid
done
fi
}
# Check if running in parallel
if [[ "${1}" == "--parallel" ]]; then
printf "WARNING: Parallel tests are flaky and may not work as expected.\n"
eval run_tests true
else
eval run_tests false
fi
To execute the script:
# to run tests sequentially, which can take an hour+
sh run-cypress.sh
# to run tests in parallel, consumes around 15 - 20 mins, at the cost of resources
sh run-cypress.sh --parallel
Getting started:
Go through the README for guidelines on file structure, formatting and instructions on how to set up and run Cypress.
In short:
cd cypress-tests
npm ci
Possible implementation:
- Shell script above is attached for reference
- Make use of
gnu-parallelto reduce the complexity of the script. The advantage here is that, it also make the script more future proof, manageable, easier to read and understand - As a bonus, the same functionality can be implemented in JavaScript directly into Cypress via its configs is a plus
[!WARNING] Make sure that before this task is picked, the machine is capable enough to run at least 2 connector tests in parallel. Running Cypress tests in parallel is too resource intensive! Please go through the Cypress docs to learn whether you're machine meets minimum requirements.
This is a P0, I'll be picking this up.
CC: @gorakhnathy7
this was parked until recently due to other priority tasks, will pick this again, soon.
Sure @pixincreate