summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTamara Dahlgren <35777542+tldahlgren@users.noreply.github.com>2020-10-21 17:32:04 -0700
committerGitHub <noreply@github.com>2020-10-21 17:32:04 -0700
commite78764caa16af8581f99855ee297d682e14f3600 (patch)
tree1947ac66707b836c19343fea655bc561170f2918 /lib
parent94221fa22577df73c71c598488f532a850caaa0a (diff)
downloadspack-e78764caa16af8581f99855ee297d682e14f3600.tar.gz
spack-e78764caa16af8581f99855ee297d682e14f3600.tar.bz2
spack-e78764caa16af8581f99855ee297d682e14f3600.tar.xz
spack-e78764caa16af8581f99855ee297d682e14f3600.zip
Added _poll_lock exception tests (#19446)
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/test/llnl/util/lock.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/lib/spack/spack/test/llnl/util/lock.py b/lib/spack/spack/test/llnl/util/lock.py
index 99c1eba588..596a801179 100644
--- a/lib/spack/spack/test/llnl/util/lock.py
+++ b/lib/spack/spack/test/llnl/util/lock.py
@@ -43,6 +43,8 @@ actually on a shared filesystem.
"""
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():