Skip to content

Commit

Permalink
limit filelock use
Browse files Browse the repository at this point in the history
  • Loading branch information
marqh committed Oct 27, 2016
1 parent bb9d169 commit f458ad0
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions lib/iris/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -804,10 +804,17 @@ def check_graphic(self):
"""
fname = os.path.join(_RESULT_PATH, 'imagerepo.lock')
lock = filelock.FileLock(fname)
# The imagerepo.json file is a critical resource, so ensure thread
# The imagerepo.json file is a critical resource, during development. So,
# if the file is writeable, or it doesn't exist but could be written, ensure thread
# safe read/write behaviour via platform independent file locking.
with lock.acquire(timeout=600):
# Otherwise, do not lock, as this prevents tests being run without
# write permissions to this _RESULT_PATH location.
if (os.access(fname, os.W_OK) or
(not os.access(fname, os.R_OK) and os.access(_RESULT_PATH, os.W_OK))):
lock = filelock.FileLock(fname)
with lock.acquire(timeout=600):
self._assert_graphic()
else:
self._assert_graphic()

def _remove_testcase_patches(self):
Expand Down

0 comments on commit f458ad0

Please sign in to comment.