test_event_chain.py 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741
  1. # -*- coding: utf-8 -*-
  2. # Copyright 2020 The Matrix.org Foundation C.I.C.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the 'License');
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an 'AS IS' BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. from typing import Dict, List, Set, Tuple
  16. from twisted.trial import unittest
  17. from synapse.api.constants import EventTypes
  18. from synapse.api.room_versions import RoomVersions
  19. from synapse.events import EventBase
  20. from synapse.rest import admin
  21. from synapse.rest.client.v1 import login, room
  22. from synapse.storage.databases.main.events import _LinkMap
  23. from synapse.types import create_requester
  24. from tests.unittest import HomeserverTestCase
  25. class EventChainStoreTestCase(HomeserverTestCase):
  26. def prepare(self, reactor, clock, hs):
  27. self.store = hs.get_datastore()
  28. self._next_stream_ordering = 1
  29. def test_simple(self):
  30. """Test that the example in `docs/auth_chain_difference_algorithm.md`
  31. works.
  32. """
  33. event_factory = self.hs.get_event_builder_factory()
  34. bob = "@creator:test"
  35. alice = "@alice:test"
  36. room_id = "!room:test"
  37. # Ensure that we have a rooms entry so that we generate the chain index.
  38. self.get_success(
  39. self.store.store_room(
  40. room_id=room_id,
  41. room_creator_user_id="",
  42. is_public=True,
  43. room_version=RoomVersions.V6,
  44. )
  45. )
  46. create = self.get_success(
  47. event_factory.for_room_version(
  48. RoomVersions.V6,
  49. {
  50. "type": EventTypes.Create,
  51. "state_key": "",
  52. "sender": bob,
  53. "room_id": room_id,
  54. "content": {"tag": "create"},
  55. },
  56. ).build(prev_event_ids=[], auth_event_ids=[])
  57. )
  58. bob_join = self.get_success(
  59. event_factory.for_room_version(
  60. RoomVersions.V6,
  61. {
  62. "type": EventTypes.Member,
  63. "state_key": bob,
  64. "sender": bob,
  65. "room_id": room_id,
  66. "content": {"tag": "bob_join"},
  67. },
  68. ).build(prev_event_ids=[], auth_event_ids=[create.event_id])
  69. )
  70. power = self.get_success(
  71. event_factory.for_room_version(
  72. RoomVersions.V6,
  73. {
  74. "type": EventTypes.PowerLevels,
  75. "state_key": "",
  76. "sender": bob,
  77. "room_id": room_id,
  78. "content": {"tag": "power"},
  79. },
  80. ).build(
  81. prev_event_ids=[], auth_event_ids=[create.event_id, bob_join.event_id],
  82. )
  83. )
  84. alice_invite = self.get_success(
  85. event_factory.for_room_version(
  86. RoomVersions.V6,
  87. {
  88. "type": EventTypes.Member,
  89. "state_key": alice,
  90. "sender": bob,
  91. "room_id": room_id,
  92. "content": {"tag": "alice_invite"},
  93. },
  94. ).build(
  95. prev_event_ids=[],
  96. auth_event_ids=[create.event_id, bob_join.event_id, power.event_id],
  97. )
  98. )
  99. alice_join = self.get_success(
  100. event_factory.for_room_version(
  101. RoomVersions.V6,
  102. {
  103. "type": EventTypes.Member,
  104. "state_key": alice,
  105. "sender": alice,
  106. "room_id": room_id,
  107. "content": {"tag": "alice_join"},
  108. },
  109. ).build(
  110. prev_event_ids=[],
  111. auth_event_ids=[create.event_id, alice_invite.event_id, power.event_id],
  112. )
  113. )
  114. power_2 = self.get_success(
  115. event_factory.for_room_version(
  116. RoomVersions.V6,
  117. {
  118. "type": EventTypes.PowerLevels,
  119. "state_key": "",
  120. "sender": bob,
  121. "room_id": room_id,
  122. "content": {"tag": "power_2"},
  123. },
  124. ).build(
  125. prev_event_ids=[],
  126. auth_event_ids=[create.event_id, bob_join.event_id, power.event_id],
  127. )
  128. )
  129. bob_join_2 = self.get_success(
  130. event_factory.for_room_version(
  131. RoomVersions.V6,
  132. {
  133. "type": EventTypes.Member,
  134. "state_key": bob,
  135. "sender": bob,
  136. "room_id": room_id,
  137. "content": {"tag": "bob_join_2"},
  138. },
  139. ).build(
  140. prev_event_ids=[],
  141. auth_event_ids=[create.event_id, bob_join.event_id, power.event_id],
  142. )
  143. )
  144. alice_join2 = self.get_success(
  145. event_factory.for_room_version(
  146. RoomVersions.V6,
  147. {
  148. "type": EventTypes.Member,
  149. "state_key": alice,
  150. "sender": alice,
  151. "room_id": room_id,
  152. "content": {"tag": "alice_join2"},
  153. },
  154. ).build(
  155. prev_event_ids=[],
  156. auth_event_ids=[
  157. create.event_id,
  158. alice_join.event_id,
  159. power_2.event_id,
  160. ],
  161. )
  162. )
  163. events = [
  164. create,
  165. bob_join,
  166. power,
  167. alice_invite,
  168. alice_join,
  169. bob_join_2,
  170. power_2,
  171. alice_join2,
  172. ]
  173. expected_links = [
  174. (bob_join, create),
  175. (power, create),
  176. (power, bob_join),
  177. (alice_invite, create),
  178. (alice_invite, power),
  179. (alice_invite, bob_join),
  180. (bob_join_2, power),
  181. (alice_join2, power_2),
  182. ]
  183. self.persist(events)
  184. chain_map, link_map = self.fetch_chains(events)
  185. # Check that the expected links and only the expected links have been
  186. # added.
  187. self.assertEqual(len(expected_links), len(list(link_map.get_additions())))
  188. for start, end in expected_links:
  189. start_id, start_seq = chain_map[start.event_id]
  190. end_id, end_seq = chain_map[end.event_id]
  191. self.assertIn(
  192. (start_seq, end_seq), list(link_map.get_links_between(start_id, end_id))
  193. )
  194. # Test that everything can reach the create event, but the create event
  195. # can't reach anything.
  196. for event in events[1:]:
  197. self.assertTrue(
  198. link_map.exists_path_from(
  199. chain_map[event.event_id], chain_map[create.event_id]
  200. ),
  201. )
  202. self.assertFalse(
  203. link_map.exists_path_from(
  204. chain_map[create.event_id], chain_map[event.event_id],
  205. ),
  206. )
  207. def test_out_of_order_events(self):
  208. """Test that we handle persisting events that we don't have the full
  209. auth chain for yet (which should only happen for out of band memberships).
  210. """
  211. event_factory = self.hs.get_event_builder_factory()
  212. bob = "@creator:test"
  213. alice = "@alice:test"
  214. room_id = "!room:test"
  215. # Ensure that we have a rooms entry so that we generate the chain index.
  216. self.get_success(
  217. self.store.store_room(
  218. room_id=room_id,
  219. room_creator_user_id="",
  220. is_public=True,
  221. room_version=RoomVersions.V6,
  222. )
  223. )
  224. # First persist the base room.
  225. create = self.get_success(
  226. event_factory.for_room_version(
  227. RoomVersions.V6,
  228. {
  229. "type": EventTypes.Create,
  230. "state_key": "",
  231. "sender": bob,
  232. "room_id": room_id,
  233. "content": {"tag": "create"},
  234. },
  235. ).build(prev_event_ids=[], auth_event_ids=[])
  236. )
  237. bob_join = self.get_success(
  238. event_factory.for_room_version(
  239. RoomVersions.V6,
  240. {
  241. "type": EventTypes.Member,
  242. "state_key": bob,
  243. "sender": bob,
  244. "room_id": room_id,
  245. "content": {"tag": "bob_join"},
  246. },
  247. ).build(prev_event_ids=[], auth_event_ids=[create.event_id])
  248. )
  249. power = self.get_success(
  250. event_factory.for_room_version(
  251. RoomVersions.V6,
  252. {
  253. "type": EventTypes.PowerLevels,
  254. "state_key": "",
  255. "sender": bob,
  256. "room_id": room_id,
  257. "content": {"tag": "power"},
  258. },
  259. ).build(
  260. prev_event_ids=[], auth_event_ids=[create.event_id, bob_join.event_id],
  261. )
  262. )
  263. self.persist([create, bob_join, power])
  264. # Now persist an invite and a couple of memberships out of order.
  265. alice_invite = self.get_success(
  266. event_factory.for_room_version(
  267. RoomVersions.V6,
  268. {
  269. "type": EventTypes.Member,
  270. "state_key": alice,
  271. "sender": bob,
  272. "room_id": room_id,
  273. "content": {"tag": "alice_invite"},
  274. },
  275. ).build(
  276. prev_event_ids=[],
  277. auth_event_ids=[create.event_id, bob_join.event_id, power.event_id],
  278. )
  279. )
  280. alice_join = self.get_success(
  281. event_factory.for_room_version(
  282. RoomVersions.V6,
  283. {
  284. "type": EventTypes.Member,
  285. "state_key": alice,
  286. "sender": alice,
  287. "room_id": room_id,
  288. "content": {"tag": "alice_join"},
  289. },
  290. ).build(
  291. prev_event_ids=[],
  292. auth_event_ids=[create.event_id, alice_invite.event_id, power.event_id],
  293. )
  294. )
  295. alice_join2 = self.get_success(
  296. event_factory.for_room_version(
  297. RoomVersions.V6,
  298. {
  299. "type": EventTypes.Member,
  300. "state_key": alice,
  301. "sender": alice,
  302. "room_id": room_id,
  303. "content": {"tag": "alice_join2"},
  304. },
  305. ).build(
  306. prev_event_ids=[],
  307. auth_event_ids=[create.event_id, alice_join.event_id, power.event_id],
  308. )
  309. )
  310. self.persist([alice_join])
  311. self.persist([alice_join2])
  312. self.persist([alice_invite])
  313. # The end result should be sane.
  314. events = [create, bob_join, power, alice_invite, alice_join]
  315. chain_map, link_map = self.fetch_chains(events)
  316. expected_links = [
  317. (bob_join, create),
  318. (power, create),
  319. (power, bob_join),
  320. (alice_invite, create),
  321. (alice_invite, power),
  322. (alice_invite, bob_join),
  323. ]
  324. # Check that the expected links and only the expected links have been
  325. # added.
  326. self.assertEqual(len(expected_links), len(list(link_map.get_additions())))
  327. for start, end in expected_links:
  328. start_id, start_seq = chain_map[start.event_id]
  329. end_id, end_seq = chain_map[end.event_id]
  330. self.assertIn(
  331. (start_seq, end_seq), list(link_map.get_links_between(start_id, end_id))
  332. )
  333. def persist(
  334. self, events: List[EventBase],
  335. ):
  336. """Persist the given events and check that the links generated match
  337. those given.
  338. """
  339. persist_events_store = self.hs.get_datastores().persist_events
  340. for e in events:
  341. e.internal_metadata.stream_ordering = self._next_stream_ordering
  342. self._next_stream_ordering += 1
  343. def _persist(txn):
  344. # We need to persist the events to the events and state_events
  345. # tables.
  346. persist_events_store._store_event_txn(txn, [(e, {}) for e in events])
  347. # Actually call the function that calculates the auth chain stuff.
  348. persist_events_store._persist_event_auth_chain_txn(txn, events)
  349. self.get_success(
  350. persist_events_store.db_pool.runInteraction("_persist", _persist,)
  351. )
  352. def fetch_chains(
  353. self, events: List[EventBase]
  354. ) -> Tuple[Dict[str, Tuple[int, int]], _LinkMap]:
  355. # Fetch the map from event ID -> (chain ID, sequence number)
  356. rows = self.get_success(
  357. self.store.db_pool.simple_select_many_batch(
  358. table="event_auth_chains",
  359. column="event_id",
  360. iterable=[e.event_id for e in events],
  361. retcols=("event_id", "chain_id", "sequence_number"),
  362. keyvalues={},
  363. )
  364. )
  365. chain_map = {
  366. row["event_id"]: (row["chain_id"], row["sequence_number"]) for row in rows
  367. }
  368. # Fetch all the links and pass them to the _LinkMap.
  369. rows = self.get_success(
  370. self.store.db_pool.simple_select_many_batch(
  371. table="event_auth_chain_links",
  372. column="origin_chain_id",
  373. iterable=[chain_id for chain_id, _ in chain_map.values()],
  374. retcols=(
  375. "origin_chain_id",
  376. "origin_sequence_number",
  377. "target_chain_id",
  378. "target_sequence_number",
  379. ),
  380. keyvalues={},
  381. )
  382. )
  383. link_map = _LinkMap()
  384. for row in rows:
  385. added = link_map.add_link(
  386. (row["origin_chain_id"], row["origin_sequence_number"]),
  387. (row["target_chain_id"], row["target_sequence_number"]),
  388. )
  389. # We shouldn't have persisted any redundant links
  390. self.assertTrue(added)
  391. return chain_map, link_map
  392. class LinkMapTestCase(unittest.TestCase):
  393. def test_simple(self):
  394. """Basic tests for the LinkMap.
  395. """
  396. link_map = _LinkMap()
  397. link_map.add_link((1, 1), (2, 1), new=False)
  398. self.assertCountEqual(link_map.get_links_between(1, 2), [(1, 1)])
  399. self.assertCountEqual(link_map.get_links_from((1, 1)), [(2, 1)])
  400. self.assertCountEqual(link_map.get_additions(), [])
  401. self.assertTrue(link_map.exists_path_from((1, 5), (2, 1)))
  402. self.assertFalse(link_map.exists_path_from((1, 5), (2, 2)))
  403. self.assertTrue(link_map.exists_path_from((1, 5), (1, 1)))
  404. self.assertFalse(link_map.exists_path_from((1, 1), (1, 5)))
  405. # Attempting to add a redundant link is ignored.
  406. self.assertFalse(link_map.add_link((1, 4), (2, 1)))
  407. self.assertCountEqual(link_map.get_links_between(1, 2), [(1, 1)])
  408. # Adding new non-redundant links works
  409. self.assertTrue(link_map.add_link((1, 3), (2, 3)))
  410. self.assertCountEqual(link_map.get_links_between(1, 2), [(1, 1), (3, 3)])
  411. self.assertTrue(link_map.add_link((2, 5), (1, 3)))
  412. self.assertCountEqual(link_map.get_links_between(2, 1), [(5, 3)])
  413. self.assertCountEqual(link_map.get_links_between(1, 2), [(1, 1), (3, 3)])
  414. self.assertCountEqual(link_map.get_additions(), [(1, 3, 2, 3), (2, 5, 1, 3)])
  415. class EventChainBackgroundUpdateTestCase(HomeserverTestCase):
  416. servlets = [
  417. admin.register_servlets,
  418. room.register_servlets,
  419. login.register_servlets,
  420. ]
  421. def prepare(self, reactor, clock, hs):
  422. self.store = hs.get_datastore()
  423. self.user_id = self.register_user("foo", "pass")
  424. self.token = self.login("foo", "pass")
  425. self.requester = create_requester(self.user_id)
  426. def _generate_room(self) -> Tuple[str, List[Set[str]]]:
  427. """Insert a room without a chain cover index.
  428. """
  429. room_id = self.helper.create_room_as(self.user_id, tok=self.token)
  430. # Mark the room as not having a chain cover index
  431. self.get_success(
  432. self.store.db_pool.simple_update(
  433. table="rooms",
  434. keyvalues={"room_id": room_id},
  435. updatevalues={"has_auth_chain_index": False},
  436. desc="test",
  437. )
  438. )
  439. # Create a fork in the DAG with different events.
  440. event_handler = self.hs.get_event_creation_handler()
  441. latest_event_ids = self.get_success(
  442. self.store.get_prev_events_for_room(room_id)
  443. )
  444. event, context = self.get_success(
  445. event_handler.create_event(
  446. self.requester,
  447. {
  448. "type": "some_state_type",
  449. "state_key": "",
  450. "content": {},
  451. "room_id": room_id,
  452. "sender": self.user_id,
  453. },
  454. prev_event_ids=latest_event_ids,
  455. )
  456. )
  457. self.get_success(
  458. event_handler.handle_new_client_event(self.requester, event, context)
  459. )
  460. state1 = set(self.get_success(context.get_current_state_ids()).values())
  461. event, context = self.get_success(
  462. event_handler.create_event(
  463. self.requester,
  464. {
  465. "type": "some_state_type",
  466. "state_key": "",
  467. "content": {},
  468. "room_id": room_id,
  469. "sender": self.user_id,
  470. },
  471. prev_event_ids=latest_event_ids,
  472. )
  473. )
  474. self.get_success(
  475. event_handler.handle_new_client_event(self.requester, event, context)
  476. )
  477. state2 = set(self.get_success(context.get_current_state_ids()).values())
  478. # Delete the chain cover info.
  479. def _delete_tables(txn):
  480. txn.execute("DELETE FROM event_auth_chains")
  481. txn.execute("DELETE FROM event_auth_chain_links")
  482. self.get_success(self.store.db_pool.runInteraction("test", _delete_tables))
  483. return room_id, [state1, state2]
  484. def test_background_update_single_room(self):
  485. """Test that the background update to calculate auth chains for historic
  486. rooms works correctly.
  487. """
  488. # Create a room
  489. room_id, states = self._generate_room()
  490. # Insert and run the background update.
  491. self.get_success(
  492. self.store.db_pool.simple_insert(
  493. "background_updates",
  494. {"update_name": "chain_cover", "progress_json": "{}"},
  495. )
  496. )
  497. # Ugh, have to reset this flag
  498. self.store.db_pool.updates._all_done = False
  499. while not self.get_success(
  500. self.store.db_pool.updates.has_completed_background_updates()
  501. ):
  502. self.get_success(
  503. self.store.db_pool.updates.do_next_background_update(100), by=0.1
  504. )
  505. # Test that the `has_auth_chain_index` has been set
  506. self.assertTrue(self.get_success(self.store.has_auth_chain_index(room_id)))
  507. # Test that calculating the auth chain difference using the newly
  508. # calculated chain cover works.
  509. self.get_success(
  510. self.store.db_pool.runInteraction(
  511. "test",
  512. self.store._get_auth_chain_difference_using_cover_index_txn,
  513. room_id,
  514. states,
  515. )
  516. )
  517. def test_background_update_multiple_rooms(self):
  518. """Test that the background update to calculate auth chains for historic
  519. rooms works correctly.
  520. """
  521. # Create a room
  522. room_id1, states1 = self._generate_room()
  523. room_id2, states2 = self._generate_room()
  524. room_id3, states2 = self._generate_room()
  525. # Insert and run the background update.
  526. self.get_success(
  527. self.store.db_pool.simple_insert(
  528. "background_updates",
  529. {"update_name": "chain_cover", "progress_json": "{}"},
  530. )
  531. )
  532. # Ugh, have to reset this flag
  533. self.store.db_pool.updates._all_done = False
  534. while not self.get_success(
  535. self.store.db_pool.updates.has_completed_background_updates()
  536. ):
  537. self.get_success(
  538. self.store.db_pool.updates.do_next_background_update(100), by=0.1
  539. )
  540. # Test that the `has_auth_chain_index` has been set
  541. self.assertTrue(self.get_success(self.store.has_auth_chain_index(room_id1)))
  542. self.assertTrue(self.get_success(self.store.has_auth_chain_index(room_id2)))
  543. self.assertTrue(self.get_success(self.store.has_auth_chain_index(room_id3)))
  544. # Test that calculating the auth chain difference using the newly
  545. # calculated chain cover works.
  546. self.get_success(
  547. self.store.db_pool.runInteraction(
  548. "test",
  549. self.store._get_auth_chain_difference_using_cover_index_txn,
  550. room_id1,
  551. states1,
  552. )
  553. )
  554. def test_background_update_single_large_room(self):
  555. """Test that the background update to calculate auth chains for historic
  556. rooms works correctly.
  557. """
  558. # Create a room
  559. room_id, states = self._generate_room()
  560. # Add a bunch of state so that it takes multiple iterations of the
  561. # background update to process the room.
  562. for i in range(0, 150):
  563. self.helper.send_state(
  564. room_id, event_type="m.test", body={"index": i}, tok=self.token
  565. )
  566. # Insert and run the background update.
  567. self.get_success(
  568. self.store.db_pool.simple_insert(
  569. "background_updates",
  570. {"update_name": "chain_cover", "progress_json": "{}"},
  571. )
  572. )
  573. # Ugh, have to reset this flag
  574. self.store.db_pool.updates._all_done = False
  575. iterations = 0
  576. while not self.get_success(
  577. self.store.db_pool.updates.has_completed_background_updates()
  578. ):
  579. iterations += 1
  580. self.get_success(
  581. self.store.db_pool.updates.do_next_background_update(100), by=0.1
  582. )
  583. # Ensure that we did actually take multiple iterations to process the
  584. # room.
  585. self.assertGreater(iterations, 1)
  586. # Test that the `has_auth_chain_index` has been set
  587. self.assertTrue(self.get_success(self.store.has_auth_chain_index(room_id)))
  588. # Test that calculating the auth chain difference using the newly
  589. # calculated chain cover works.
  590. self.get_success(
  591. self.store.db_pool.runInteraction(
  592. "test",
  593. self.store._get_auth_chain_difference_using_cover_index_txn,
  594. room_id,
  595. states,
  596. )
  597. )
  598. def test_background_update_multiple_large_room(self):
  599. """Test that the background update to calculate auth chains for historic
  600. rooms works correctly.
  601. """
  602. # Create the rooms
  603. room_id1, _ = self._generate_room()
  604. room_id2, _ = self._generate_room()
  605. # Add a bunch of state so that it takes multiple iterations of the
  606. # background update to process the room.
  607. for i in range(0, 150):
  608. self.helper.send_state(
  609. room_id1, event_type="m.test", body={"index": i}, tok=self.token
  610. )
  611. for i in range(0, 150):
  612. self.helper.send_state(
  613. room_id2, event_type="m.test", body={"index": i}, tok=self.token
  614. )
  615. # Insert and run the background update.
  616. self.get_success(
  617. self.store.db_pool.simple_insert(
  618. "background_updates",
  619. {"update_name": "chain_cover", "progress_json": "{}"},
  620. )
  621. )
  622. # Ugh, have to reset this flag
  623. self.store.db_pool.updates._all_done = False
  624. iterations = 0
  625. while not self.get_success(
  626. self.store.db_pool.updates.has_completed_background_updates()
  627. ):
  628. iterations += 1
  629. self.get_success(
  630. self.store.db_pool.updates.do_next_background_update(100), by=0.1
  631. )
  632. # Ensure that we did actually take multiple iterations to process the
  633. # room.
  634. self.assertGreater(iterations, 1)
  635. # Test that the `has_auth_chain_index` has been set
  636. self.assertTrue(self.get_success(self.store.has_auth_chain_index(room_id1)))
  637. self.assertTrue(self.get_success(self.store.has_auth_chain_index(room_id2)))