mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2024-09-07 04:01:52 +00:00
Test if a purge can make /messages return 500 responses
This commit is contained in:
parent
c350bc2f92
commit
6356f2088f
@ -25,7 +25,9 @@ from twisted.internet import defer
|
||||
|
||||
import synapse.rest.admin
|
||||
from synapse.api.constants import EventContentFields, EventTypes, Membership
|
||||
from synapse.handlers.pagination import PurgeStatus
|
||||
from synapse.rest.client.v1 import login, profile, room
|
||||
from synapse.util.stringutils import random_string
|
||||
|
||||
from tests import unittest
|
||||
|
||||
@ -910,6 +912,76 @@ class RoomMessageListTestCase(RoomBase):
|
||||
|
||||
return channel.json_body["chunk"]
|
||||
|
||||
def test_room_messages_purge(self):
|
||||
store = self.hs.get_datastore()
|
||||
pagination_handler = self.hs.get_pagination_handler()
|
||||
|
||||
# Send a first message in the room, which will be removed by the purge.
|
||||
first_event_id = self.helper.send(self.room_id, "message 1")["event_id"]
|
||||
first_token = self.get_success(
|
||||
store.get_topological_token_for_event(first_event_id)
|
||||
)
|
||||
|
||||
# Send a second message in the room, which won't be removed, and which we'll
|
||||
# use as the marker to purge events before.
|
||||
second_event_id = self.helper.send(self.room_id, "message 2")["event_id"]
|
||||
second_token = self.get_success(
|
||||
store.get_topological_token_for_event(second_event_id)
|
||||
)
|
||||
|
||||
# Send a third event in the room to ensure we don't fall under any edge case
|
||||
# due to our marker being the latest forward extremity in the room.
|
||||
self.helper.send(self.room_id, "message 3")
|
||||
|
||||
# Check that we get the first and second message when querying /messages.
|
||||
request, channel = self.make_request(
|
||||
"GET",
|
||||
"/rooms/%s/messages?access_token=x&from=%s&dir=b&filter=%s"
|
||||
% (self.room_id, second_token, json.dumps({"types": [EventTypes.Message]})),
|
||||
)
|
||||
self.render(request)
|
||||
self.assertEqual(channel.code, 200, channel.json_body)
|
||||
|
||||
chunk = channel.json_body["chunk"]
|
||||
self.assertEqual(len(chunk), 2, [event["content"] for event in chunk])
|
||||
|
||||
# Purge every event before the second event.
|
||||
purge_id = random_string(16)
|
||||
pagination_handler._purges_by_id[purge_id] = PurgeStatus()
|
||||
self.get_success(pagination_handler._purge_history(
|
||||
purge_id=purge_id,
|
||||
room_id=self.room_id,
|
||||
token=second_token,
|
||||
delete_local_events=True,
|
||||
))
|
||||
|
||||
# Check that we only get the second message through /message now that the first
|
||||
# has been purged.
|
||||
request, channel = self.make_request(
|
||||
"GET",
|
||||
"/rooms/%s/messages?access_token=x&from=%s&dir=b&filter=%s"
|
||||
% (self.room_id, second_token, json.dumps({"types": [EventTypes.Message]})),
|
||||
)
|
||||
self.render(request)
|
||||
self.assertEqual(channel.code, 200, channel.json_body)
|
||||
|
||||
chunk = channel.json_body["chunk"]
|
||||
self.assertEqual(len(chunk), 1, [event["content"] for event in chunk])
|
||||
|
||||
# Check that we get no event, but also no error, when querying /messages with
|
||||
# the token that was pointing at the first event, because we don't have it
|
||||
# anymore.
|
||||
request, channel = self.make_request(
|
||||
"GET",
|
||||
"/rooms/%s/messages?access_token=x&from=%s&dir=b&filter=%s"
|
||||
% (self.room_id, first_token, json.dumps({"types": [EventTypes.Message]})),
|
||||
)
|
||||
self.render(request)
|
||||
self.assertEqual(channel.code, 200, channel.json_body)
|
||||
|
||||
chunk = channel.json_body["chunk"]
|
||||
self.assertEqual(len(chunk), 0, [event["content"] for event in chunk])
|
||||
|
||||
|
||||
class RoomSearchTestCase(unittest.HomeserverTestCase):
|
||||
servlets = [
|
||||
|
Loading…
Reference in New Issue
Block a user