0
0
Fork 1
mirror of https://mau.dev/maunium/synapse.git synced 2024-12-21 08:44:00 +01:00
synapse/tests/util/test_log_context.py

36 lines
1 KiB
Python
Raw Normal View History

2014-10-30 02:21:33 +01:00
from twisted.internet import defer
from twisted.internet import reactor
from .. import unittest
from synapse.util.async import sleep
from synapse.util.logcontext import LoggingContext
2016-02-09 15:57:43 +01:00
2014-10-30 02:21:33 +01:00
class LoggingContextTestCase(unittest.TestCase):
def _check_test_key(self, value):
self.assertEquals(
LoggingContext.current_context().test_key, value
)
def test_with_context(self):
with LoggingContext() as context_one:
context_one.test_key = "test"
self._check_test_key("test")
@defer.inlineCallbacks
def test_sleep(self):
@defer.inlineCallbacks
def competing_callback():
with LoggingContext() as competing_context:
competing_context.test_key = "competing"
yield sleep(0)
self._check_test_key("competing")
reactor.callLater(0, competing_callback)
with LoggingContext() as context_one:
context_one.test_key = "one"
yield sleep(0)
self._check_test_key("one")