summary refs log tree commit diff
path: root/tests/util
diff options
context:
space:
mode:
authorAmber Brown <hawkowl@atleastfornow.net>2019-07-03 04:01:28 +1000
committerRichard van der Hoff <1389908+richvdh@users.noreply.github.com>2019-07-02 19:01:28 +0100
commit0ee9076ffe40140db5e86763af077efbdb5d86b0 (patch)
treeacab7d2c00d9daeaf45e7c5eeee9e6cf1f8f60af /tests/util
parenttweak changelog (diff)
downloadsynapse-0ee9076ffe40140db5e86763af077efbdb5d86b0.tar.xz
Fix media repo breaking (#5593)
Diffstat (limited to 'tests/util')
-rw-r--r--tests/util/test_logcontext.py33
1 files changed, 21 insertions, 12 deletions
diff --git a/tests/util/test_logcontext.py b/tests/util/test_logcontext.py
index 8adaee3c8d..8d69fbf111 100644
--- a/tests/util/test_logcontext.py
+++ b/tests/util/test_logcontext.py
@@ -39,24 +39,17 @@ class LoggingContextTestCase(unittest.TestCase):
 
         callback_completed = [False]
 
-        def test():
+        with LoggingContext() as context_one:
             context_one.request = "one"
-            d = function()
+
+            # fire off function, but don't wait on it.
+            d2 = logcontext.run_in_background(function)
 
             def cb(res):
-                self._check_test_key("one")
                 callback_completed[0] = True
                 return res
 
-            d.addCallback(cb)
-
-            return d
-
-        with LoggingContext() as context_one:
-            context_one.request = "one"
-
-            # fire off function, but don't wait on it.
-            logcontext.run_in_background(test)
+            d2.addCallback(cb)
 
             self._check_test_key("one")
 
@@ -105,6 +98,22 @@ class LoggingContextTestCase(unittest.TestCase):
 
         return self._test_run_in_background(testfunc)
 
+    def test_run_in_background_with_coroutine(self):
+        async def testfunc():
+            self._check_test_key("one")
+            d = Clock(reactor).sleep(0)
+            self.assertIs(LoggingContext.current_context(), LoggingContext.sentinel)
+            await d
+            self._check_test_key("one")
+
+        return self._test_run_in_background(testfunc)
+
+    def test_run_in_background_with_nonblocking_coroutine(self):
+        async def testfunc():
+            self._check_test_key("one")
+
+        return self._test_run_in_background(testfunc)
+
     @defer.inlineCallbacks
     def test_make_deferred_yieldable(self):
         # a function which retuns an incomplete deferred, but doesn't follow