Added _poll_lock exception tests (#19446)

This commit is contained in:
Tamara Dahlgren 2020-10-21 17:32:04 -07:00 committed by GitHub
parent 94221fa225
commit e78764caa1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -43,6 +43,8 @@
"""
import collections
import errno
import fcntl
import os
import socket
import shutil
@ -1277,6 +1279,30 @@ def test_downgrade_write_fails(tmpdir):
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):
"""Test the lock read-to-write upgrade operation."""
with tmpdir.as_cwd():