summary refs log tree commit diff
path: root/tests/unittest.py
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2023-03-30 16:21:12 +0100
committerGitHub <noreply@github.com>2023-03-30 16:21:12 +0100
commit91c3f32673e0c62ea603dcc18f7f21f73c011f33 (patch)
treecd79456df5729402960c80d033dab32a24017925 /tests/unittest.py
parentImplement MSC3984 to proxy /keys/query requests to appservices. (#15321) (diff)
downloadsynapse-91c3f32673e0c62ea603dcc18f7f21f73c011f33.tar.xz
Speed up SQLite unit test CI (#15334)
Tests now take 40% of the time.
Diffstat (limited to '')
-rw-r--r--tests/unittest.py16
1 files changed, 13 insertions, 3 deletions
diff --git a/tests/unittest.py b/tests/unittest.py
index f9160faa1d..8a16fd3665 100644
--- a/tests/unittest.py
+++ b/tests/unittest.py
@@ -146,6 +146,9 @@ class TestCase(unittest.TestCase):
                     % (current_context(),)
                 )
 
+            # Disable GC for duration of test. See below for why.
+            gc.disable()
+
             old_level = logging.getLogger().level
             if level is not None and old_level != level:
 
@@ -163,12 +166,19 @@ class TestCase(unittest.TestCase):
 
             return orig()
 
+        # We want to force a GC to workaround problems with deferreds leaking
+        # logcontexts when they are GCed (see the logcontext docs).
+        #
+        # The easiest way to do this would be to do a full GC after each test
+        # run, but that is very expensive. Instead, we disable GC (above) for
+        # the duration of the test so that we only need to run a gen-0 GC, which
+        # is a lot quicker.
+
         @around(self)
         def tearDown(orig: Callable[[], R]) -> R:
             ret = orig()
-            # force a GC to workaround problems with deferreds leaking logcontexts when
-            # they are GCed (see the logcontext docs)
-            gc.collect()
+            gc.collect(0)
+            gc.enable()
             set_current_context(SENTINEL_CONTEXT)
 
             return ret