summary refs log tree commit diff
diff options
context:
space:
mode:
authorMark Haines <mjark@negativecurvature.net>2016-04-06 16:52:39 +0100
committerMark Haines <mjark@negativecurvature.net>2016-04-06 16:52:39 +0100
commit8d2bca1a90bc737c1a51d1a78d0e6c5d77589cea (patch)
treeb5f0d0df4d80e5f826a3577f0bb8cda3b3df5bd8
parentMerge pull request #697 from matrix-org/markjh/slaveI (diff)
parentTest that room membership is replicated (diff)
downloadsynapse-8d2bca1a90bc737c1a51d1a78d0e6c5d77589cea.tar.xz
Merge pull request #702 from matrix-org/markjh/slaveII
Test that room membership is replicated
Diffstat (limited to '')
-rw-r--r--synapse/replication/slave/storage/events.py7
-rw-r--r--tests/replication/slave/storage/test_events.py71
2 files changed, 67 insertions, 11 deletions
diff --git a/synapse/replication/slave/storage/events.py b/synapse/replication/slave/storage/events.py
index 68b924e37b..680dc89536 100644
--- a/synapse/replication/slave/storage/events.py
+++ b/synapse/replication/slave/storage/events.py
@@ -71,9 +71,6 @@ class SlavedEventStore(BaseSlavedStore):
 
     get_current_state = DataStore.get_current_state.__func__
     get_current_state_for_key = DataStore.get_current_state_for_key.__func__
-    _get_rooms_for_user_where_membership_is_txn = (
-        DataStore._get_rooms_for_user_where_membership_is_txn.__func__
-    )
     get_rooms_for_user_where_membership_is = (
         DataStore.get_rooms_for_user_where_membership_is.__func__
     )
@@ -95,6 +92,10 @@ class SlavedEventStore(BaseSlavedStore):
     _fetch_events_txn = DataStore._fetch_events_txn.__func__
     _fetch_event_rows = DataStore._fetch_event_rows.__func__
     _get_event_from_row_txn = DataStore._get_event_from_row_txn.__func__
+    _get_rooms_for_user_where_membership_is_txn = (
+        DataStore._get_rooms_for_user_where_membership_is_txn.__func__
+    )
+    _get_members_rows_txn = DataStore._get_members_rows_txn.__func__
 
     def stream_positions(self):
         result = super(SlavedEventStore, self).stream_positions()
diff --git a/tests/replication/slave/storage/test_events.py b/tests/replication/slave/storage/test_events.py
index c30c7c6063..351d777fb2 100644
--- a/tests/replication/slave/storage/test_events.py
+++ b/tests/replication/slave/storage/test_events.py
@@ -14,14 +14,14 @@
 
 from ._base import BaseSlavedStoreTestCase
 
-from synapse.types import UserID
 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 = UserID.from_string(USER_ID)
+USER_ID_2 = "@bright:blue"
 OUTLIER = {"outlier": True}
 ROOM_ID = "!room:blue"
 
@@ -69,16 +69,66 @@ class SlavedEventStoreTestCase(BaseSlavedStoreTestCase):
             "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
+        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
 
@@ -103,12 +153,17 @@ class SlavedEventStoreTestCase(BaseSlavedStoreTestCase):
 
         context = EventContext(current_state=state)
 
+        ordering = None
         if backfill:
             yield self.master_store.persist_events(
                 [(event, context)], backfilled=True
             )
         else:
-            yield self.master_store.persist_event(
+            ordering, _ = yield self.master_store.persist_event(
                 event, context, current_state=reset_state
             )
+
+        if ordering:
+            event.internal_metadata.stream_ordering = ordering
+
         defer.returnValue(event)