summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksander Mistewicz <a.mistewicz@samsung.com>2016-07-12 18:31:35 +0200
committerAleksander Mistewicz <a.mistewicz@samsung.com>2016-12-06 16:37:13 +0100
commit3270f93d7f49c68afb783f325ddee9babcc88642 (patch)
treea44ee0c644f46c67298aa67e08dca09fe7e85cf6
parent25470c9f2dde4a249f83afc218a07ca02455fbd5 (diff)
downloadmajor-3270f93d7f49c68afb783f325ddee9babcc88642.tar.gz
major-3270f93d7f49c68afb783f325ddee9babcc88642.tar.bz2
major-3270f93d7f49c68afb783f325ddee9babcc88642.zip
Add test/resource_locking.py.bats
Change-Id: I7ea1e13702ea17488da6c2c0424db1283d7f4db2 Signed-off-by: Aleksander Mistewicz <a.mistewicz@samsung.com>
-rwxr-xr-xtest/resource_locking.py.bats89
1 files changed, 89 insertions, 0 deletions
diff --git a/test/resource_locking.py.bats b/test/resource_locking.py.bats
new file mode 100755
index 0000000..27aa416
--- /dev/null
+++ b/test/resource_locking.py.bats
@@ -0,0 +1,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" ]
+}