Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
synapse
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Monitor
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Maunium
synapse
Commits
88b9c5cb
Commit
88b9c5cb
authored
7 years ago
by
Richard van der Hoff
Browse files
Options
Downloads
Patches
Plain Diff
Make it possible to run tests against postgres
parent
d7eacc4f
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/utils.py
+34
-9
34 additions, 9 deletions
tests/utils.py
with
34 additions
and
9 deletions
tests/utils.py
+
34
−
9
View file @
88b9c5cb
...
@@ -25,11 +25,17 @@ from synapse.api.errors import CodeMessageException, cs_error
...
@@ -25,11 +25,17 @@ from synapse.api.errors import CodeMessageException, cs_error
from
synapse.federation.transport
import
server
from
synapse.federation.transport
import
server
from
synapse.http.server
import
HttpServer
from
synapse.http.server
import
HttpServer
from
synapse.server
import
HomeServer
from
synapse.server
import
HomeServer
from
synapse.storage
import
PostgresEngine
from
synapse.storage.engines
import
create_engine
from
synapse.storage.engines
import
create_engine
from
synapse.storage.prepare_database
import
prepare_database
from
synapse.storage.prepare_database
import
prepare_database
from
synapse.util.logcontext
import
LoggingContext
from
synapse.util.logcontext
import
LoggingContext
from
synapse.util.ratelimitutils
import
FederationRateLimiter
from
synapse.util.ratelimitutils
import
FederationRateLimiter
# set this to True to run the tests against postgres instead of sqlite.
# It requires you to have a local postgres database called synapse_test, within
# which ALL TABLES WILL BE DROPPED
USE_POSTGRES_FOR_TESTS
=
False
@defer.inlineCallbacks
@defer.inlineCallbacks
def
setup_test_homeserver
(
name
=
"
test
"
,
datastore
=
None
,
config
=
None
,
**
kargs
):
def
setup_test_homeserver
(
name
=
"
test
"
,
datastore
=
None
,
config
=
None
,
**
kargs
):
...
@@ -64,14 +70,25 @@ def setup_test_homeserver(name="test", datastore=None, config=None, **kargs):
...
@@ -64,14 +70,25 @@ def setup_test_homeserver(name="test", datastore=None, config=None, **kargs):
if
"
clock
"
not
in
kargs
:
if
"
clock
"
not
in
kargs
:
kargs
[
"
clock
"
]
=
MockClock
()
kargs
[
"
clock
"
]
=
MockClock
()
config
.
database_config
=
{
if
USE_POSTGRES_FOR_TESTS
:
"
name
"
:
"
sqlite3
"
,
config
.
database_config
=
{
"
args
"
:
{
"
name
"
:
"
psycopg2
"
,
"
database
"
:
"
:memory:
"
,
"
args
"
:
{
"
cp_min
"
:
1
,
"
database
"
:
"
synapse_test
"
,
"
cp_max
"
:
1
,
"
cp_min
"
:
1
,
},
"
cp_max
"
:
5
,
}
},
}
else
:
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
# we need to configure the connection pool to run the on_new_connection
...
@@ -89,7 +106,15 @@ def setup_test_homeserver(name="test", datastore=None, config=None, **kargs):
...
@@ -89,7 +106,15 @@ def setup_test_homeserver(name="test", datastore=None, config=None, **kargs):
tls_server_context_factory
=
Mock
(),
tls_server_context_factory
=
Mock
(),
**
kargs
**
kargs
)
)
yield
prepare_database
(
hs
.
get_db_conn
(),
db_engine
,
config
)
db_conn
=
hs
.
get_db_conn
()
# make sure that the database is empty
if
isinstance
(
db_engine
,
PostgresEngine
):
cur
=
db_conn
.
cursor
()
cur
.
execute
(
"
SELECT tablename FROM pg_tables where schemaname=
'
public
'"
)
rows
=
cur
.
fetchall
()
for
r
in
rows
:
cur
.
execute
(
"
DROP TABLE %s CASCADE
"
%
r
[
0
])
yield
prepare_database
(
db_conn
,
db_engine
,
config
)
hs
.
setup
()
hs
.
setup
()
else
:
else
:
hs
=
HomeServer
(
hs
=
HomeServer
(
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment