diff --git a/CHANGELOG.md b/CHANGELOG.md index b0e8202..1437c02 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] +### [1.81.0.0] - 2023-11-18 + +### Updated + +- Synapse to 1.81.0 + ### [1.80.0.0] - 2023-04-03 ### Updated @@ -131,7 +137,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Location of github action workflow file `build.yml` - Fix robustness for matrix-synapse name and packages changes and rebuilding in the same path (updater script) -[unreleased]: https://github.com/conhealth/LifeTime-Desktop/compare/v1.80.0.0...HEAD +[unreleased]: https://github.com/conhealth/LifeTime-Desktop/compare/v1.81.0.0...HEAD +[1.80.0.0]: https://github.com/conhealth/LifeTime-Desktop/compare/v1.80.0.0...v1.81.0.0 [1.79.0.0]: https://github.com/conhealth/LifeTime-Desktop/compare/v1.79.0.0...v1.80.0.0 [1.79.0.0]: https://github.com/conhealth/LifeTime-Desktop/compare/v1.78.0.0...v1.79.0.0 [1.78.0.0]: https://github.com/conhealth/LifeTime-Desktop/compare/v1.77.0.0...v1.78.0.0 diff --git a/matrix_synapse_testutils/server.py b/matrix_synapse_testutils/server.py index a6aa251..c43903a 100644 --- a/matrix_synapse_testutils/server.py +++ b/matrix_synapse_testutils/server.py @@ -16,6 +16,7 @@ import logging import os import os.path +import sqlite3 import time import uuid import warnings @@ -79,7 +80,9 @@ from synapse.logging.context import ContextResourceUsage from synapse.server import HomeServer from synapse.storage import DataStore +from synapse.storage.database import LoggingDatabaseConnection from synapse.storage.engines import PostgresEngine, create_engine +from synapse.storage.prepare_database import prepare_database from synapse.types import ISynapseReactor, JsonDict from synapse.util import Clock @@ -104,6 +107,10 @@ # the type of thing that can be passed into `make_request` in the headers list CustomHeaderType = Tuple[Union[str, bytes], Union[str, bytes]] +# A pre-prepared SQLite DB that is used as a template when creating new SQLite +# DB each test run. This dramatically speeds up test set up when using SQLite. +PREPPED_SQLITE_DB_CONN: Optional[LoggingDatabaseConnection] = None + class TimedOutException(Exception): """ @@ -899,6 +906,22 @@ def setup_test_homeserver( "args": {"database": test_db_location, "cp_min": 1, "cp_max": 1}, } + # Check if we have set up a DB that we can use as a template. + global PREPPED_SQLITE_DB_CONN + if PREPPED_SQLITE_DB_CONN is None: + temp_engine = create_engine(database_config) + PREPPED_SQLITE_DB_CONN = LoggingDatabaseConnection( + sqlite3.connect(":memory:"), temp_engine, "PREPPED_CONN" + ) + + database = DatabaseConnectionConfig("master", database_config) + config.database.databases = [database] + prepare_database( + PREPPED_SQLITE_DB_CONN, create_engine(database_config), config + ) + + database_config["_TEST_PREPPED_CONN"] = PREPPED_SQLITE_DB_CONN + if "db_txn_limit" in kwargs: database_config["txn_limit"] = kwargs["db_txn_limit"] @@ -983,7 +1006,9 @@ def cleanup() -> None: dropped = True except psycopg2.OperationalError as e: warnings.warn( - "Couldn't drop old db: " + str(e), category=UserWarning + "Couldn't drop old db: " + str(e), + category=UserWarning, + stacklevel=2, ) time.sleep(0.5) @@ -991,7 +1016,11 @@ def cleanup() -> None: db_conn.close() if not dropped: - warnings.warn("Failed to drop old DB.", category=UserWarning) + warnings.warn( + "Failed to drop old DB.", + category=UserWarning, + stacklevel=2, + ) if not LEAVE_DB: # Register the cleanup hook diff --git a/matrix_synapse_testutils/unittest.py b/matrix_synapse_testutils/unittest.py index 421d7a8..baf5ce0 100644 --- a/matrix_synapse_testutils/unittest.py +++ b/matrix_synapse_testutils/unittest.py @@ -146,6 +146,9 @@ def setUp(orig: Callable[[], R]) -> R: % (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 @@ def tearDown(orig: Callable[[], R]) -> R: 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 diff --git a/pyproject.toml b/pyproject.toml index 215dccc..f8f7707 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -16,7 +16,7 @@ classifiers = [ "Topic :: Software Development" ] dependencies = [ - "matrix-synapse[test]==1.80.0" + "matrix-synapse[test]==1.81.0" ] [project.urls]