From 3270f93d7f49c68afb783f325ddee9babcc88642 Mon Sep 17 00:00:00 2001 From: Aleksander Mistewicz Date: Tue, 12 Jul 2016 18:31:35 +0200 Subject: [PATCH] Add test/resource_locking.py.bats Change-Id: I7ea1e13702ea17488da6c2c0424db1283d7f4db2 Signed-off-by: Aleksander Mistewicz --- test/resource_locking.py.bats | 89 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100755 test/resource_locking.py.bats 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" ] +} -- 2.7.4