From 2fc9e16664e39b8fa29c9f1cb024b973b4f06050 Mon Sep 17 00:00:00 2001 From: Eric Eastwood Date: Wed, 29 Jun 2022 16:42:28 +0200 Subject: [PATCH 01/11] Add test for joining a new federated room --- server/ensure-room-joined.js | 33 ++++++++++++++++++++ server/fetch-events-in-range.js | 10 ------- server/routes/install-routes.js | 10 +++++-- shared/lib/url-creator.js | 10 +++++-- test/client-utils.js | 20 +++++++++++++ test/e2e-tests.js | 53 ++++++++++++++++++++++++++++++++- 6 files changed, 121 insertions(+), 15 deletions(-) create mode 100644 server/ensure-room-joined.js diff --git a/server/ensure-room-joined.js b/server/ensure-room-joined.js new file mode 100644 index 00000000..1855ff9f --- /dev/null +++ b/server/ensure-room-joined.js @@ -0,0 +1,33 @@ +'use strict'; + +const assert = require('assert'); +const { URLSearchParams } = require('url'); +const urlJoin = require('url-join'); + +const { fetchEndpointAsJson } = require('./lib/fetch-endpoint'); + +const config = require('./lib/config'); +const matrixServerUrl = config.get('matrixServerUrl'); +assert(matrixServerUrl); + +async function ensureRoomJoined(accessToken, roomId, viaServers) { + let qs = new URLSearchParams(); + [].concat(viaServers).forEach((viaServer) => { + qs.append('via', viaServer); + }); + + // TODO: Only join world_readable rooms. Perhaps we want to serve public rooms + // where we have been invited. GET + // /_matrix/client/v3/directory/list/room/{roomId} (Gets the visibility of a + // given room on the server’s public room directory.) + const joinEndpoint = urlJoin( + matrixServerUrl, + `_matrix/client/r0/join/${roomId}?${qs.toString()}` + ); + await fetchEndpointAsJson(joinEndpoint, { + method: 'POST', + accessToken, + }); +} + +module.exports = ensureRoomJoined; diff --git a/server/fetch-events-in-range.js b/server/fetch-events-in-range.js index 582c1e5d..f6c767f3 100644 --- a/server/fetch-events-in-range.js +++ b/server/fetch-events-in-range.js @@ -26,16 +26,6 @@ async function fetchEventsFromTimestampBackwards(accessToken, roomId, ts, limit) assert(ts); assert(limit); - // TODO: Only join world_readable rooms. Perhaps we want to serve public rooms - // where we have been invited. GET - // /_matrix/client/v3/directory/list/room/{roomId} (Gets the visibility of a - // given room on the server’s public room directory.) - const joinEndpoint = urlJoin(matrixServerUrl, `_matrix/client/r0/join/${roomId}`); - await fetchEndpointAsJson(joinEndpoint, { - method: 'POST', - accessToken, - }); - const timestampToEventEndpoint = urlJoin( matrixServerUrl, `_matrix/client/unstable/org.matrix.msc3030/rooms/${roomId}/timestamp_to_event?ts=${ts}&dir=b` diff --git a/server/routes/install-routes.js b/server/routes/install-routes.js index a405a516..aadcf2f5 100644 --- a/server/routes/install-routes.js +++ b/server/routes/install-routes.js @@ -9,6 +9,7 @@ const StatusError = require('../lib/status-error'); const fetchRoomData = require('../fetch-room-data'); const fetchEventsInRange = require('../fetch-events-in-range'); +const ensureRoomJoined = require('../ensure-room-joined'); const renderHydrogenToString = require('../render-hydrogen-to-string'); const config = require('../lib/config'); @@ -117,7 +118,8 @@ function installRoutes(app) { // the format isn't correct, redirect to the correct hour range if (hourRange && toHour !== fromHour + 1) { res.redirect( - urlJoin( + // FIXME: Can we use the matrixPublicArchiveURLCreator here? + `${urlJoin( basePath, roomIdOrAlias, 'date', @@ -125,7 +127,7 @@ function installRoutes(app) { req.params.mm, req.params.dd, `${fromHour}-${fromHour + 1}` - ) + )}?${new URLSearchParams(req.query).toString()}` ); return; } @@ -133,6 +135,10 @@ function installRoutes(app) { // TODO: Highlight tile that matches ?at=$xxx //const aroundId = req.query.at; + // We have to wait for the room join to happen first before we can fetch + // any of the additional room info or messages. + await ensureRoomJoined(matrixAccessToken, roomIdOrAlias, req.query.via); + // Do these in parallel to avoid the extra time in sequential round-trips // (we want to display the archive page faster) const [roomData, { events, stateEventMap }] = await Promise.all([ diff --git a/shared/lib/url-creator.js b/shared/lib/url-creator.js index 7057a34d..1bf96e5c 100644 --- a/shared/lib/url-creator.js +++ b/shared/lib/url-creator.js @@ -1,18 +1,24 @@ 'use strict'; const urlJoin = require('url-join'); +const { URLSearchParams } = require('url'); class URLCreator { constructor(basePath) { this._basePath = basePath; } - archiveUrlForDate(roomId, date) { + archiveUrlForDate(roomId, date, { viaServers = [] } = {}) { + let qs = new URLSearchParams(); + [].concat(viaServers).forEach((viaServer) => { + qs.append('via', viaServer); + }); + // Gives the date in YYYY/mm/dd format. // date.toISOString() -> 2022-02-16T23:20:04.709Z const urlDate = date.toISOString().split('T')[0].replaceAll('-', '/'); - return urlJoin(this._basePath, `${roomId}/date/${urlDate}`); + return `${urlJoin(this._basePath, `${roomId}/date/${urlDate}`)}?${qs.toString()}`; } } diff --git a/test/client-utils.js b/test/client-utils.js index 30dc2ef8..9a8bb592 100644 --- a/test/client-utils.js +++ b/test/client-utils.js @@ -15,6 +15,22 @@ function getTxnId() { return `${new Date().getTime()}--${txnCount}`; } +async function ensureUserRegistered({ matrixServerUrl, username }) { + const registerResponse = await fetchEndpointAsJson( + urlJoin(matrixServerUrl, '/_matrix/client/v3/register'), + { + method: 'POST', + body: { + type: 'm.login.dummy', + username, + }, + } + ); + + const userId = registerResponse['user_id']; + assert(userId); +} + // Get client to act with for all of the client methods. This will use the // application service access token and client methods will append `?user_id` // for the specific user to act upon so we can use the `?ts` message timestamp @@ -169,6 +185,9 @@ async function createMessagesInRoom({ client, roomId, numMessages, prefix, times eventIds.push(eventId); } + // Sanity check that we actually sent some messages + assert.strictEqual(eventIds.length, numMessages); + return eventIds; } @@ -248,6 +267,7 @@ async function uploadContent({ client, roomId, data, fileName, contentType }) { } module.exports = { + ensureUserRegistered, getTestClientForHs, createTestRoom, joinRoom, diff --git a/test/e2e-tests.js b/test/e2e-tests.js index bb5769b9..d5672332 100644 --- a/test/e2e-tests.js +++ b/test/e2e-tests.js @@ -14,6 +14,7 @@ const { fetchEndpointAsText, fetchEndpointAsJson } = require('../server/lib/fetc const config = require('../server/lib/config'); const { + ensureUserRegistered, getTestClientForHs, createTestRoom, joinRoom, @@ -106,6 +107,23 @@ describe('matrix-public-archive', () => { }); describe('Archive', () => { + before(async () => { + // FIXME: This doesn't work because `400 Bad Request: + // {"errcode":"M_EXCLUSIVE","error":"This user ID is reserved by an + // application service."}` and we can't easily remove the AS registration, + // register the user, add the AS back, restart Synapse, and continue the + // tests. + // + // Make sure the application service archiver user itself is also + // explicitly registered otherwise we run into 404, `Profile was not + // found` errors when joining a remote federated room from the archiver + // user, see https://github.com/matrix-org/synapse/issues/4778 + await ensureUserRegistered({ + matrixServerUrl: testMatrixServerUrl1, + username: 'archiver', + }); + }); + // Use a fixed date at the start of the UTC day so that the tests are // consistent. Otherwise, the tests could fail when they start close to // midnight and it rolls over to the next day. @@ -163,6 +181,7 @@ describe('matrix-public-archive', () => { `Coulomb's Law of Friction: Kinetic friction is independent of the sliding velocity.`, ]; + // TODO: Can we use `createMessagesInRoom` here instead? const eventIds = []; for (const messageText of messageTextList) { const eventId = await sendMessageOnArchiveDate({ @@ -379,7 +398,39 @@ describe('matrix-public-archive', () => { ); }); - it(`can render day back in time from room on remote homeserver we haven't backfilled from`); + it(`can render day back in time from room on remote homeserver we haven't backfilled from`, async () => { + //const hs1Client = await getTestClientForHs(testMatrixServerUrl1); + const hs2Client = await getTestClientForHs(testMatrixServerUrl2); + + // Create a room on hs2 + const hs2RoomId = await createTestRoom(hs2Client); + const room2EventIds = await createMessagesInRoom({ + client: hs2Client, + roomId: hs2RoomId, + numMessages: 3, + prefix: HOMESERVER_URL_TO_PRETTY_NAME_MAP[hs2Client.homeserverUrl], + timestamp: archiveDate.getTime(), + }); + + archiveUrl = matrixPublicArchiveURLCreator.archiveUrlForDate(hs2RoomId, archiveDate, { + // Since hs1 doesn't know about this room on hs2 yet, we have to provide + // a via server to ask through. + viaServers: ['hs2'], + }); + + const archivePageHtml = await fetchEndpointAsText(archiveUrl); + + const dom = parseHTML(archivePageHtml); + + // Make sure the messages are visible + for (let i = 0; i < room2EventIds.length; i++) { + const eventId = room2EventIds[i]; + assert.strictEqual( + dom.document.querySelectorAll(`[data-event-id="${eventId}"]`).length, + room2EventIds.length + ); + } + }); it(`will redirect to hour pagination when there are too many messages`); From 86433320d1cee8a95f13f7fa0a1582a7fa3507c9 Mon Sep 17 00:00:00 2001 From: Eric Eastwood Date: Wed, 29 Jun 2022 19:25:38 +0200 Subject: [PATCH 02/11] Past join problems --- server/ensure-room-joined.js | 5 ++- test/client-utils.js | 83 ++++++++++++++++++++++-------------- test/e2e-tests.js | 23 +++++----- 3 files changed, 64 insertions(+), 47 deletions(-) diff --git a/server/ensure-room-joined.js b/server/ensure-room-joined.js index 1855ff9f..7a3943db 100644 --- a/server/ensure-room-joined.js +++ b/server/ensure-room-joined.js @@ -10,10 +10,10 @@ const config = require('./lib/config'); const matrixServerUrl = config.get('matrixServerUrl'); assert(matrixServerUrl); -async function ensureRoomJoined(accessToken, roomId, viaServers) { +async function ensureRoomJoined(accessToken, roomId, viaServers = []) { let qs = new URLSearchParams(); [].concat(viaServers).forEach((viaServer) => { - qs.append('via', viaServer); + qs.append('server_name', viaServer); }); // TODO: Only join world_readable rooms. Perhaps we want to serve public rooms @@ -24,6 +24,7 @@ async function ensureRoomJoined(accessToken, roomId, viaServers) { matrixServerUrl, `_matrix/client/r0/join/${roomId}?${qs.toString()}` ); + console.log('joinEndpoint', joinEndpoint); await fetchEndpointAsJson(joinEndpoint, { method: 'POST', accessToken, diff --git a/test/client-utils.js b/test/client-utils.js index 9a8bb592..748fcad7 100644 --- a/test/client-utils.js +++ b/test/client-utils.js @@ -8,6 +8,8 @@ const { fetchEndpointAsJson, fetchEndpoint } = require('../server/lib/fetch-endp const config = require('../server/lib/config'); const matrixAccessToken = config.get('matrixAccessToken'); assert(matrixAccessToken); +const testMatrixServerUrl1 = config.get('testMatrixServerUrl1'); +assert(testMatrixServerUrl1); let txnCount = 0; function getTxnId() { @@ -31,6 +33,14 @@ async function ensureUserRegistered({ matrixServerUrl, username }) { assert(userId); } +async function getTestClientForAs() { + return { + homeserverUrl: testMatrixServerUrl1, + accessToken: matrixAccessToken, + userId: '@archiver:hs1', + }; +} + // Get client to act with for all of the client methods. This will use the // application service access token and client methods will append `?user_id` // for the specific user to act upon so we can use the `?ts` message timestamp @@ -108,13 +118,15 @@ async function joinRoom({ client, roomId, viaServers }) { qs.append('user_id', client.applicationServiceUserIdOverride); } - const joinRoomResponse = await fetchEndpointAsJson( - urlJoin(client.homeserverUrl, `/_matrix/client/v3/join/${roomId}?${qs.toString()}`), - { - method: 'POST', - accessToken: client.accessToken, - } + const joinRoomUrl = urlJoin( + client.homeserverUrl, + `/_matrix/client/v3/join/${roomId}?${qs.toString()}` ); + console.log('test client joinRoomUrl', joinRoomUrl); + const joinRoomResponse = await fetchEndpointAsJson(joinRoomUrl, { + method: 'POST', + accessToken: client.accessToken, + }); const joinedRoomId = joinRoomResponse['room_id']; assert(joinedRoomId); @@ -197,33 +209,39 @@ async function updateProfile({ client, displayName, avatarUrl }) { qs.append('user_id', client.applicationServiceUserIdOverride); } - const updateDisplayNamePromise = fetchEndpointAsJson( - urlJoin( - client.homeserverUrl, - `/_matrix/client/v3/profile/${client.userId}/displayname?${qs.toString()}` - ), - { - method: 'PUT', - body: { - displayname: displayName, - }, - accessToken: client.accessToken, - } - ); + let updateDisplayNamePromise = Promise.resolve(); + if (displayName) { + updateDisplayNamePromise = fetchEndpointAsJson( + urlJoin( + client.homeserverUrl, + `/_matrix/client/v3/profile/${client.userId}/displayname?${qs.toString()}` + ), + { + method: 'PUT', + body: { + displayname: displayName, + }, + accessToken: client.accessToken, + } + ); + } - const updateAvatarUrlPromise = fetchEndpointAsJson( - urlJoin( - client.homeserverUrl, - `/_matrix/client/v3/profile/${client.userId}/avatar_url?${qs.toString()}` - ), - { - method: 'PUT', - body: { - avatar_url: avatarUrl, - }, - accessToken: client.accessToken, - } - ); + let updateAvatarUrlPromise = Promise.resolve(); + if (avatarUrl) { + updateAvatarUrlPromise = fetchEndpointAsJson( + urlJoin( + client.homeserverUrl, + `/_matrix/client/v3/profile/${client.userId}/avatar_url?${qs.toString()}` + ), + { + method: 'PUT', + body: { + avatar_url: avatarUrl, + }, + accessToken: client.accessToken, + } + ); + } await Promise.all([updateDisplayNamePromise, updateAvatarUrlPromise]); @@ -268,6 +286,7 @@ async function uploadContent({ client, roomId, data, fileName, contentType }) { module.exports = { ensureUserRegistered, + getTestClientForAs, getTestClientForHs, createTestRoom, joinRoom, diff --git a/test/e2e-tests.js b/test/e2e-tests.js index d5672332..a7b08575 100644 --- a/test/e2e-tests.js +++ b/test/e2e-tests.js @@ -15,6 +15,7 @@ const config = require('../server/lib/config'); const { ensureUserRegistered, + getTestClientForAs, getTestClientForHs, createTestRoom, joinRoom, @@ -108,19 +109,16 @@ describe('matrix-public-archive', () => { describe('Archive', () => { before(async () => { - // FIXME: This doesn't work because `400 Bad Request: - // {"errcode":"M_EXCLUSIVE","error":"This user ID is reserved by an - // application service."}` and we can't easily remove the AS registration, - // register the user, add the AS back, restart Synapse, and continue the - // tests. + // Make sure the application service archiver user itself has a profile + // set otherwise we run into 404, `Profile was not found` errors when + // joining a remote federated room from the archiver user, see + // https://github.com/matrix-org/synapse/issues/4778 // - // Make sure the application service archiver user itself is also - // explicitly registered otherwise we run into 404, `Profile was not - // found` errors when joining a remote federated room from the archiver - // user, see https://github.com/matrix-org/synapse/issues/4778 - await ensureUserRegistered({ - matrixServerUrl: testMatrixServerUrl1, - username: 'archiver', + // FIXME: Remove after https://github.com/matrix-org/synapse/issues/4778 is resolved + const asClient = await getTestClientForAs(); + await updateProfile({ + client: asClient, + displayName: 'Archiver', }); }); @@ -399,7 +397,6 @@ describe('matrix-public-archive', () => { }); it(`can render day back in time from room on remote homeserver we haven't backfilled from`, async () => { - //const hs1Client = await getTestClientForHs(testMatrixServerUrl1); const hs2Client = await getTestClientForHs(testMatrixServerUrl2); // Create a room on hs2 From 298d941e8e682e225b3c36be8eb0bf7b03e7cb16 Mon Sep 17 00:00:00 2001 From: Eric Eastwood Date: Tue, 5 Jul 2022 17:35:24 -0500 Subject: [PATCH 03/11] Add macOS reference --- test/README.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/README.md b/test/README.md index 0040cecc..ef4c7781 100644 --- a/test/README.md +++ b/test/README.md @@ -27,6 +27,19 @@ $ npm run test-interactive ### Developer utility +macOS: + +```sh +$ docker ps --all | grep test_hs +$ docker logs -f --tail 10 matrix_public_archive_test-hs1-1 +$ docker logs -f --tail 10 matrix_public_archive_test-hs2-1 + +$ docker stop matrix_public_archive_test-hs1-1 matrix_public_archive_test-hs2-1 +$ docker rm matrix_public_archive_test-hs1-1 matrix_public_archive_test-hs2-1 +``` + +Windows: + ```sh $ docker ps --all | grep test_hs $ docker logs -f --tail 10 matrix_public_archive_test_hs1_1 From a516663e19f4e59b04463138f787dd39691a42bd Mon Sep 17 00:00:00 2001 From: Eric Eastwood Date: Thu, 7 Jul 2022 08:23:43 -0500 Subject: [PATCH 04/11] name change --- test/e2e-tests.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/e2e-tests.js b/test/e2e-tests.js index 62c95673..a47c015a 100644 --- a/test/e2e-tests.js +++ b/test/e2e-tests.js @@ -392,7 +392,7 @@ describe('matrix-public-archive', () => { ); }); - it(`can render day back in time from room on remote homeserver we haven't backfilled from`, async () => { + it.only(`can render day back in time from room on remote homeserver we haven't backfilled from`, async () => { const hs2Client = await getTestClientForHs(testMatrixServerUrl2); // Create a room on hs2 @@ -404,6 +404,7 @@ describe('matrix-public-archive', () => { prefix: HOMESERVER_URL_TO_PRETTY_NAME_MAP[hs2Client.homeserverUrl], timestamp: archiveDate.getTime(), }); + console.log('archiveDate.getTime()', archiveDate.getTime()); archiveUrl = matrixPublicArchiveURLCreator.archiveUrlForDate(hs2RoomId, archiveDate, { // Since hs1 doesn't know about this room on hs2 yet, we have to provide From e1d056fdab0367e705fd6afefa0407406d99f592 Mon Sep 17 00:00:00 2001 From: Eric Eastwood Date: Mon, 29 Aug 2022 14:16:29 -0500 Subject: [PATCH 05/11] Remove unnecessary Docker compose number difference between platforms See https://github.com/matrix-org/matrix-public-archive/pull/31#discussion_r914270013 --- test/README.md | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/test/README.md b/test/README.md index ef4c7781..0040cecc 100644 --- a/test/README.md +++ b/test/README.md @@ -27,19 +27,6 @@ $ npm run test-interactive ### Developer utility -macOS: - -```sh -$ docker ps --all | grep test_hs -$ docker logs -f --tail 10 matrix_public_archive_test-hs1-1 -$ docker logs -f --tail 10 matrix_public_archive_test-hs2-1 - -$ docker stop matrix_public_archive_test-hs1-1 matrix_public_archive_test-hs2-1 -$ docker rm matrix_public_archive_test-hs1-1 matrix_public_archive_test-hs2-1 -``` - -Windows: - ```sh $ docker ps --all | grep test_hs $ docker logs -f --tail 10 matrix_public_archive_test_hs1_1 From 06e939588baf4efb8b0169971c39f9cbf57bd28e Mon Sep 17 00:00:00 2001 From: Eric Eastwood Date: Mon, 29 Aug 2022 14:26:21 -0500 Subject: [PATCH 06/11] Remove `URLSearchParams` import because it works without and more compatible with browser vs Node.js See https://github.com/matrix-org/matrix-public-archive/pull/31#discussion_r915899766 --- server/ensure-room-joined.js | 2 -- shared/lib/url-creator.js | 1 - test/client-utils.js | 1 - test/e2e-tests.js | 1 - 4 files changed, 5 deletions(-) diff --git a/server/ensure-room-joined.js b/server/ensure-room-joined.js index 7a3943db..cd0bd299 100644 --- a/server/ensure-room-joined.js +++ b/server/ensure-room-joined.js @@ -1,7 +1,6 @@ 'use strict'; const assert = require('assert'); -const { URLSearchParams } = require('url'); const urlJoin = require('url-join'); const { fetchEndpointAsJson } = require('./lib/fetch-endpoint'); @@ -24,7 +23,6 @@ async function ensureRoomJoined(accessToken, roomId, viaServers = []) { matrixServerUrl, `_matrix/client/r0/join/${roomId}?${qs.toString()}` ); - console.log('joinEndpoint', joinEndpoint); await fetchEndpointAsJson(joinEndpoint, { method: 'POST', accessToken, diff --git a/shared/lib/url-creator.js b/shared/lib/url-creator.js index 1bf96e5c..21bd4dc7 100644 --- a/shared/lib/url-creator.js +++ b/shared/lib/url-creator.js @@ -1,7 +1,6 @@ 'use strict'; const urlJoin = require('url-join'); -const { URLSearchParams } = require('url'); class URLCreator { constructor(basePath) { diff --git a/test/client-utils.js b/test/client-utils.js index 748fcad7..760b0682 100644 --- a/test/client-utils.js +++ b/test/client-utils.js @@ -1,7 +1,6 @@ 'use strict'; const assert = require('assert'); -const { URLSearchParams } = require('url'); const urlJoin = require('url-join'); const { fetchEndpointAsJson, fetchEndpoint } = require('../server/lib/fetch-endpoint'); diff --git a/test/e2e-tests.js b/test/e2e-tests.js index a47c015a..b6fc5595 100644 --- a/test/e2e-tests.js +++ b/test/e2e-tests.js @@ -404,7 +404,6 @@ describe('matrix-public-archive', () => { prefix: HOMESERVER_URL_TO_PRETTY_NAME_MAP[hs2Client.homeserverUrl], timestamp: archiveDate.getTime(), }); - console.log('archiveDate.getTime()', archiveDate.getTime()); archiveUrl = matrixPublicArchiveURLCreator.archiveUrlForDate(hs2RoomId, archiveDate, { // Since hs1 doesn't know about this room on hs2 yet, we have to provide From 9549acfb484ba4b41be590e675ca89e7ff4b0bc8 Mon Sep 17 00:00:00 2001 From: Eric Eastwood Date: Mon, 29 Aug 2022 14:52:17 -0500 Subject: [PATCH 07/11] Only add the ? if there are query parameters --- server/routes/install-routes.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/server/routes/install-routes.js b/server/routes/install-routes.js index d0dbbd34..71d51c65 100644 --- a/server/routes/install-routes.js +++ b/server/routes/install-routes.js @@ -137,6 +137,12 @@ function installRoutes(app) { // If the hourRange is defined, we force the range to always be 1 hour. If // the format isn't correct, redirect to the correct hour range if (hourRange && toHour !== fromHour + 1) { + // Pass through the query parameters + let queryParamterUrlPiece = ''; + if (req.query) { + queryParamterUrlPiece = `?${new URLSearchParams(req.query).toString()}`; + } + res.redirect( // FIXME: Can we use the matrixPublicArchiveURLCreator here? `${urlJoin( @@ -147,7 +153,7 @@ function installRoutes(app) { req.params.mm, req.params.dd, `${fromHour}-${fromHour + 1}` - )}?${new URLSearchParams(req.query).toString()}` + )}${queryParamterUrlPiece}` ); return; } From 00c10248bd5e67c3f839c8b5729912ddb0d69e68 Mon Sep 17 00:00:00 2001 From: Eric Eastwood Date: Mon, 29 Aug 2022 15:10:54 -0500 Subject: [PATCH 08/11] Better test assertion that tells you what's missing --- test/e2e-tests.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/test/e2e-tests.js b/test/e2e-tests.js index b6fc5595..05dde16e 100644 --- a/test/e2e-tests.js +++ b/test/e2e-tests.js @@ -14,7 +14,6 @@ const { fetchEndpointAsText, fetchEndpointAsJson } = require('../server/lib/fetc const config = require('../server/lib/config'); const { - ensureUserRegistered, getTestClientForAs, getTestClientForHs, createTestRoom, @@ -416,13 +415,14 @@ describe('matrix-public-archive', () => { const dom = parseHTML(archivePageHtml); // Make sure the messages are visible - for (let i = 0; i < room2EventIds.length; i++) { - const eventId = room2EventIds[i]; - assert.strictEqual( - dom.document.querySelectorAll(`[data-event-id="${eventId}"]`).length, - room2EventIds.length - ); - } + assert.deepStrictEqual( + room2EventIds.map((eventId) => { + return dom.document + .querySelector(`[data-event-id="${eventId}"]`) + ?.getAttribute('data-event-id'); + }), + room2EventIds + ); }); it(`will redirect to hour pagination when there are too many messages`); From 5b2b03ae3f59b4cf51098f0245d605e69337cc03 Mon Sep 17 00:00:00 2001 From: Eric Eastwood Date: Mon, 29 Aug 2022 16:26:18 -0500 Subject: [PATCH 09/11] Fix test failing because the homeserver backfilled the first instead of the last message All of the messages were at the same time, so the homeserver, just returned the first one but in reality, it's a series of messages that happen one after the other so it should return the last one. We adjust the timestamps so they actually appear as a series. Although we think about changing the sort on the date tiebreak when looking backwards in Synapse. --- test/client-utils.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/client-utils.js b/test/client-utils.js index 760b0682..05e47bbc 100644 --- a/test/client-utils.js +++ b/test/client-utils.js @@ -191,7 +191,10 @@ async function createMessagesInRoom({ client, roomId, numMessages, prefix, times msgtype: 'm.text', body: `${prefix} - message${i}`, }, - timestamp, + // We can't use the exact same timestamp for every message in the tests + // otherwise it's a toss up which event will be returned as the closest + // for `/timestamp_to_event`. + timestamp: timestamp + i, }); eventIds.push(eventId); } From d4270a878aea9f744d5c7e6c9da094c89a7e8303 Mon Sep 17 00:00:00 2001 From: Eric Eastwood Date: Mon, 29 Aug 2022 16:27:48 -0500 Subject: [PATCH 10/11] Remove `it.only` --- test/e2e-tests.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/e2e-tests.js b/test/e2e-tests.js index 05dde16e..c2211607 100644 --- a/test/e2e-tests.js +++ b/test/e2e-tests.js @@ -391,7 +391,7 @@ describe('matrix-public-archive', () => { ); }); - it.only(`can render day back in time from room on remote homeserver we haven't backfilled from`, async () => { + it(`can render day back in time from room on remote homeserver we haven't backfilled from`, async () => { const hs2Client = await getTestClientForHs(testMatrixServerUrl2); // Create a room on hs2 From 12b62ffd9feda6f1ab3916c7b81071e17cb16b0f Mon Sep 17 00:00:00 2001 From: Eric Eastwood Date: Mon, 29 Aug 2022 18:23:44 -0500 Subject: [PATCH 11/11] Note that this isn't necessary once https://github.com/matrix-org/synapse/pull/13658 lands --- test/client-utils.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/client-utils.js b/test/client-utils.js index 05e47bbc..a119aa4b 100644 --- a/test/client-utils.js +++ b/test/client-utils.js @@ -193,7 +193,9 @@ async function createMessagesInRoom({ client, roomId, numMessages, prefix, times }, // We can't use the exact same timestamp for every message in the tests // otherwise it's a toss up which event will be returned as the closest - // for `/timestamp_to_event`. + // for `/timestamp_to_event`. As a note, we don't have to do this after + // https://github.com/matrix-org/synapse/pull/13658 merges but it still + // seems like a good idea to make the tests more clear. timestamp: timestamp + i, }); eventIds.push(eventId);