mirror of
https://mau.dev/maunium/synapse.git
synced 2024-10-01 01:36:05 -04:00
Create dbpool as normal in tests
... instead of creating our own special SQLiteMemoryDbPool, whose purpose was a bit of a mystery. For some reason this makes one of the tests run slightly slower, so bump the sleep(). Sorry.
This commit is contained in:
parent
b178eca261
commit
d7eacc4f87
@ -167,7 +167,7 @@ class KeyringTestCase(unittest.TestCase):
|
|||||||
|
|
||||||
# wait a tick for it to send the request to the perspectives server
|
# wait a tick for it to send the request to the perspectives server
|
||||||
# (it first tries the datastore)
|
# (it first tries the datastore)
|
||||||
yield async.sleep(0.005)
|
yield async.sleep(1) # XXX find out why this takes so long!
|
||||||
self.http_client.post_json.assert_called_once()
|
self.http_client.post_json.assert_called_once()
|
||||||
|
|
||||||
self.assertIs(LoggingContext.current_context(), context_11)
|
self.assertIs(LoggingContext.current_context(), context_11)
|
||||||
@ -183,7 +183,7 @@ class KeyringTestCase(unittest.TestCase):
|
|||||||
res_deferreds_2 = kr.verify_json_objects_for_server(
|
res_deferreds_2 = kr.verify_json_objects_for_server(
|
||||||
[("server10", json1)],
|
[("server10", json1)],
|
||||||
)
|
)
|
||||||
yield async.sleep(0.005)
|
yield async.sleep(01)
|
||||||
self.http_client.post_json.assert_not_called()
|
self.http_client.post_json.assert_not_called()
|
||||||
res_deferreds_2[0].addBoth(self.check_context, None)
|
res_deferreds_2[0].addBoth(self.check_context, None)
|
||||||
|
|
||||||
|
@ -19,7 +19,6 @@ import urllib
|
|||||||
import urlparse
|
import urlparse
|
||||||
|
|
||||||
from mock import Mock, patch
|
from mock import Mock, patch
|
||||||
from twisted.enterprise.adbapi import ConnectionPool
|
|
||||||
from twisted.internet import defer, reactor
|
from twisted.internet import defer, reactor
|
||||||
|
|
||||||
from synapse.api.errors import CodeMessageException, cs_error
|
from synapse.api.errors import CodeMessageException, cs_error
|
||||||
@ -60,30 +59,37 @@ def setup_test_homeserver(name="test", datastore=None, config=None, **kargs):
|
|||||||
config.update_user_directory = False
|
config.update_user_directory = False
|
||||||
|
|
||||||
config.use_frozen_dicts = True
|
config.use_frozen_dicts = True
|
||||||
config.database_config = {"name": "sqlite3"}
|
|
||||||
config.ldap_enabled = False
|
config.ldap_enabled = False
|
||||||
|
|
||||||
if "clock" not in kargs:
|
if "clock" not in kargs:
|
||||||
kargs["clock"] = MockClock()
|
kargs["clock"] = MockClock()
|
||||||
|
|
||||||
|
config.database_config = {
|
||||||
|
"name": "sqlite3",
|
||||||
|
"args": {
|
||||||
|
"database": ":memory:",
|
||||||
|
"cp_min": 1,
|
||||||
|
"cp_max": 1,
|
||||||
|
},
|
||||||
|
}
|
||||||
db_engine = create_engine(config.database_config)
|
db_engine = create_engine(config.database_config)
|
||||||
|
|
||||||
|
# we need to configure the connection pool to run the on_new_connection
|
||||||
|
# function, so that we can test code that uses custom sqlite functions
|
||||||
|
# (like rank).
|
||||||
|
config.database_config["args"]["cp_openfun"] = db_engine.on_new_connection
|
||||||
|
|
||||||
if datastore is None:
|
if datastore is None:
|
||||||
# we need to configure the connection pool to run the on_new_connection
|
|
||||||
# function, so that we can test code that uses custom sqlite functions
|
|
||||||
# (like rank).
|
|
||||||
db_pool = SQLiteMemoryDbPool(
|
|
||||||
cp_openfun=db_engine.on_new_connection,
|
|
||||||
)
|
|
||||||
yield db_pool.prepare()
|
|
||||||
hs = HomeServer(
|
hs = HomeServer(
|
||||||
name, db_pool=db_pool, config=config,
|
name, config=config,
|
||||||
|
db_config=config.database_config,
|
||||||
version_string="Synapse/tests",
|
version_string="Synapse/tests",
|
||||||
database_engine=db_engine,
|
database_engine=db_engine,
|
||||||
get_db_conn=db_pool.get_db_conn,
|
|
||||||
room_list_handler=object(),
|
room_list_handler=object(),
|
||||||
tls_server_context_factory=Mock(),
|
tls_server_context_factory=Mock(),
|
||||||
**kargs
|
**kargs
|
||||||
)
|
)
|
||||||
|
yield prepare_database(hs.get_db_conn(), db_engine, config)
|
||||||
hs.setup()
|
hs.setup()
|
||||||
else:
|
else:
|
||||||
hs = HomeServer(
|
hs = HomeServer(
|
||||||
@ -308,38 +314,6 @@ class MockClock(object):
|
|||||||
return d
|
return d
|
||||||
|
|
||||||
|
|
||||||
class SQLiteMemoryDbPool(ConnectionPool, object):
|
|
||||||
def __init__(self, **kwargs):
|
|
||||||
connkw = {
|
|
||||||
"cp_min": 1,
|
|
||||||
"cp_max": 1,
|
|
||||||
}
|
|
||||||
connkw.update(kwargs)
|
|
||||||
|
|
||||||
super(SQLiteMemoryDbPool, self).__init__(
|
|
||||||
"sqlite3", ":memory:", **connkw
|
|
||||||
)
|
|
||||||
|
|
||||||
self.config = Mock()
|
|
||||||
self.config.password_providers = []
|
|
||||||
self.config.database_config = {"name": "sqlite3"}
|
|
||||||
|
|
||||||
def prepare(self):
|
|
||||||
engine = self.create_engine()
|
|
||||||
return self.runWithConnection(
|
|
||||||
lambda conn: prepare_database(conn, engine, self.config)
|
|
||||||
)
|
|
||||||
|
|
||||||
def get_db_conn(self):
|
|
||||||
conn = self.connect()
|
|
||||||
engine = self.create_engine()
|
|
||||||
prepare_database(conn, engine, self.config)
|
|
||||||
return conn
|
|
||||||
|
|
||||||
def create_engine(self):
|
|
||||||
return create_engine(self.config.database_config)
|
|
||||||
|
|
||||||
|
|
||||||
def _format_call(args, kwargs):
|
def _format_call(args, kwargs):
|
||||||
return ", ".join(
|
return ", ".join(
|
||||||
["%r" % (a) for a in args] +
|
["%r" % (a) for a in args] +
|
||||||
|
Loading…
Reference in New Issue
Block a user