#!/bin/bash

[ -f tests/database.server.sqlite ] && rm tests/database.server.sqlite

export OG_SERVER_CONFIG='../tests/config_server.py'
export OG_ENGINE_DIR='./tests/ogr_test_engine'
cd web
export PYTHONPATH="$(pwd)"
./db.py
./fill_data.py
./admin.py &
admin_pid=$!
./job_receiver.py &
job_receiver_pid=$!
cd ../job_executer
export OG_JOB_EXECUTER_CONFIG="../tests/config_client1.py"
./job_executer.py &
client1_pid=$!
export OG_JOB_EXECUTER_CONFIG="../tests/config_client2.py"
./job_executer.py &
client2_pid=$!
export OG_JOB_EXECUTER_CONFIG="../tests/config_client3.py"
./job_executer.py &
client3_pid=$!
trap "cd .. && kill -9 $admin_pid $client1_pid $client2_pid $client3_pid $job_receiver_pid" EXIT SIGTERM
cd ../tests
export OG_SERVER_CONFIG='config_server.py'
python .
exit 0