mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2024-09-08 01:31:54 +00:00
Clean-up some broken/unused code in the test framework (#8514)
This commit is contained in:
parent
9789b1fba5
commit
d35a451399
1
changelog.d/8514.misc
Normal file
1
changelog.d/8514.misc
Normal file
@ -0,0 +1 @@
|
|||||||
|
Remove unused code from the test framework.
|
@ -367,8 +367,6 @@ def setup_test_homeserver(cleanup_func, *args, **kwargs):
|
|||||||
"""
|
"""
|
||||||
server = _sth(cleanup_func, *args, **kwargs)
|
server = _sth(cleanup_func, *args, **kwargs)
|
||||||
|
|
||||||
database = server.config.database.get_single_database()
|
|
||||||
|
|
||||||
# Make the thread pool synchronous.
|
# Make the thread pool synchronous.
|
||||||
clock = server.get_clock()
|
clock = server.get_clock()
|
||||||
|
|
||||||
|
116
tests/utils.py
116
tests/utils.py
@ -192,7 +192,6 @@ class TestHomeServer(HomeServer):
|
|||||||
def setup_test_homeserver(
|
def setup_test_homeserver(
|
||||||
cleanup_func,
|
cleanup_func,
|
||||||
name="test",
|
name="test",
|
||||||
datastore=None,
|
|
||||||
config=None,
|
config=None,
|
||||||
reactor=None,
|
reactor=None,
|
||||||
homeserverToUse=TestHomeServer,
|
homeserverToUse=TestHomeServer,
|
||||||
@ -249,7 +248,7 @@ def setup_test_homeserver(
|
|||||||
|
|
||||||
# Create the database before we actually try and connect to it, based off
|
# Create the database before we actually try and connect to it, based off
|
||||||
# the template database we generate in setupdb()
|
# the template database we generate in setupdb()
|
||||||
if datastore is None and isinstance(db_engine, PostgresEngine):
|
if isinstance(db_engine, PostgresEngine):
|
||||||
db_conn = db_engine.module.connect(
|
db_conn = db_engine.module.connect(
|
||||||
database=POSTGRES_BASE_DB,
|
database=POSTGRES_BASE_DB,
|
||||||
user=POSTGRES_USER,
|
user=POSTGRES_USER,
|
||||||
@ -265,79 +264,66 @@ def setup_test_homeserver(
|
|||||||
cur.close()
|
cur.close()
|
||||||
db_conn.close()
|
db_conn.close()
|
||||||
|
|
||||||
if datastore is None:
|
hs = homeserverToUse(
|
||||||
hs = homeserverToUse(
|
name,
|
||||||
name,
|
config=config,
|
||||||
config=config,
|
version_string="Synapse/tests",
|
||||||
version_string="Synapse/tests",
|
tls_server_context_factory=Mock(),
|
||||||
tls_server_context_factory=Mock(),
|
tls_client_options_factory=Mock(),
|
||||||
tls_client_options_factory=Mock(),
|
reactor=reactor,
|
||||||
reactor=reactor,
|
**kargs
|
||||||
**kargs
|
)
|
||||||
)
|
|
||||||
|
|
||||||
hs.setup()
|
hs.setup()
|
||||||
if homeserverToUse.__name__ == "TestHomeServer":
|
if homeserverToUse.__name__ == "TestHomeServer":
|
||||||
hs.setup_background_tasks()
|
hs.setup_background_tasks()
|
||||||
|
|
||||||
if isinstance(db_engine, PostgresEngine):
|
if isinstance(db_engine, PostgresEngine):
|
||||||
database = hs.get_datastores().databases[0]
|
database = hs.get_datastores().databases[0]
|
||||||
|
|
||||||
# We need to do cleanup on PostgreSQL
|
# We need to do cleanup on PostgreSQL
|
||||||
def cleanup():
|
def cleanup():
|
||||||
import psycopg2
|
import psycopg2
|
||||||
|
|
||||||
# Close all the db pools
|
# Close all the db pools
|
||||||
database._db_pool.close()
|
database._db_pool.close()
|
||||||
|
|
||||||
dropped = False
|
dropped = False
|
||||||
|
|
||||||
# Drop the test database
|
# Drop the test database
|
||||||
db_conn = db_engine.module.connect(
|
db_conn = db_engine.module.connect(
|
||||||
database=POSTGRES_BASE_DB,
|
database=POSTGRES_BASE_DB,
|
||||||
user=POSTGRES_USER,
|
user=POSTGRES_USER,
|
||||||
host=POSTGRES_HOST,
|
host=POSTGRES_HOST,
|
||||||
password=POSTGRES_PASSWORD,
|
password=POSTGRES_PASSWORD,
|
||||||
)
|
)
|
||||||
db_conn.autocommit = True
|
db_conn.autocommit = True
|
||||||
cur = db_conn.cursor()
|
cur = db_conn.cursor()
|
||||||
|
|
||||||
# Try a few times to drop the DB. Some things may hold on to the
|
# Try a few times to drop the DB. Some things may hold on to the
|
||||||
# database for a few more seconds due to flakiness, preventing
|
# database for a few more seconds due to flakiness, preventing
|
||||||
# us from dropping it when the test is over. If we can't drop
|
# us from dropping it when the test is over. If we can't drop
|
||||||
# it, warn and move on.
|
# it, warn and move on.
|
||||||
for x in range(5):
|
for x in range(5):
|
||||||
try:
|
try:
|
||||||
cur.execute("DROP DATABASE IF EXISTS %s;" % (test_db,))
|
cur.execute("DROP DATABASE IF EXISTS %s;" % (test_db,))
|
||||||
db_conn.commit()
|
db_conn.commit()
|
||||||
dropped = True
|
dropped = True
|
||||||
except psycopg2.OperationalError as e:
|
except psycopg2.OperationalError as e:
|
||||||
warnings.warn(
|
warnings.warn(
|
||||||
"Couldn't drop old db: " + str(e), category=UserWarning
|
"Couldn't drop old db: " + str(e), category=UserWarning
|
||||||
)
|
)
|
||||||
time.sleep(0.5)
|
time.sleep(0.5)
|
||||||
|
|
||||||
cur.close()
|
cur.close()
|
||||||
db_conn.close()
|
db_conn.close()
|
||||||
|
|
||||||
if not dropped:
|
if not dropped:
|
||||||
warnings.warn("Failed to drop old DB.", category=UserWarning)
|
warnings.warn("Failed to drop old DB.", category=UserWarning)
|
||||||
|
|
||||||
if not LEAVE_DB:
|
if not LEAVE_DB:
|
||||||
# Register the cleanup hook
|
# Register the cleanup hook
|
||||||
cleanup_func(cleanup)
|
cleanup_func(cleanup)
|
||||||
|
|
||||||
else:
|
|
||||||
hs = homeserverToUse(
|
|
||||||
name,
|
|
||||||
datastore=datastore,
|
|
||||||
config=config,
|
|
||||||
version_string="Synapse/tests",
|
|
||||||
tls_server_context_factory=Mock(),
|
|
||||||
tls_client_options_factory=Mock(),
|
|
||||||
reactor=reactor,
|
|
||||||
**kargs
|
|
||||||
)
|
|
||||||
|
|
||||||
# bcrypt is far too slow to be doing in unit tests
|
# bcrypt is far too slow to be doing in unit tests
|
||||||
# Need to let the HS build an auth handler and then mess with it
|
# Need to let the HS build an auth handler and then mess with it
|
||||||
|
Loading…
Reference in New Issue
Block a user