@@ -1265,7 +1265,29 @@ func TestPartialStateJoin(t *testing.T) {
12651265 queryParams := req .URL .Query ()
12661266 t .Logf ("Incoming state_ids request for event %s in room %s" , queryParams ["event_id" ], roomID )
12671267 fedStateIdsRequestReceivedWaiter .Finish ()
1268- fedStateIdsSendResponseWaiter .Wait (t , 60 * time .Second )
1268+
1269+ // Wait for `fedStateIdsSendResponseWaiter`
1270+ select {
1271+ case <- fedStateIdsSendResponseWaiter .Done ():
1272+ // Happy-path now that we're done waiting, continue serving the request now
1273+ case <- req .Context ().Done ():
1274+ // The request was cancelled (the Complement server is probably shutting down)
1275+ // which means nobody wants this response any more (just bail out without
1276+ // doing any more work).
1277+ //
1278+ // Also as a note: although the cancellation itself happens while the test is
1279+ // still running, `srv.Close()` cancels any if-flight requests but does not
1280+ // wait for this goroutine, so by the time we wake up here the test may have
1281+ // already completed and touching `t` after that panics.
1282+ return
1283+ case <- time .After (60 * time .Second ):
1284+ // Sanity check so a wedged test fails loudly instead of blocking forever.
1285+ t .Fatalf (
1286+ "Timed out waiting for the test to finish the `sendResponseWaiter` while trying" +
1287+ "to serve /state_ids response for event %s" , queryParams ["event_id" ],
1288+ )
1289+ }
1290+
12691291 t .Logf ("Replying to /state_ids request with invalid response" )
12701292
12711293 w .WriteHeader (200 )
0 commit comments