mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-11-13 09:00:44 -05:00
Merge branch 'develop' of github.com:matrix-org/synapse into erikj/dns_cache
This commit is contained in:
commit
a28d066732
60 changed files with 2286 additions and 1242 deletions
14
tests/replication/slave/__init__.py
Normal file
14
tests/replication/slave/__init__.py
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2016 OpenMarket Ltd
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
14
tests/replication/slave/storage/__init__.py
Normal file
14
tests/replication/slave/storage/__init__.py
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2016 OpenMarket Ltd
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
57
tests/replication/slave/storage/_base.py
Normal file
57
tests/replication/slave/storage/_base.py
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
# Copyright 2016 OpenMarket Ltd
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from twisted.internet import defer
|
||||
from tests import unittest
|
||||
|
||||
from synapse.replication.slave.storage.events import SlavedEventStore
|
||||
|
||||
from mock import Mock, NonCallableMock
|
||||
from tests.utils import setup_test_homeserver
|
||||
from synapse.replication.resource import ReplicationResource
|
||||
|
||||
|
||||
class BaseSlavedStoreTestCase(unittest.TestCase):
|
||||
@defer.inlineCallbacks
|
||||
def setUp(self):
|
||||
self.hs = yield setup_test_homeserver(
|
||||
"blue",
|
||||
http_client=None,
|
||||
replication_layer=Mock(),
|
||||
ratelimiter=NonCallableMock(spec_set=[
|
||||
"send_message",
|
||||
]),
|
||||
)
|
||||
self.hs.get_ratelimiter().send_message.return_value = (True, 0)
|
||||
|
||||
self.replication = ReplicationResource(self.hs)
|
||||
|
||||
self.master_store = self.hs.get_datastore()
|
||||
self.slaved_store = SlavedEventStore(self.hs.get_db_conn(), self.hs)
|
||||
self.event_id = 0
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def replicate(self):
|
||||
streams = self.slaved_store.stream_positions()
|
||||
result = yield self.replication.replicate(streams, 100)
|
||||
yield self.slaved_store.process_replication(result)
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def check(self, method, args, expected_result=None):
|
||||
master_result = yield getattr(self.master_store, method)(*args)
|
||||
slaved_result = yield getattr(self.slaved_store, method)(*args)
|
||||
self.assertEqual(master_result, slaved_result)
|
||||
if expected_result is not None:
|
||||
self.assertEqual(master_result, expected_result)
|
||||
self.assertEqual(slaved_result, expected_result)
|
||||
169
tests/replication/slave/storage/test_events.py
Normal file
169
tests/replication/slave/storage/test_events.py
Normal file
|
|
@ -0,0 +1,169 @@
|
|||
# Copyright 2016 OpenMarket Ltd
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from ._base import BaseSlavedStoreTestCase
|
||||
|
||||
from synapse.events import FrozenEvent
|
||||
from synapse.events.snapshot import EventContext
|
||||
from synapse.storage.roommember import RoomsForUser
|
||||
|
||||
from twisted.internet import defer
|
||||
|
||||
USER_ID = "@feeling:blue"
|
||||
USER_ID_2 = "@bright:blue"
|
||||
OUTLIER = {"outlier": True}
|
||||
ROOM_ID = "!room:blue"
|
||||
|
||||
|
||||
class SlavedEventStoreTestCase(BaseSlavedStoreTestCase):
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def test_room_name_and_aliases(self):
|
||||
create = yield self.persist(type="m.room.create", key="", creator=USER_ID)
|
||||
yield self.persist(type="m.room.member", key=USER_ID, membership="join")
|
||||
yield self.persist(type="m.room.name", key="", name="name1")
|
||||
yield self.persist(
|
||||
type="m.room.aliases", key="blue", aliases=["#1:blue"]
|
||||
)
|
||||
yield self.replicate()
|
||||
yield self.check(
|
||||
"get_room_name_and_aliases", (ROOM_ID,), ("name1", ["#1:blue"])
|
||||
)
|
||||
|
||||
# Set the room name.
|
||||
yield self.persist(type="m.room.name", key="", name="name2")
|
||||
yield self.replicate()
|
||||
yield self.check(
|
||||
"get_room_name_and_aliases", (ROOM_ID,), ("name2", ["#1:blue"])
|
||||
)
|
||||
|
||||
# Set the room aliases.
|
||||
yield self.persist(
|
||||
type="m.room.aliases", key="blue", aliases=["#2:blue"]
|
||||
)
|
||||
yield self.replicate()
|
||||
yield self.check(
|
||||
"get_room_name_and_aliases", (ROOM_ID,), ("name2", ["#2:blue"])
|
||||
)
|
||||
|
||||
# Leave and join the room clobbering the state.
|
||||
yield self.persist(type="m.room.member", key=USER_ID, membership="leave")
|
||||
yield self.persist(
|
||||
type="m.room.member", key=USER_ID, membership="join",
|
||||
reset_state=[create]
|
||||
)
|
||||
yield self.replicate()
|
||||
|
||||
yield self.check(
|
||||
"get_room_name_and_aliases", (ROOM_ID,), (None, [])
|
||||
)
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def test_room_members(self):
|
||||
create = yield self.persist(type="m.room.create", key="", creator=USER_ID)
|
||||
yield self.replicate()
|
||||
yield self.check("get_rooms_for_user", (USER_ID,), [])
|
||||
yield self.check("get_users_in_room", (ROOM_ID,), [])
|
||||
|
||||
# Join the room.
|
||||
join = yield self.persist(type="m.room.member", key=USER_ID, membership="join")
|
||||
yield self.replicate()
|
||||
yield self.check("get_rooms_for_user", (USER_ID,), [RoomsForUser(
|
||||
room_id=ROOM_ID,
|
||||
sender=USER_ID,
|
||||
membership="join",
|
||||
event_id=join.event_id,
|
||||
stream_ordering=join.internal_metadata.stream_ordering,
|
||||
)])
|
||||
yield self.check("get_users_in_room", (ROOM_ID,), [USER_ID])
|
||||
|
||||
# Leave the room.
|
||||
yield self.persist(type="m.room.member", key=USER_ID, membership="leave")
|
||||
yield self.replicate()
|
||||
yield self.check("get_rooms_for_user", (USER_ID,), [])
|
||||
yield self.check("get_users_in_room", (ROOM_ID,), [])
|
||||
|
||||
# Add some other user to the room.
|
||||
join = yield self.persist(type="m.room.member", key=USER_ID_2, membership="join")
|
||||
yield self.replicate()
|
||||
yield self.check("get_rooms_for_user", (USER_ID_2,), [RoomsForUser(
|
||||
room_id=ROOM_ID,
|
||||
sender=USER_ID,
|
||||
membership="join",
|
||||
event_id=join.event_id,
|
||||
stream_ordering=join.internal_metadata.stream_ordering,
|
||||
)])
|
||||
yield self.check("get_users_in_room", (ROOM_ID,), [USER_ID_2])
|
||||
|
||||
# Join the room clobbering the state.
|
||||
# This should remove any evidence of the other user being in the room.
|
||||
yield self.persist(
|
||||
type="m.room.member", key=USER_ID, membership="join",
|
||||
reset_state=[create]
|
||||
)
|
||||
yield self.replicate()
|
||||
yield self.check("get_users_in_room", (ROOM_ID,), [USER_ID])
|
||||
yield self.check("get_rooms_for_user", (USER_ID_2,), [])
|
||||
|
||||
event_id = 0
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def persist(
|
||||
self, sender=USER_ID, room_id=ROOM_ID, type={}, key=None, internal={},
|
||||
state=None, reset_state=False, backfill=False,
|
||||
depth=None, prev_events=[], auth_events=[], prev_state=[],
|
||||
**content
|
||||
):
|
||||
"""
|
||||
Returns:
|
||||
synapse.events.FrozenEvent: The event that was persisted.
|
||||
"""
|
||||
if depth is None:
|
||||
depth = self.event_id
|
||||
|
||||
event_dict = {
|
||||
"sender": sender,
|
||||
"type": type,
|
||||
"content": content,
|
||||
"event_id": "$%d:blue" % (self.event_id,),
|
||||
"room_id": room_id,
|
||||
"depth": depth,
|
||||
"origin_server_ts": self.event_id,
|
||||
"prev_events": prev_events,
|
||||
"auth_events": auth_events,
|
||||
}
|
||||
if key is not None:
|
||||
event_dict["state_key"] = key
|
||||
event_dict["prev_state"] = prev_state
|
||||
|
||||
event = FrozenEvent(event_dict, internal_metadata_dict=internal)
|
||||
|
||||
self.event_id += 1
|
||||
|
||||
context = EventContext(current_state=state)
|
||||
|
||||
ordering = None
|
||||
if backfill:
|
||||
yield self.master_store.persist_events(
|
||||
[(event, context)], backfilled=True
|
||||
)
|
||||
else:
|
||||
ordering, _ = yield self.master_store.persist_event(
|
||||
event, context, current_state=reset_state
|
||||
)
|
||||
|
||||
if ordering:
|
||||
event.internal_metadata.stream_ordering = ordering
|
||||
|
||||
defer.returnValue(event)
|
||||
|
|
@ -259,8 +259,8 @@ class RoomPermissionsTestCase(RestTestCase):
|
|||
# set [invite/join/left] of self, set [invite/join/left] of other,
|
||||
# expect all 404s because room doesn't exist on any server
|
||||
for usr in [self.user_id, self.rmcreator_id]:
|
||||
yield self.join(room=room, user=usr, expect_code=404)
|
||||
yield self.leave(room=room, user=usr, expect_code=404)
|
||||
yield self.join(room=room, user=usr, expect_code=403)
|
||||
yield self.leave(room=room, user=usr, expect_code=403)
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def test_membership_private_room_perms(self):
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ class SQLBaseStoreTestCase(unittest.TestCase):
|
|||
"test",
|
||||
db_pool=self.db_pool,
|
||||
config=config,
|
||||
database_engine=create_engine(config),
|
||||
database_engine=create_engine(config.database_config),
|
||||
)
|
||||
|
||||
self.datastore = SQLBaseStore(hs)
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ def setup_test_homeserver(name="test", datastore=None, config=None, **kargs):
|
|||
hs = HomeServer(
|
||||
name, db_pool=db_pool, config=config,
|
||||
version_string="Synapse/tests",
|
||||
database_engine=create_engine(config),
|
||||
database_engine=create_engine(config.database_config),
|
||||
get_db_conn=db_pool.get_db_conn,
|
||||
**kargs
|
||||
)
|
||||
|
|
@ -73,7 +73,7 @@ def setup_test_homeserver(name="test", datastore=None, config=None, **kargs):
|
|||
hs = HomeServer(
|
||||
name, db_pool=None, datastore=datastore, config=config,
|
||||
version_string="Synapse/tests",
|
||||
database_engine=create_engine(config),
|
||||
database_engine=create_engine(config.database_config),
|
||||
**kargs
|
||||
)
|
||||
|
||||
|
|
@ -298,7 +298,7 @@ class SQLiteMemoryDbPool(ConnectionPool, object):
|
|||
return conn
|
||||
|
||||
def create_engine(self):
|
||||
return create_engine(self.config)
|
||||
return create_engine(self.config.database_config)
|
||||
|
||||
|
||||
class MemoryDataStore(object):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue