Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Fix chain cover update to handle events with duplicate auth events #9210

Merged
merged 2 commits into from
Jan 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/9210.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix chain cover update to handle events with duplicate auth events. Introduced in v1.26.0rc1.
2 changes: 1 addition & 1 deletion synapse/util/iterutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def sorted_topologically(
if node not in degree_map:
continue

for edge in edges:
for edge in set(edges):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

edges is unordered, correct?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

if edge in degree_map:
degree_map[node] += 1

Expand Down
12 changes: 12 additions & 0 deletions tests/util/test_itertools.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,15 @@ def test_fork(self):
# Valid orderings are `[1, 3, 2, 4]` or `[1, 2, 3, 4]`, but we should
# always get the same one.
self.assertEqual(list(sorted_topologically([4, 3, 2, 1], graph)), [1, 2, 3, 4])

def test_duplicates(self):
"Test that a graph with duplicate edges work"
graph = {1: [], 2: [1, 1], 3: [2, 2], 4: [3]} # type: Dict[int, List[int]]

self.assertEqual(list(sorted_topologically([4, 3, 2, 1], graph)), [1, 2, 3, 4])

def test_multiple_paths(self):
"Test that a graph with multiple paths between two nodes work"
graph = {1: [], 2: [1], 3: [2], 4: [3, 2, 1]} # type: Dict[int, List[int]]

self.assertEqual(list(sorted_topologically([4, 3, 2, 1], graph)), [1, 2, 3, 4])