summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJulien Jehannet <julien.jehannet@logilab.fr>2009-01-19 20:49:53 +0100
committerJulien Jehannet <julien.jehannet@logilab.fr>2009-01-19 20:49:53 +0100
commite2c18aeb354c4b1396a42bfd074042e477ae665d (patch)
treef65a7b1b5b3724449531adec5741a4464a9dbda3 /test
parentc03716922dba37c700e81b92a22ef9256440f8bd (diff)
downloadlogilab-common-e2c18aeb354c4b1396a42bfd074042e477ae665d.tar.gz
improve acquire_lock() method
Diffstat (limited to 'test')
-rw-r--r--test/unittest_shellutils.py29
1 files changed, 28 insertions, 1 deletions
diff --git a/test/unittest_shellutils.py b/test/unittest_shellutils.py
index 396d7c6..903312d 100644
--- a/test/unittest_shellutils.py
+++ b/test/unittest_shellutils.py
@@ -5,7 +5,8 @@ from os.path import join
from logilab.common.testlib import TestCase, unittest_main
-from logilab.common.shellutils import globfind, find, ProgressBar
+from logilab.common.shellutils import globfind, find, ProgressBar, acquire_lock, release_lock
+from logilab.common.proc import NoSuchProcess
from StringIO import StringIO
DATA_DIR = join('data','find_test')
@@ -123,5 +124,31 @@ class ProgressBarTC(TestCase):
self._update_test(5, (8, 16, 25, 33, 42, (42, True)), size=42)
+class AcquireLockTC(TestCase):
+
+ def setUp(self):
+ self.tmpdir = tempfile.mkdtemp()
+ self.lock = join(self.tmpdir, 'LOCK')
+
+ def tearDown(self):
+ shutil.rmtree(self.tmpdir)
+
+ def test_acquire_normal(self):
+ self.assertTrue(acquire_lock(self.lock, 1, 1))
+ self.assertTrue(os.path.exists(self.lock))
+ release_lock(self.lock)
+ self.assertFalse(os.path.exists(self.lock))
+
+ def test_no_possible_acquire(self):
+ self.assertRaises(Exception, acquire_lock, self.lock, 0)
+
+ def test_wrong_process(self):
+ fd = os.open(self.lock, os.O_EXCL | os.O_RDWR | os.O_CREAT)
+ os.write(fd, '1111111111')
+ os.close(fd)
+ self.assertTrue(os.path.exists(self.lock))
+ self.assertRaises(NoSuchProcess, acquire_lock, self.lock)
+
+
if __name__ == '__main__':
unittest_main()