summaryrefslogtreecommitdiffstats
path: root/pym/portage/tests/locks
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2011-06-08 17:32:56 -0700
committerZac Medico <zmedico@gentoo.org>2011-06-08 17:32:56 -0700
commitc249745ca37f996ef7de51d1be2997e6734d649b (patch)
tree5078b49c69db7f662f3960a6529de12354e05ac7 /pym/portage/tests/locks
parentac01d2898ece4589cdaa971382cc1dc17261ed58 (diff)
downloadportage-c249745ca37f996ef7de51d1be2997e6734d649b.tar.gz
portage-c249745ca37f996ef7de51d1be2997e6734d649b.tar.bz2
portage-c249745ca37f996ef7de51d1be2997e6734d649b.zip
Test noblocking locks.
Diffstat (limited to 'pym/portage/tests/locks')
-rw-r--r--pym/portage/tests/locks/test_lock_nonblock.py46
1 files changed, 46 insertions, 0 deletions
diff --git a/pym/portage/tests/locks/test_lock_nonblock.py b/pym/portage/tests/locks/test_lock_nonblock.py
new file mode 100644
index 000000000..d5748ad62
--- /dev/null
+++ b/pym/portage/tests/locks/test_lock_nonblock.py
@@ -0,0 +1,46 @@
+# Copyright 2011 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+import shutil
+import tempfile
+import traceback
+
+import portage
+from portage import os
+from portage.tests import TestCase
+
+class LockNonblockTestCase(TestCase):
+
+ def testLockNonblock(self):
+ tempdir = tempfile.mkdtemp()
+ try:
+ path = os.path.join(tempdir, 'lock_me')
+ lock1 = portage.locks.lockfile(path)
+ pid = os.fork()
+ if pid == 0:
+ portage.process._setup_pipes({0:0, 1:1, 2:2})
+ rval = 2
+ try:
+ try:
+ lock2 = portage.locks.lockfile(path, flags=os.O_NONBLOCK)
+ except portage.exception.TryAgain:
+ rval = os.EX_OK
+ else:
+ rval = 1
+ portage.locks.unlockfile(lock2)
+ except SystemExit:
+ raise
+ except:
+ traceback.print_exc()
+ finally:
+ os._exit(rval)
+
+ self.assertEqual(pid > 0, True)
+ pid, status = os.waitpid(pid, 0)
+ self.assertEqual(os.WIFEXITED(status), True)
+ self.assertEqual(os.WEXITSTATUS(status), os.EX_OK)
+
+ portage.locks.unlockfile(lock1)
+ finally:
+ shutil.rmtree(tempdir)
+