Created
March 26, 2018 22:57
-
-
Save liath/49fece9fc6dca640a4d9ecedb7b3c4a7 to your computer and use it in GitHub Desktop.
test case for danilop/yas3fs PR #133
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from shutil import rmtree | |
from tempfile import mkdtemp | |
from threading import Thread | |
from time import sleep | |
from unittest import TestCase | |
from yas3fs import FSCache | |
class testPR133(TestCase): | |
"""Per https://github.com/danilop/yas3fs/pull/133 \ | |
Fix deadlock when a path is re-locked while the cache is locked globally""" | |
def setUp(self): | |
self.tempdir = mkdtemp(prefix='yas3fs-pr133-test-') | |
self.cache = FSCache(self.tempdir) | |
def tearDown(self): | |
rmtree(self.tempdir) | |
def test_deadlock(self): | |
def getGlobalLock(): | |
with self.cache.lock: | |
print('locked global') | |
while(True): | |
sleep(10) | |
def getPathLock(): | |
with self.cache.get_lock('pr133'): | |
print('locked local') | |
self.cache.entries['pr133'] = {} | |
self.cache.entries['pr133']['lock'] = self.cache.new_locks['pr133'] | |
del self.cache.new_locks['pr133'] | |
sleep(2) | |
print('attempting to relock local') | |
with self.cache.get_lock('pr133'): | |
print('relocked local') | |
# lock a path | |
llock = Thread(target=getPathLock) | |
llock.start() | |
sleep(1) | |
# lock the world | |
glock = Thread(target=getGlobalLock) | |
glock.setDaemon(True) | |
glock.start() | |
# wait a bit | |
llock.join(timeout=3) | |
# see if we've encountered a stalemate | |
self.assertFalse(llock.isAlive(), 'Attempt to relock path failed') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment