From da38d6cca9d25b58e8d3f09ade64c87d9ee4a36f Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 10 Jul 2011 14:20:41 -0600 Subject: [PATCH] ... --- src/calibre/db/locking.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/calibre/db/locking.py b/src/calibre/db/locking.py index 3092f1a2fa..0b34855d01 100644 --- a/src/calibre/db/locking.py +++ b/src/calibre/db/locking.py @@ -211,6 +211,26 @@ if __name__ == '__main__': class TestSHLock(unittest.TestCase): """Testcases for SHLock class.""" + def test_multithread_deadlock(self): + lock = SHLock() + def two_shared(): + lock.acquire(shared=True) + time.sleep(0.2) + lock.acquire(blocking=True, shared=True) + lock.release() + lock.release() + def one_exclusive(): + time.sleep(0.1) + lock.acquire(blocking=True, shared=False) + threads = [Thread(target=two_shared), Thread(target=one_exclusive)] + for t in threads: + t.daemon = True + t.start() + for t in threads: + t.join(5) + live = [t for t in threads if t.is_alive()] + self.assertListEqual(live, [], 'ShLock hung') + def test_upgrade(self): lock = SHLock() lock.acquire(shared=True)