From 02ebb9f0c3ab56bc8e9f19721e6189e9486252a3 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Tue, 11 Nov 2014 14:16:48 +0000 Subject: Fix state tests --- tests/test_state.py | 693 +++++++++++++--------------------------------------- 1 file changed, 176 insertions(+), 517 deletions(-) (limited to 'tests/test_state.py') diff --git a/tests/test_state.py b/tests/test_state.py index 4b1feaf410..3cc358be32 100644 --- a/tests/test_state.py +++ b/tests/test_state.py @@ -15,599 +15,258 @@ from tests import unittest from twisted.internet import defer -from twisted.python.log import PythonLoggingObserver from synapse.state import StateHandler -from synapse.storage.pdu import PduEntry -from synapse.federation.pdu_codec import encode_event_id -from synapse.federation.units import Pdu - -from collections import namedtuple from mock import Mock -import mock - - -ReturnType = namedtuple( - "StateReturnType", ["new_branch", "current_branch"] -) - - -def _gen_get_power_level(power_level_list): - def get_power_level(room_id, user_id): - return defer.succeed(power_level_list.get(user_id, None)) - return get_power_level class StateTestCase(unittest.TestCase): def setUp(self): - self.persistence = Mock(spec=[ - "get_unresolved_state_tree", - "update_current_state", - "get_latest_pdus_in_context", - "get_current_state_pdu", - "get_pdu", - "get_power_level", - ]) - self.replication = Mock(spec=["get_pdu"]) - - hs = Mock(spec=["get_datastore", "get_replication_layer"]) - hs.get_datastore.return_value = self.persistence - hs.get_replication_layer.return_value = self.replication - hs.hostname = "bob.com" - - self.state = StateHandler(hs) - - @defer.inlineCallbacks - def test_new_state_key(self): - # We've never seen anything for this state before - new_pdu = new_fake_pdu("A", "test", "mem", "x", None, "u") - - self.persistence.get_power_level.side_effect = _gen_get_power_level({}) - - self.persistence.get_unresolved_state_tree.return_value = ( - (ReturnType([new_pdu], []), None) - ) - - is_new = yield self.state.handle_new_state(new_pdu) - - self.assertTrue(is_new) - - self.persistence.get_unresolved_state_tree.assert_called_once_with( - new_pdu - ) - - self.assertEqual(1, self.persistence.update_current_state.call_count) - - self.assertFalse(self.replication.get_pdu.called) - - @defer.inlineCallbacks - def test_direct_overwrite(self): - # We do a direct overwriting of the old state, i.e., the new state - # points to the old state. - - old_pdu = new_fake_pdu("A", "test", "mem", "x", None, "u1") - new_pdu = new_fake_pdu("B", "test", "mem", "x", "A", "u2") - - self.persistence.get_power_level.side_effect = _gen_get_power_level({ - "u1": 10, - "u2": 5, - }) - - self.persistence.get_unresolved_state_tree.return_value = ( - (ReturnType([new_pdu, old_pdu], [old_pdu]), None) - ) - - is_new = yield self.state.handle_new_state(new_pdu) - - self.assertTrue(is_new) - - self.persistence.get_unresolved_state_tree.assert_called_once_with( - new_pdu + self.store = Mock( + spec_set=[ + "get_state_groups", + ] ) + hs = Mock(spec=["get_datastore"]) + hs.get_datastore.return_value = self.store - self.assertEqual(1, self.persistence.update_current_state.call_count) - - self.assertFalse(self.replication.get_pdu.called) + self.state = StateHandler(hs) + self.event_id = 0 @defer.inlineCallbacks - def test_overwrite(self): - old_pdu_1 = new_fake_pdu("A", "test", "mem", "x", None, "u1") - old_pdu_2 = new_fake_pdu("B", "test", "mem", "x", "A", "u2") - new_pdu = new_fake_pdu("C", "test", "mem", "x", "B", "u3") - - self.persistence.get_power_level.side_effect = _gen_get_power_level({ - "u1": 10, - "u2": 5, - "u3": 0, - }) - - self.persistence.get_unresolved_state_tree.return_value = ( - (ReturnType([new_pdu, old_pdu_2, old_pdu_1], [old_pdu_1]), None) - ) + def test_annotate_with_old_message(self): + event = self.create_event(type="test_message", name="event") - is_new = yield self.state.handle_new_state(new_pdu) + old_state = [ + self.create_event(type="test1", state_key="1"), + self.create_event(type="test1", state_key="2"), + self.create_event(type="test2", state_key=""), + ] - self.assertTrue(is_new) + yield self.state.annotate_state_groups(event, old_state=old_state) - self.persistence.get_unresolved_state_tree.assert_called_once_with( - new_pdu - ) + for k, v in event.old_state_events.items(): + type, state_key = k + self.assertEqual(type, v.type) + self.assertEqual(state_key, v.state_key) - self.assertEqual(1, self.persistence.update_current_state.call_count) + self.assertEqual(set(old_state), set(event.old_state_events.values())) + self.assertDictEqual(event.old_state_events, event.state_events) - self.assertFalse(self.replication.get_pdu.called) + self.assertIsNone(event.state_group) @defer.inlineCallbacks - def test_power_level_fail(self): - # We try to update the state based on an outdated state, and have a - # too low power level. - - old_pdu_1 = new_fake_pdu("A", "test", "mem", "x", None, "u1") - old_pdu_2 = new_fake_pdu("B", "test", "mem", "x", None, "u2") - new_pdu = new_fake_pdu("C", "test", "mem", "x", "A", "u3") - - self.persistence.get_power_level.side_effect = _gen_get_power_level({ - "u1": 10, - "u2": 10, - "u3": 5, - }) - - self.persistence.get_unresolved_state_tree.return_value = ( - (ReturnType([new_pdu, old_pdu_1], [old_pdu_2, old_pdu_1]), None) - ) - - is_new = yield self.state.handle_new_state(new_pdu) - - self.assertFalse(is_new) - - self.persistence.get_unresolved_state_tree.assert_called_once_with( - new_pdu - ) - - self.assertEqual(0, self.persistence.update_current_state.call_count) + def test_annotate_with_old_state(self): + event = self.create_event(type="state", state_key="", name="event") - self.assertFalse(self.replication.get_pdu.called) - - @defer.inlineCallbacks - def test_power_level_succeed(self): - # We try to update the state based on an outdated state, but have - # sufficient power level to force the update. - - old_pdu_1 = new_fake_pdu("A", "test", "mem", "x", None, "u1") - old_pdu_2 = new_fake_pdu("B", "test", "mem", "x", None, "u2") - new_pdu = new_fake_pdu("C", "test", "mem", "x", "A", "u3") - - self.persistence.get_power_level.side_effect = _gen_get_power_level({ - "u1": 10, - "u2": 10, - "u3": 15, - }) - - self.persistence.get_unresolved_state_tree.return_value = ( - (ReturnType([new_pdu, old_pdu_1], [old_pdu_2, old_pdu_1]), None) - ) + old_state = [ + self.create_event(type="test1", state_key="1"), + self.create_event(type="test1", state_key="2"), + self.create_event(type="test2", state_key=""), + ] - is_new = yield self.state.handle_new_state(new_pdu) + yield self.state.annotate_state_groups(event, old_state=old_state) - self.assertTrue(is_new) + for k, v in event.old_state_events.items(): + type, state_key = k + self.assertEqual(type, v.type) + self.assertEqual(state_key, v.state_key) - self.persistence.get_unresolved_state_tree.assert_called_once_with( - new_pdu + self.assertEqual( + set(old_state + [event]), + set(event.old_state_events.values()) ) - self.assertEqual(1, self.persistence.update_current_state.call_count) + self.assertDictEqual(event.old_state_events, event.state_events) - self.assertFalse(self.replication.get_pdu.called) + self.assertIsNone(event.state_group) @defer.inlineCallbacks - def test_power_level_equal_same_len(self): - # We try to update the state based on an outdated state, the power - # levels are the same and so are the branch lengths - - old_pdu_1 = new_fake_pdu("A", "test", "mem", "x", None, "u1") - old_pdu_2 = new_fake_pdu("B", "test", "mem", "x", None, "u2") - new_pdu = new_fake_pdu("C", "test", "mem", "x", "A", "u3") - - self.persistence.get_power_level.side_effect = _gen_get_power_level({ - "u1": 10, - "u2": 10, - "u3": 10, - }) - - self.persistence.get_unresolved_state_tree.return_value = ( - (ReturnType([new_pdu, old_pdu_1], [old_pdu_2, old_pdu_1]), None) - ) - - is_new = yield self.state.handle_new_state(new_pdu) + def test_trivial_annotate_message(self): + event = self.create_event(type="test_message", name="event") + event.prev_events = [] + + old_state = [ + self.create_event(type="test1", state_key="1"), + self.create_event(type="test1", state_key="2"), + self.create_event(type="test2", state_key=""), + ] - self.assertTrue(is_new) + group_name = "group_name_1" - self.persistence.get_unresolved_state_tree.assert_called_once_with( - new_pdu - ) + self.store.get_state_groups.return_value = { + group_name: old_state, + } - self.assertEqual(1, self.persistence.update_current_state.call_count) + yield self.state.annotate_state_groups(event) - self.assertFalse(self.replication.get_pdu.called) + for k, v in event.old_state_events.items(): + type, state_key = k + self.assertEqual(type, v.type) + self.assertEqual(state_key, v.state_key) - @defer.inlineCallbacks - def test_power_level_equal_diff_len(self): - # We try to update the state based on an outdated state, the power - # levels are the same but the branch length of the new one is longer. - - old_pdu_1 = new_fake_pdu("A", "test", "mem", "x", None, "u1") - old_pdu_2 = new_fake_pdu("B", "test", "mem", "x", None, "u2") - old_pdu_3 = new_fake_pdu("C", "test", "mem", "x", "A", "u3") - new_pdu = new_fake_pdu("D", "test", "mem", "x", "C", "u4") - - self.persistence.get_power_level.side_effect = _gen_get_power_level({ - "u1": 10, - "u2": 10, - "u3": 10, - "u4": 10, - }) - - self.persistence.get_unresolved_state_tree.return_value = ( - ( - ReturnType( - [new_pdu, old_pdu_3, old_pdu_1], - [old_pdu_2, old_pdu_1] - ), - None - ) + self.assertEqual( + set([e.event_id for e in old_state]), + set([e.event_id for e in event.old_state_events.values()]) ) - is_new = yield self.state.handle_new_state(new_pdu) - - self.assertTrue(is_new) - - self.persistence.get_unresolved_state_tree.assert_called_once_with( - new_pdu + self.assertDictEqual( + { + k: v.event_id + for k, v in event.old_state_events.items() + }, + { + k: v.event_id + for k, v in event.state_events.items() + } ) - self.assertEqual(1, self.persistence.update_current_state.call_count) - - self.assertFalse(self.replication.get_pdu.called) + self.assertEqual(group_name, event.state_group) @defer.inlineCallbacks - def test_missing_pdu(self): - # We try to update state against a PDU we haven't yet seen, - # triggering a get_pdu request - - # The pdu we haven't seen - old_pdu_1 = new_fake_pdu( - "A", "test", "mem", "x", None, "u1", depth=0 - ) - - old_pdu_2 = new_fake_pdu( - "B", "test", "mem", "x", "A", "u2", depth=1 - ) - new_pdu = new_fake_pdu( - "C", "test", "mem", "x", "A", "u3", depth=2 - ) - - self.persistence.get_power_level.side_effect = _gen_get_power_level({ - "u1": 10, - "u2": 10, - "u3": 20, - }) - - # The return_value of `get_unresolved_state_tree`, which changes after - # the call to get_pdu - tree_to_return = [(ReturnType([new_pdu], [old_pdu_2]), 0)] - - def return_tree(p): - return tree_to_return[0] - - def set_return_tree(destination, pdu_origin, pdu_id, outlier=False): - tree_to_return[0] = ( - ReturnType( - [new_pdu, old_pdu_1], [old_pdu_2, old_pdu_1] - ), - None - ) - return defer.succeed(None) - - self.persistence.get_unresolved_state_tree.side_effect = return_tree + def test_trivial_annotate_state(self): + event = self.create_event(type="state", state_key="", name="event") + event.prev_events = [] + + old_state = [ + self.create_event(type="test1", state_key="1"), + self.create_event(type="test1", state_key="2"), + self.create_event(type="test2", state_key=""), + ] - self.replication.get_pdu.side_effect = set_return_tree + group_name = "group_name_1" - self.persistence.get_pdu.return_value = None + self.store.get_state_groups.return_value = { + group_name: old_state, + } - is_new = yield self.state.handle_new_state(new_pdu) + yield self.state.annotate_state_groups(event) - self.assertTrue(is_new) + for k, v in event.old_state_events.items(): + type, state_key = k + self.assertEqual(type, v.type) + self.assertEqual(state_key, v.state_key) - self.replication.get_pdu.assert_called_with( - destination=new_pdu.origin, - pdu_origin=old_pdu_1.origin, - pdu_id=old_pdu_1.pdu_id, - outlier=True + self.assertEqual( + set([e.event_id for e in old_state]), + set([e.event_id for e in event.old_state_events.values()]) ) - self.persistence.get_unresolved_state_tree.assert_called_with( - new_pdu + self.assertEqual( + set([e.event_id for e in old_state] + [event.event_id]), + set([e.event_id for e in event.state_events.values()]) ) - self.assertEquals( - 2, self.persistence.get_unresolved_state_tree.call_count + new_state = { + k: v.event_id + for k, v in event.state_events.items() + } + old_state = { + k: v.event_id + for k, v in event.old_state_events.items() + } + old_state[(event.type, event.state_key)] = event.event_id + self.assertDictEqual( + old_state, + new_state ) - self.assertEqual(1, self.persistence.update_current_state.call_count) + self.assertIsNone(event.state_group) @defer.inlineCallbacks - def test_missing_pdu_depth_1(self): - # We try to update state against a PDU we haven't yet seen, - # triggering a get_pdu request - - # The pdu we haven't seen - old_pdu_1 = new_fake_pdu( - "A", "test", "mem", "x", None, "u1", depth=0 - ) - - old_pdu_2 = new_fake_pdu( - "B", "test", "mem", "x", "A", "u2", depth=2 - ) - old_pdu_3 = new_fake_pdu( - "C", "test", "mem", "x", "B", "u3", depth=3 - ) - new_pdu = new_fake_pdu( - "D", "test", "mem", "x", "A", "u4", depth=4 - ) - - self.persistence.get_power_level.side_effect = _gen_get_power_level({ - "u1": 10, - "u2": 10, - "u3": 10, - "u4": 20, - }) - - # The return_value of `get_unresolved_state_tree`, which changes after - # the call to get_pdu - tree_to_return = [ - ( - ReturnType([new_pdu], [old_pdu_3]), - 0 - ), - ( - ReturnType( - [new_pdu, old_pdu_1], [old_pdu_3] - ), - 1 - ), - ( - ReturnType( - [new_pdu, old_pdu_1], [old_pdu_3, old_pdu_2, old_pdu_1] - ), - None - ), + def test_resolve_message_conflict(self): + event = self.create_event(type="test_message", name="event") + event.prev_events = [] + + old_state_1 = [ + self.create_event(type="test1", state_key="1"), + self.create_event(type="test1", state_key="2"), + self.create_event(type="test2", state_key=""), ] - to_return = [0] - - def return_tree(p): - return tree_to_return[to_return[0]] - - def set_return_tree(destination, pdu_origin, pdu_id, outlier=False): - to_return[0] += 1 - return defer.succeed(None) - - self.persistence.get_unresolved_state_tree.side_effect = return_tree - - self.replication.get_pdu.side_effect = set_return_tree - - self.persistence.get_pdu.return_value = None - - is_new = yield self.state.handle_new_state(new_pdu) + old_state_2 = [ + self.create_event(type="test1", state_key="1"), + self.create_event(type="test3", state_key="2"), + self.create_event(type="test4", state_key=""), + ] - self.assertTrue(is_new) + group_name_1 = "group_name_1" + group_name_2 = "group_name_2" - self.assertEqual(2, self.replication.get_pdu.call_count) + self.store.get_state_groups.return_value = { + group_name_1: old_state_1, + group_name_2: old_state_2, + } - self.replication.get_pdu.assert_has_calls( - [ - mock.call( - destination=new_pdu.origin, - pdu_origin=old_pdu_1.origin, - pdu_id=old_pdu_1.pdu_id, - outlier=True - ), - mock.call( - destination=old_pdu_3.origin, - pdu_origin=old_pdu_2.origin, - pdu_id=old_pdu_2.pdu_id, - outlier=True - ), - ] - ) + yield self.state.annotate_state_groups(event) - self.persistence.get_unresolved_state_tree.assert_called_with( - new_pdu - ) + self.assertEqual(len(event.old_state_events), 5) - self.assertEquals( - 3, self.persistence.get_unresolved_state_tree.call_count + self.assertEqual( + set([e.event_id for e in event.state_events.values()]), + set([e.event_id for e in event.old_state_events.values()]) ) - self.assertEqual(1, self.persistence.update_current_state.call_count) + self.assertIsNone(event.state_group) @defer.inlineCallbacks - def test_missing_pdu_depth_2(self): - # We try to update state against a PDU we haven't yet seen, - # triggering a get_pdu request - - # The pdu we haven't seen - old_pdu_1 = new_fake_pdu( - "A", "test", "mem", "x", None, "u1", depth=0 - ) - - old_pdu_2 = new_fake_pdu( - "B", "test", "mem", "x", "A", "u2", depth=2 - ) - old_pdu_3 = new_fake_pdu( - "C", "test", "mem", "x", "B", "u3", depth=3 - ) - new_pdu = new_fake_pdu( - "D", "test", "mem", "x", "A", "u4", depth=1 - ) - - self.persistence.get_power_level.side_effect = _gen_get_power_level({ - "u1": 10, - "u2": 10, - "u3": 10, - "u4": 20, - }) - - # The return_value of `get_unresolved_state_tree`, which changes after - # the call to get_pdu - tree_to_return = [ - ( - ReturnType([new_pdu], [old_pdu_3]), - 1, - ), - ( - ReturnType( - [new_pdu], [old_pdu_3, old_pdu_2] - ), - 0, - ), - ( - ReturnType( - [new_pdu, old_pdu_1], [old_pdu_3, old_pdu_2, old_pdu_1] - ), - None - ), + def test_resolve_state_conflict(self): + event = self.create_event(type="test4", state_key="", name="event") + event.prev_events = [] + + old_state_1 = [ + self.create_event(type="test1", state_key="1"), + self.create_event(type="test1", state_key="2"), + self.create_event(type="test2", state_key=""), ] - to_return = [0] - - def return_tree(p): - return tree_to_return[to_return[0]] - - def set_return_tree(destination, pdu_origin, pdu_id, outlier=False): - to_return[0] += 1 - return defer.succeed(None) - - self.persistence.get_unresolved_state_tree.side_effect = return_tree - - self.replication.get_pdu.side_effect = set_return_tree - - self.persistence.get_pdu.return_value = None - - is_new = yield self.state.handle_new_state(new_pdu) - - self.assertTrue(is_new) - - self.assertEqual(2, self.replication.get_pdu.call_count) - - self.replication.get_pdu.assert_has_calls( - [ - mock.call( - destination=old_pdu_3.origin, - pdu_origin=old_pdu_2.origin, - pdu_id=old_pdu_2.pdu_id, - outlier=True - ), - mock.call( - destination=new_pdu.origin, - pdu_origin=old_pdu_1.origin, - pdu_id=old_pdu_1.pdu_id, - outlier=True - ), - ] - ) - - self.persistence.get_unresolved_state_tree.assert_called_with( - new_pdu - ) - - self.assertEquals( - 3, self.persistence.get_unresolved_state_tree.call_count - ) - - self.assertEqual(1, self.persistence.update_current_state.call_count) - - @defer.inlineCallbacks - def test_no_common_ancestor(self): - # We do a direct overwriting of the old state, i.e., the new state - # points to the old state. + old_state_2 = [ + self.create_event(type="test1", state_key="1"), + self.create_event(type="test3", state_key="2"), + self.create_event(type="test4", state_key=""), + ] - old_pdu = new_fake_pdu("A", "test", "mem", "x", None, "u1") - new_pdu = new_fake_pdu("B", "test", "mem", "x", None, "u2") + group_name_1 = "group_name_1" + group_name_2 = "group_name_2" - self.persistence.get_power_level.side_effect = _gen_get_power_level({ - "u1": 5, - "u2": 10, - }) + self.store.get_state_groups.return_value = { + group_name_1: old_state_1, + group_name_2: old_state_2, + } - self.persistence.get_unresolved_state_tree.return_value = ( - (ReturnType([new_pdu], [old_pdu]), None) - ) + yield self.state.annotate_state_groups(event) - is_new = yield self.state.handle_new_state(new_pdu) + self.assertEqual(len(event.old_state_events), 5) - self.assertTrue(is_new) + expected_new = event.old_state_events + expected_new[(event.type, event.state_key)] = event - self.persistence.get_unresolved_state_tree.assert_called_once_with( - new_pdu + self.assertEqual( + set([e.event_id for e in expected_new.values()]), + set([e.event_id for e in event.state_events.values()]), ) - self.assertEqual(1, self.persistence.update_current_state.call_count) - - self.assertFalse(self.replication.get_pdu.called) - - @defer.inlineCallbacks - def test_new_event(self): - event = Mock() - event.event_id = "12123123@test" + self.assertIsNone(event.state_group) - state_pdu = new_fake_pdu("C", "test", "mem", "x", "A", 20) + def create_event(self, name=None, type=None, state_key=None): + self.event_id += 1 + event_id = str(self.event_id) - snapshot = Mock() - snapshot.prev_state_pdu = state_pdu - event_id = "pdu_id@origin.com" + if not name: + if state_key is not None: + name = "<%s-%s>" % (type, state_key) + else: + name = "<%s>" % (type, ) - def fill_out_prev_events(event): - event.prev_events = [event_id] - event.depth = 6 - snapshot.fill_out_prev_events = fill_out_prev_events + event = Mock(name=name, spec=[]) + event.type = type - yield self.state.handle_new_event(event, snapshot) - - self.assertLess(5, event.depth) - - self.assertEquals(1, len(event.prev_events)) - - prev_id = event.prev_events[0] - - self.assertEqual(event_id, prev_id) - - self.assertEqual( - encode_event_id(state_pdu.pdu_id, state_pdu.origin), - event.prev_state - ) + if state_key is not None: + event.state_key = state_key + event.event_id = event_id + event.user_id = "@user_id:example.com" + event.room_id = "!room_id:example.com" -def new_fake_pdu(pdu_id, context, pdu_type, state_key, prev_state_id, - user_id, depth=0): - new_pdu = Pdu( - pdu_id=pdu_id, - pdu_type=pdu_type, - state_key=state_key, - user_id=user_id, - prev_state_id=prev_state_id, - origin="example.com", - context="context", - origin_server_ts=1405353060021, - depth=depth, - content_json="{}", - unrecognized_keys="{}", - outlier=True, - is_state=True, - prev_state_origin="example.com", - have_processed=True, - content={}, - ) - - return new_pdu + return event -- cgit 1.4.1 From 3db2c0d43e6859e522859be271e5d361053f22b4 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Tue, 11 Nov 2014 16:58:53 +0000 Subject: Rename annotate_state_groups to annotate_event_with_state --- synapse/handlers/_base.py | 2 +- synapse/handlers/federation.py | 14 +++++++------- synapse/state.py | 2 +- tests/handlers/test_federation.py | 6 +++--- tests/handlers/test_room.py | 8 ++++---- tests/test_state.py | 12 ++++++------ 6 files changed, 22 insertions(+), 22 deletions(-) (limited to 'tests/test_state.py') diff --git a/synapse/handlers/_base.py b/synapse/handlers/_base.py index 07a8464107..30c6733063 100644 --- a/synapse/handlers/_base.py +++ b/synapse/handlers/_base.py @@ -64,7 +64,7 @@ class BaseHandler(object): snapshot.fill_out_prev_events(event) - yield self.state_handler.annotate_state_groups(event) + yield self.state_handler.annotate_event_with_state(event) yield self.auth.add_auth_events(event) diff --git a/synapse/handlers/federation.py b/synapse/handlers/federation.py index c2cd91bb39..d8d5730b65 100644 --- a/synapse/handlers/federation.py +++ b/synapse/handlers/federation.py @@ -111,7 +111,7 @@ class FederationHandler(BaseHandler): if state: state = [self.pdu_codec.event_from_pdu(p) for p in state] - is_new_state = yield self.state_handler.annotate_state_groups( + is_new_state = yield self.state_handler.annotate_event_with_state( event, old_state=state ) @@ -202,7 +202,7 @@ class FederationHandler(BaseHandler): event = self.pdu_codec.event_from_pdu(pdu) # FIXME (erikj): Not sure this actually works :/ - yield self.state_handler.annotate_state_groups(event) + yield self.state_handler.annotate_event_with_state(event) events.append(event) @@ -268,7 +268,7 @@ class FederationHandler(BaseHandler): logger.debug("do_invite_join state: %s", state) - is_new_state = yield self.state_handler.annotate_state_groups( + is_new_state = yield self.state_handler.annotate_event_with_state( event, old_state=state ) @@ -289,7 +289,7 @@ class FederationHandler(BaseHandler): # FIXME: Auth these. e.outlier = True - yield self.state_handler.annotate_state_groups( + yield self.state_handler.annotate_event_with_state( e, ) @@ -330,7 +330,7 @@ class FederationHandler(BaseHandler): snapshot = yield self.store.snapshot_room(event) snapshot.fill_out_prev_events(event) - yield self.state_handler.annotate_state_groups(event) + yield self.state_handler.annotate_event_with_state(event) yield self.auth.add_auth_events(event) self.auth.check(event, raises=True) @@ -345,7 +345,7 @@ class FederationHandler(BaseHandler): event.outlier = False - is_new_state = yield self.state_handler.annotate_state_groups(event) + is_new_state = yield self.state_handler.annotate_event_with_state(event) self.auth.check(event, raises=True) # FIXME (erikj): All this is duplicated above :( @@ -421,7 +421,7 @@ class FederationHandler(BaseHandler): ) ) - yield self.state_handler.annotate_state_groups(event) + yield self.state_handler.annotate_event_with_state(event) yield self.store.persist_event( event, diff --git a/synapse/state.py b/synapse/state.py index 11c54fd38c..9c22cf7701 100644 --- a/synapse/state.py +++ b/synapse/state.py @@ -45,7 +45,7 @@ class StateHandler(object): @defer.inlineCallbacks @log_function - def annotate_state_groups(self, event, old_state=None): + def annotate_event_with_state(self, event, old_state=None): yield run_on_reactor() if old_state: diff --git a/tests/handlers/test_federation.py b/tests/handlers/test_federation.py index a9d6b2bb17..e386cddb38 100644 --- a/tests/handlers/test_federation.py +++ b/tests/handlers/test_federation.py @@ -36,7 +36,7 @@ class FederationTestCase(unittest.TestCase): self.mock_config.signing_key = [MockKey()] self.state_handler = NonCallableMock(spec_set=[ - "annotate_state_groups", + "annotate_event_with_state", ]) self.auth = NonCallableMock(spec_set=[ @@ -85,7 +85,7 @@ class FederationTestCase(unittest.TestCase): self.datastore.persist_event.return_value = defer.succeed(None) self.datastore.get_room.return_value = defer.succeed(True) - self.state_handler.annotate_state_groups.return_value = ( + self.state_handler.annotate_event_with_state.return_value = ( defer.succeed(False) ) @@ -95,7 +95,7 @@ class FederationTestCase(unittest.TestCase): ANY, False, is_new_state=False ) - self.state_handler.annotate_state_groups.assert_called_once_with( + self.state_handler.annotate_event_with_state.assert_called_once_with( ANY, old_state=None, ) diff --git a/tests/handlers/test_room.py b/tests/handlers/test_room.py index 55c9f6e142..ee264e5ee2 100644 --- a/tests/handlers/test_room.py +++ b/tests/handlers/test_room.py @@ -60,7 +60,7 @@ class RoomMemberHandlerTestCase(unittest.TestCase): ]), auth=NonCallableMock(spec_set=["check", "add_auth_events"]), state_handler=NonCallableMock(spec_set=[ - "annotate_state_groups", + "annotate_event_with_state", ]), config=self.mock_config, ) @@ -251,7 +251,7 @@ class RoomCreationTest(unittest.TestCase): ]), auth=NonCallableMock(spec_set=["check", "add_auth_events"]), state_handler=NonCallableMock(spec_set=[ - "annotate_state_groups", + "annotate_event_with_state", ]), ratelimiter=NonCallableMock(spec_set=[ "send_message", @@ -282,7 +282,7 @@ class RoomCreationTest(unittest.TestCase): def annotate(event): event.state_events = {} return defer.succeed(None) - self.state_handler.annotate_state_groups.side_effect = annotate + self.state_handler.annotate_event_with_state.side_effect = annotate def hosts(room): return defer.succeed([]) @@ -311,6 +311,6 @@ class RoomCreationTest(unittest.TestCase): self.assertEquals(user_id, join_event.user_id) self.assertEquals(user_id, join_event.state_key) - self.assertTrue(self.state_handler.annotate_state_groups.called) + self.assertTrue(self.state_handler.annotate_event_with_state.called) self.assertTrue(self.federation.handle_new_event.called) diff --git a/tests/test_state.py b/tests/test_state.py index 3cc358be32..7979b54a35 100644 --- a/tests/test_state.py +++ b/tests/test_state.py @@ -44,7 +44,7 @@ class StateTestCase(unittest.TestCase): self.create_event(type="test2", state_key=""), ] - yield self.state.annotate_state_groups(event, old_state=old_state) + yield self.state.annotate_event_with_state(event, old_state=old_state) for k, v in event.old_state_events.items(): type, state_key = k @@ -66,7 +66,7 @@ class StateTestCase(unittest.TestCase): self.create_event(type="test2", state_key=""), ] - yield self.state.annotate_state_groups(event, old_state=old_state) + yield self.state.annotate_event_with_state(event, old_state=old_state) for k, v in event.old_state_events.items(): type, state_key = k @@ -99,7 +99,7 @@ class StateTestCase(unittest.TestCase): group_name: old_state, } - yield self.state.annotate_state_groups(event) + yield self.state.annotate_event_with_state(event) for k, v in event.old_state_events.items(): type, state_key = k @@ -141,7 +141,7 @@ class StateTestCase(unittest.TestCase): group_name: old_state, } - yield self.state.annotate_state_groups(event) + yield self.state.annotate_event_with_state(event) for k, v in event.old_state_events.items(): type, state_key = k @@ -199,7 +199,7 @@ class StateTestCase(unittest.TestCase): group_name_2: old_state_2, } - yield self.state.annotate_state_groups(event) + yield self.state.annotate_event_with_state(event) self.assertEqual(len(event.old_state_events), 5) @@ -235,7 +235,7 @@ class StateTestCase(unittest.TestCase): group_name_2: old_state_2, } - yield self.state.annotate_state_groups(event) + yield self.state.annotate_event_with_state(event) self.assertEqual(len(event.old_state_events), 5) -- cgit 1.4.1