Merge "Require lock_path limit to be a positive int"
This commit is contained in:
commit
0da972bbb0
@ -2338,7 +2338,11 @@ def lock_path(directory, timeout=10, timeout_class=None, limit=1):
|
|||||||
the same directory at the time this method is called. Note that this
|
the same directory at the time this method is called. Note that this
|
||||||
limit is only applied during the current call to this method and does
|
limit is only applied during the current call to this method and does
|
||||||
not prevent subsequent calls giving a larger limit. Defaults to 1.
|
not prevent subsequent calls giving a larger limit. Defaults to 1.
|
||||||
|
:raises TypeError: if limit is not an int.
|
||||||
|
:raises ValueError: if limit is less than 1.
|
||||||
"""
|
"""
|
||||||
|
if limit < 1:
|
||||||
|
raise ValueError('limit must be greater than or equal to 1')
|
||||||
if timeout_class is None:
|
if timeout_class is None:
|
||||||
timeout_class = swift.common.exceptions.LockTimeout
|
timeout_class = swift.common.exceptions.LockTimeout
|
||||||
mkdirs(directory)
|
mkdirs(directory)
|
||||||
|
@ -963,6 +963,26 @@ class TestUtils(unittest.TestCase):
|
|||||||
success = True
|
success = True
|
||||||
self.assertFalse(success)
|
self.assertFalse(success)
|
||||||
|
|
||||||
|
@with_tempdir
|
||||||
|
def test_lock_path_invalid_limit(self, tmpdir):
|
||||||
|
success = False
|
||||||
|
with self.assertRaises(ValueError):
|
||||||
|
with utils.lock_path(tmpdir, 0.1, limit=0):
|
||||||
|
success = True
|
||||||
|
self.assertFalse(success)
|
||||||
|
with self.assertRaises(ValueError):
|
||||||
|
with utils.lock_path(tmpdir, 0.1, limit=-1):
|
||||||
|
success = True
|
||||||
|
self.assertFalse(success)
|
||||||
|
with self.assertRaises(TypeError):
|
||||||
|
with utils.lock_path(tmpdir, 0.1, limit='1'):
|
||||||
|
success = True
|
||||||
|
self.assertFalse(success)
|
||||||
|
with self.assertRaises(TypeError):
|
||||||
|
with utils.lock_path(tmpdir, 0.1, limit=1.1):
|
||||||
|
success = True
|
||||||
|
self.assertFalse(success)
|
||||||
|
|
||||||
@with_tempdir
|
@with_tempdir
|
||||||
def test_lock_path_num_sleeps(self, tmpdir):
|
def test_lock_path_num_sleeps(self, tmpdir):
|
||||||
num_short_calls = [0]
|
num_short_calls = [0]
|
||||||
|
Loading…
Reference in New Issue
Block a user