diff options
| author | Jenkins <jenkins@review.openstack.org> | 2013-03-22 16:45:55 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2013-03-22 16:45:55 +0000 |
| commit | ad611a718b699eb377f271fa2e5bf2e26c602b75 (patch) | |
| tree | 67691ff518e2a829f60eeecf7e98079e1ecf3cde | |
| parent | 3b8db7e5072c7fd04b2bad637a5718f07d6f967c (diff) | |
| parent | f689e1cb5cfe9b43b3e2fec0e28b1ce80a0cccae (diff) | |
| download | oslo-ad611a718b699eb377f271fa2e5bf2e26c602b75.tar.gz oslo-ad611a718b699eb377f271fa2e5bf2e26c602b75.tar.xz oslo-ad611a718b699eb377f271fa2e5bf2e26c602b75.zip | |
Merge "lockutils: improve the external locks test"
| -rw-r--r-- | tests/unit/test_lockutils.py | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/tests/unit/test_lockutils.py b/tests/unit/test_lockutils.py index 685b0b8..e1f0375 100644 --- a/tests/unit/test_lockutils.py +++ b/tests/unit/test_lockutils.py @@ -127,18 +127,15 @@ class LockTestCase(utils.BaseTestCase): def test_synchronized_externally(self): """We can lock across multiple processes""" - tempdir = tempfile.mkdtemp() - self.config(lock_path=tempdir) + lock_dir = tempfile.mkdtemp() + self.config(lock_path=lock_dir) @lockutils.synchronized('external', 'test-', external=True) - def lock_files(tempdir): - if not os.path.exists(tempdir): - os.makedirs(tempdir) - + def lock_files(handles_dir): # Open some files we can use for locking handles = [] for n in range(50): - path = os.path.join(tempdir, ('file-%s' % n)) + path = os.path.join(handles_dir, ('file-%s' % n)) handles.append(open(path, 'w')) # Loop over all the handles and try locking the file @@ -159,6 +156,7 @@ class LockTestCase(utils.BaseTestCase): # Check if we were able to open all files self.assertEqual(50, count) + handles_dir = tempfile.mkdtemp() try: children = [] for n in range(50): @@ -166,13 +164,17 @@ class LockTestCase(utils.BaseTestCase): if pid: children.append(pid) else: - lock_files(tempdir) - os._exit(0) + try: + lock_files(handles_dir) + finally: + os._exit(0) for i, child in enumerate(children): (pid, status) = os.waitpid(child, 0) if pid: self.assertEqual(0, status) finally: - if os.path.exists(tempdir): - shutil.rmtree(tempdir, ignore_errors=True) + if os.path.exists(handles_dir): + shutil.rmtree(handles_dir, ignore_errors=True) + if os.path.exists(lock_dir): + shutil.rmtree(lock_dir, ignore_errors=True) |
