#!/bin/bash

set -o errexit -o nounset -o pipefail

install_deps() {
  for version in 2 3;
  do
    python$version -m pip install .
  done
}

install_extensions() {
    cd test/extensions
    sh install_packages.sh
    cd ../../
}

run_tests() {
  cd test/core && PYTHONPATH=`pwd`/../../ python3 run_tests.py --num-parallel 8 && cd ../../
}

# We run realtime cards tests separately because there these tests validate the asynchronous updates to the
# information stored in the datastore. So if there are other processes starving resources then these tests will
# surely fail since a lot of checks have timeouts. 
run_runtime_card_tests() {
  CARD_GRAPHS="small-foreach,small-parallel,nested-branches,single-linear-step,simple-foreach"
  cd test/core && PYTHONPATH=`pwd`/../../ python3 run_tests.py --num-parallel 8 --contexts python3-all-local-cards-realtime --graphs $CARD_GRAPHS && cd ../../
}

install_deps && install_extensions && run_tests && run_runtime_card_tests
