Commits

wooparadog  committed 43980af

add test for exception raised at releasing lock

  • Participants
  • Parent commits 6a4f7d5

Comments (0)

Files changed (1)

File tests/core/test_dogpile.py

+import pytest
 from unittest import TestCase
 import time
 import threading
-from dogpile.core import Dogpile, SyncReaderDogpile, NeedRegenerationException
+from dogpile.core import (Dogpile, SyncReaderDogpile,
+        NeedRegenerationException, LockReleaseException)
 from dogpile.core.nameregistry import NameRegistry
 import contextlib
 import math
         with dogpile.acquire(create_resource):
             assert the_resource[0] == 1
 
+    def test_raise_exception_when_releasing_lock(self):
+        class MockLock(object):
+            def acquire(self, wait=True):
+                pass
+
+            def release(self):
+                raise ValueError
+
+        lock = MockLock()
+
+        dogpile = Dogpile(None, lock=lock)
+
+        def create_resource():
+            return 1
+
+        with pytest.raises(LockReleaseException) as e:
+            with dogpile.acquire(create_resource):
+                assert e.value.return_val == 1
+                assert e.errisinstance(ValueError)