-
Notifications
You must be signed in to change notification settings - Fork 46
/
test
executable file
·54 lines (42 loc) · 1.7 KB
/
test
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
#!/usr/bin/env bash
set -x
function fatal {
echo "${1}"
exit 1
}
# Set magic variables for current FILE & DIR
__FILE__="$(test -L "$0" && readlink "$0" || echo "$0")"
__DIR__="$(dirname "${__FILE__}")"
export CRONLOCK_VERBOSE=yes
# This config should fail
export CRONLOCK_CONFIG="${__DIR__}/invalid.conf"
CRONLOCK_RESET=yes ./cronlock pwd
[ "${?}" -ne 201 ] && fatal "Invalid redis port in invalid.conf should have failed"
export CRONLOCK_CONFIG=""
# Reset the key for clean testing. Should only fail if redis is dead
CRONLOCK_RESET=yes ./cronlock pwd
[ "${?}" -ne 200 ] && fatal "Unable to run reset cronlock. Redis ok?"
# Set the key. Should only fail with redis or code problems
CRONLOCK_RESET=yes ./cronlock sleep 2
CRONLOCK_GRACE=2 CRONLOCK_TIMEOUT=1 ./cronlock sleep 2
[ "${?}" -ne 202 ] && fatal "Timeout should have kicked in"
sleep 1
# Set the key. Should only fail with redis or code problems
CRONLOCK_GRACE=2 ./cronlock pwd
[ "${?}" -ne 0 ] && fatal "Unable to run just the first cronlock. Redis ok?"
sleep 1
# Should not be getting a lock after the first cronlock
CRONLOCK_GRACE=1 ./cronlock pwd
[ "${?}" -ne 200 ] && fatal "I should not have been able to run pwd within 2s grace"
sleep 3
# Should be able to get a lock again after the grace
CRONLOCK_GRACE=10 ./cronlock pwd
[ "${?}" -ne 0 ] && fatal "I should have been able to run pwd again"
CRONLOCK_DB=1 ./cronlock pwd
[ "${?}" -ne 0 ] && fatal "I should have been able to run pwd after changing dbs"
CRONLOCK_DB=-1 ./cronlock pwd
[ "${?}" -ne 201 ] && fatal "Invalid db should have failed"
# Invalid auth code should fail with redis
CRONLOCK_AUTH=INVALID_AUTH_CODE ./cronlock pwd
[ "${?}" -ne 201 ] && fatal "Invalid redis auth code should have failed"
exit 0