-
Notifications
You must be signed in to change notification settings - Fork 2
/
test_helper.sh
56 lines (45 loc) · 1.01 KB
/
test_helper.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/bin/bash
TIMEOUT=30
wait_for_port () {
port=$1
timeout=$2
for i in `seq 1 $TIMEOUT`
do
if [ `lsof -nt -iTCP:${SERVICE_PORT:="8080"} -sTCP:LISTEN | wc -l` -gt 0 ]
then
return 0
fi
sleep 1
done
return 1
}
server_pid=
kill_server () {
if [ $server_pid ]; then echo "killing $server_pid"; kill $server_pid; fi
}
handle_force_exit () {
echo -e "\nHandling interrupt"
kill_server
exit 1
}
trap handle_force_exit INT
run_test () {
type=$1
timeout=$2
lein trampoline run&
server_pid=$!
port=${SERVICE_PORT:="8080"}
echo "PID: $server_pid"
echo -e "**********\nGiving lein $timeout seconds to build and start the application...\n**********"
if wait_for_port $port $timeout
then
lein midje $1
at_res=$?
kill_server
exit $at_res
else
kill_server
echo "Exploded failed to start, it was not reachable on port $port within $timeout seconds"
exit 1
fi
}