mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-05-02 10:56:06 -04:00
Fix a bug which could lead to incorrect state (#13278)
There are two fixes here: 1. A long-standing bug where we incorrectly calculated `delta_ids`; and 2. A bug introduced in #13267 where we got current state incorrect.
This commit is contained in:
parent
512486bbeb
commit
7be954f59b
4 changed files with 58 additions and 7 deletions
|
@ -21,7 +21,7 @@ from synapse.api.constants import EventTypes, Membership
|
|||
from synapse.api.room_versions import RoomVersions
|
||||
from synapse.events import make_event_from_dict
|
||||
from synapse.events.snapshot import EventContext
|
||||
from synapse.state import StateHandler, StateResolutionHandler
|
||||
from synapse.state import StateHandler, StateResolutionHandler, _make_state_cache_entry
|
||||
from synapse.util import Clock
|
||||
from synapse.util.macaroons import MacaroonGenerator
|
||||
|
||||
|
@ -760,3 +760,43 @@ class StateTestCase(unittest.TestCase):
|
|||
|
||||
result = yield defer.ensureDeferred(self.state.compute_event_context(event))
|
||||
return result
|
||||
|
||||
def test_make_state_cache_entry(self):
|
||||
"Test that calculating a prev_group and delta is correct"
|
||||
|
||||
new_state = {
|
||||
("a", ""): "E",
|
||||
("b", ""): "E",
|
||||
("c", ""): "E",
|
||||
("d", ""): "E",
|
||||
}
|
||||
|
||||
# old_state_1 has fewer differences to new_state than old_state_2, but
|
||||
# the delta involves deleting a key, which isn't allowed in the deltas,
|
||||
# so we should pick old_state_2 as the prev_group.
|
||||
|
||||
# `old_state_1` has two differences: `a` and `e`
|
||||
old_state_1 = {
|
||||
("a", ""): "F",
|
||||
("b", ""): "E",
|
||||
("c", ""): "E",
|
||||
("d", ""): "E",
|
||||
("e", ""): "E",
|
||||
}
|
||||
|
||||
# `old_state_2` has three differences: `a`, `c` and `d`
|
||||
old_state_2 = {
|
||||
("a", ""): "F",
|
||||
("b", ""): "E",
|
||||
("c", ""): "F",
|
||||
("d", ""): "F",
|
||||
}
|
||||
|
||||
entry = _make_state_cache_entry(new_state, {1: old_state_1, 2: old_state_2})
|
||||
|
||||
self.assertEqual(entry.prev_group, 2)
|
||||
|
||||
# There are three changes from `old_state_2` to `new_state`
|
||||
self.assertEqual(
|
||||
entry.delta_ids, {("a", ""): "E", ("c", ""): "E", ("d", ""): "E"}
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue