mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-05-04 16:14:56 -04:00
Fix logcontext leak in HttpTransactionCache
ONE DAY I WILL PURGE THE WORLD OF THIS EVIL
This commit is contained in:
parent
6d6e7288fe
commit
6e1cb54a05
2 changed files with 38 additions and 21 deletions
|
@ -3,6 +3,7 @@ from synapse.rest.client.transactions import CLEANUP_PERIOD_MS
|
|||
from twisted.internet import defer
|
||||
from mock import Mock, call
|
||||
|
||||
from synapse.util import async
|
||||
from synapse.util.logcontext import LoggingContext
|
||||
from tests import unittest
|
||||
from tests.utils import MockClock
|
||||
|
@ -41,6 +42,26 @@ class HttpTransactionCacheTestCase(unittest.TestCase):
|
|||
# expect only a single call to do the work
|
||||
cb.assert_called_once_with("some_arg", keyword="arg", changing_args=0)
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def test_logcontexts_with_async_result(self):
|
||||
@defer.inlineCallbacks
|
||||
def cb():
|
||||
yield async.sleep(0)
|
||||
defer.returnValue("yay")
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def test():
|
||||
with LoggingContext("c") as c1:
|
||||
res = yield self.cache.fetch_or_execute(self.mock_key, cb)
|
||||
self.assertIs(LoggingContext.current_context(), c1)
|
||||
self.assertEqual(res, "yay")
|
||||
|
||||
# run the test twice in parallel
|
||||
d = defer.gatherResults([test(), test()])
|
||||
self.assertIs(LoggingContext.current_context(), LoggingContext.sentinel)
|
||||
yield d
|
||||
self.assertIs(LoggingContext.current_context(), LoggingContext.sentinel)
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def test_does_not_cache_exceptions(self):
|
||||
"""Checks that, if the callback throws an exception, it is called again
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue