Skip to content
Snippets Groups Projects
Unverified Commit f192a938 authored by Richard van der Hoff's avatar Richard van der Hoff Committed by GitHub
Browse files

Merge pull request #3481 from matrix-org/rav/fix_cachedescriptor_test

Reinstate lost run_on_reactor in unit test
parents 13f7adf8 ea555d56
No related branches found
No related tags found
No related merge requests found
Reinstate lost run_on_reactor in unit tests
...@@ -19,13 +19,19 @@ import logging ...@@ -19,13 +19,19 @@ import logging
import mock import mock
from synapse.api.errors import SynapseError from synapse.api.errors import SynapseError
from synapse.util import logcontext from synapse.util import logcontext
from twisted.internet import defer from twisted.internet import defer, reactor
from synapse.util.caches import descriptors from synapse.util.caches import descriptors
from tests import unittest from tests import unittest
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
def run_on_reactor():
d = defer.Deferred()
reactor.callLater(0, d.callback, 0)
return logcontext.make_deferred_yieldable(d)
class CacheTestCase(unittest.TestCase): class CacheTestCase(unittest.TestCase):
def test_invalidate_all(self): def test_invalidate_all(self):
cache = descriptors.Cache("testcache") cache = descriptors.Cache("testcache")
...@@ -194,6 +200,8 @@ class DescriptorTestCase(unittest.TestCase): ...@@ -194,6 +200,8 @@ class DescriptorTestCase(unittest.TestCase):
def fn(self, arg1): def fn(self, arg1):
@defer.inlineCallbacks @defer.inlineCallbacks
def inner_fn(): def inner_fn():
# we want this to behave like an asynchronous function
yield run_on_reactor()
raise SynapseError(400, "blah") raise SynapseError(400, "blah")
return inner_fn() return inner_fn()
...@@ -203,7 +211,12 @@ class DescriptorTestCase(unittest.TestCase): ...@@ -203,7 +211,12 @@ class DescriptorTestCase(unittest.TestCase):
with logcontext.LoggingContext() as c1: with logcontext.LoggingContext() as c1:
c1.name = "c1" c1.name = "c1"
try: try:
yield obj.fn(1) d = obj.fn(1)
self.assertEqual(
logcontext.LoggingContext.current_context(),
logcontext.LoggingContext.sentinel,
)
yield d
self.fail("No exception thrown") self.fail("No exception thrown")
except SynapseError: except SynapseError:
pass pass
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment