From e91a70fa7acda2bb3e251dce3097f414c70d2376 Mon Sep 17 00:00:00 2001 From: Eric Eastwood Date: Thu, 13 Oct 2022 04:11:04 -0500 Subject: [PATCH] De-flake MSC3030 backfill test with Synapse worker replication (#492) Spawning from https://github.com/matrix-org/synapse/pull/14028#discussion_r987156197 CI failure: https://github.com/matrix-org/synapse/actions/runs/3182998161/jobs/5189731097#step:6:15343 (from [discussion](https://github.com/matrix-org/synapse/pull/14028#discussion_r987156197)) ``` WORKERS=1 POSTGRES=1 COMPLEMENT_ALWAYS_PRINT_SERVER_LOGS=1 COMPLEMENT_DIR=../complement ./scripts-dev/complement.sh -run TestJumpToDateEndpoint/parallel/federation/can_paginate_after_getting_remote_event_from_timestamp_to_event_endpoint ``` ### Why did this test fail with workers before? The reason they failed before was because we're fighting against stale caches across workers racing while waiting for invalidation, see https://github.com/matrix-org/synapse/issues/13185#issuecomment-1269413897 > Here is what happens: > > 1. `serverB` has `event1` stored as an `outlier` from previous requests (specifically from MSC3030 jump to date pulling in a missing `prev_event` after backfilling) > 1. Client on `serverB` calls `/messages?dir=b` > 1. `serverB:client_reader1` accepts the request and drives things > 1. `serverB:client_reader1` has some backward extremities in range and requests `/backfill` from `serverA` > 1. `serverB:client_reader1` processes the events from backfill including `event1` and puts them in the `_event_persist_queue` > 1. `serverB:master` picks up the events from the `_event_persist_queue` and persists them to the database, de-outliers `event1` and invalidates its own cache and sends them over replication > 1. `serverB:client_reader1` starts assembling the `/messages` response and gets `event1` out of the stale cache still as an `outlier` > 1. `serverB:client_reader1` responds to the `/messages` request without `event1` because `outliers` are filtered out > 1. `serverB:client_reader1` finally gets the replication data and invalidates its own cache for `event1` (too late, we already got the events from the stale cache and responded) --- tests/msc3030_test.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/msc3030_test.go b/tests/msc3030_test.go index 061a63ad..8350b192 100644 --- a/tests/msc3030_test.go +++ b/tests/msc3030_test.go @@ -203,6 +203,13 @@ func TestJumpToDateEndpoint(t *testing.T) { contextResResBody := client.ParseJSON(t, contextRes) paginationToken := client.GetJSONFieldStr(t, contextResResBody, "end") + // Hit `/messages` until `eventA` has been backfilled and replicated across + // workers (the worker persisting events isn't necessarily the same as the worker + // serving `/messages`) + fetchUntilMessagesResponseHas(t, remoteCharlie, roomID, func(ev gjson.Result) bool { + return ev.Get("event_id").Str == eventA.EventID + }) + // Paginate backwards from eventB messagesRes := remoteCharlie.MustDoFunc(t, "GET", []string{"_matrix", "client", "r0", "rooms", roomID, "messages"}, client.WithContentType("application/json"), client.WithQueries(url.Values{ "dir": []string{"b"},