Added _poll_lock exception tests (#19446)
This commit is contained in:
parent
94221fa225
commit
e78764caa1
@ -43,6 +43,8 @@
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
import collections
|
import collections
|
||||||
|
import errno
|
||||||
|
import fcntl
|
||||||
import os
|
import os
|
||||||
import socket
|
import socket
|
||||||
import shutil
|
import shutil
|
||||||
@ -1277,6 +1279,30 @@ def test_downgrade_write_fails(tmpdir):
|
|||||||
lock.downgrade_write_to_read()
|
lock.downgrade_write_to_read()
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("err_num,err_msg",
|
||||||
|
[(errno.EACCES, "Fake EACCES error"),
|
||||||
|
(errno.EAGAIN, "Fake EAGAIN error"),
|
||||||
|
(errno.ENOENT, "Fake ENOENT error")])
|
||||||
|
def test_poll_lock_exception(tmpdir, monkeypatch, err_num, err_msg):
|
||||||
|
"""Test poll lock exception handling."""
|
||||||
|
def _lockf(fd, cmd, len, start, whence):
|
||||||
|
raise IOError(err_num, err_msg)
|
||||||
|
|
||||||
|
with tmpdir.as_cwd():
|
||||||
|
lockfile = 'lockfile'
|
||||||
|
lock = lk.Lock(lockfile)
|
||||||
|
|
||||||
|
touch(lockfile)
|
||||||
|
|
||||||
|
monkeypatch.setattr(fcntl, 'lockf', _lockf)
|
||||||
|
|
||||||
|
if err_num in [errno.EAGAIN, errno.EACCES]:
|
||||||
|
assert not lock._poll_lock(fcntl.LOCK_EX)
|
||||||
|
else:
|
||||||
|
with pytest.raises(IOError, match=err_msg):
|
||||||
|
lock._poll_lock(fcntl.LOCK_EX)
|
||||||
|
|
||||||
|
|
||||||
def test_upgrade_read_okay(tmpdir):
|
def test_upgrade_read_okay(tmpdir):
|
||||||
"""Test the lock read-to-write upgrade operation."""
|
"""Test the lock read-to-write upgrade operation."""
|
||||||
with tmpdir.as_cwd():
|
with tmpdir.as_cwd():
|
||||||
|
Loading…
Reference in New Issue
Block a user