summaryrefslogtreecommitdiff
path: root/test/resource_locking.py.bats
blob: 27aa4160f57664b2aabaaf7630be7fbd2b94349f (plain)
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/env bats

teardown() {
    test -z "`ls /var/tmp/uuid-foo* 2>/dev/null`" || rm /var/tmp/uuid-foo* 2>/dev/null
}

@test "no arguments" {
    RES="`python tct/resource_locking.py 2>&1`" || RET="$?"
    [ "$RET" -ne 0 ]
    [ -n "$RES" ]
}

@test "missing argument" {
    RES="`python tct/resource_locking.py --lock 2>&1`" || RET="$?"
    [ -n "$RES" ]
}

@test "wrong arguments" {
    RES="`python tct/resource_locking.py -qwe 2>&1`" || RET="$?"
    [ -n "$RES" ]
}

@test "lock" {
    touch /var/tmp/uuid-foo_1
    RES="`python tct/resource_locking.py --lock foo`"
    [ "$RES" = "foo_1" ]
}

@test "retrylock" {
    touch /var/tmp/uuid-foo_1
    RES="`python tct/resource_locking.py --retrylock foo`"
    [ "$RES" = "foo_1" ]
}

@test "lock_twice" {
    touch /var/tmp/uuid-foo_1
    RES="`python tct/resource_locking.py --lock foo`"
    [ "$RES" = "foo_1" ]
    RES="`python tct/resource_locking.py --lock foo`"
    [ -z "$RES" ]
}

@test "lock_unlock" {
    touch /var/tmp/uuid-foo_1
    RES="`python tct/resource_locking.py --lock foo`"
    [ "$RES" = "foo_1" ]
    RES="`python tct/resource_locking.py --unlock foo_1`"
    [ -z "$RES" ]
}

@test "lock_order" {
    touch /var/tmp/uuid-foo_1
    touch /var/tmp/uuid-foo_2
    touch /var/tmp/uuid-foo_3
    echo 3 > /var/tmp/uuid-foo_1.cnt
    echo 1 > /var/tmp/uuid-foo_2.cnt
    echo 2 > /var/tmp/uuid-foo_3.cnt
    RES="`python tct/resource_locking.py --lock foo`"
    [ "$RES" = "foo_2" ]
    RES="`python tct/resource_locking.py --lock foo`"
    [ "$RES" = "foo_3" ]
    RES="`python tct/resource_locking.py --lock foo`"
    [ "$RES" = "foo_1" ]
    RES="`python tct/resource_locking.py --lock foo`"
    [ -z "$RES" ]
}

@test "lock_unlockfailed" {
    touch /var/tmp/uuid-foo_1
    RES="`python tct/resource_locking.py --lock foo`"
    [ "$RES" = "foo_1" ]
    RES="`python tct/resource_locking.py --unlockfailed foo_1`"
    [ -z "$RES" ]
    [ "`cat /var/tmp/uuid-foo_1.cnt`" = "11" ]
}

@test "lock_unlockfailed_with_inc" {
    touch /var/tmp/uuid-foo_1
    RES="`python tct/resource_locking.py --lock foo`"
    [ "$RES" = "foo_1" ]
    RES="`python tct/resource_locking.py --unlockfailed foo_1 --inc 666`"
    [ -z "$RES" ]
    [ "`cat /var/tmp/uuid-foo_1.cnt`" = "667" ]
}

@test "retrylock_empty" {
    RES="`python tct/resource_locking.py --retrylock foobar 2>&1`" || RET="$?"
    [ -n "$RES" ]
}