These used to work because there was a huge blocking load operation,
which is now more asynchronous.
Note that the change made in `SongSelect` is not required, but defensive
(feels it should have been doing this the whole time).
https://github.com/ppy/osu/actions/runs/9985890747/job/27597501295
In this case, the settings overlay is taking a very long time to load
(on a background thread), and pops in when it finishes loading because
it's been requested to open.
The opens the settings overlay, closes it (by pressing escape, this does
not actually close it because it's not loaded yet), and then enters song
select by pressing 'P' 3 times. The settings overlay finishes loading at
just the right opportune moment to eat one of the 'P' key presses.
In an upcoming change, I stumbled upon a test failure mode wherein tests
in `TestSceneScreenNavigation` would die on the following exception:
2023-05-07 17:58:42 [error]: System.ObjectDisposedException: Cannot access a closed Realm.
2023-05-07 17:58:42 [error]: Object name: 'Realms.Realm'.
2023-05-07 17:58:42 [error]: at Realms.Realm.ThrowIfDisposed()
2023-05-07 17:58:42 [error]: at Realms.Realm.All[T]()
2023-05-07 17:58:42 [error]: at osu.Game.Beatmaps.BeatmapManager.<>c__DisplayClass25_0.<QueryBeatmap>b__0(Realm r) in D:\a\osu\osu\osu.Game\Beatmaps\BeatmapManager.cs:line 282
2023-05-07 17:58:42 [error]: at osu.Game.Database.RealmAccess.Run[T](Func`2 action) in D:\a\osu\osu\osu.Game\Database\RealmAccess.cs:line 387
2023-05-07 17:58:42 [error]: at osu.Game.Beatmaps.BeatmapManager.QueryBeatmap(Expression`1 query) in D:\a\osu\osu\osu.Game\Beatmaps\BeatmapManager.cs:line 282
2023-05-07 17:58:42 [error]: at osu.Game.Tests.Visual.OnlinePlay.TestRoomRequestsHandler.<HandleRequest>g__createResponseBeatmaps|6_0(Int32[] beatmapIds, <>c__DisplayClass6_0& ) in D:\a\osu\osu\osu.Game\Tests\Visual\OnlinePlay\TestRoomRequestsHandler.cs:line 174
2023-05-07 17:58:42 [error]: at osu.Game.Tests.Visual.OnlinePlay.TestRoomRequestsHandler.HandleRequest(APIRequest request, APIUser localUser, BeatmapManager beatmapManager) in D:\a\osu\osu\osu.Game\Tests\Visual\OnlinePlay\TestRoomRequestsHandler.cs:line 140
2023-05-07 17:58:42 [error]: at osu.Game.Tests.Visual.TestMultiplayerComponents.<>c__DisplayClass18_0.<load>b__0(APIRequest request) in D:\a\osu\osu\osu.Game.Tests\Visual\TestMultiplayerComponents.cs:line 80
2023-05-07 17:58:42 [error]: at osu.Game.Online.API.DummyAPIAccess.<>c__DisplayClass32_0.<Queue>b__0() in D:\a\osu\osu\osu.Game\Online\API\DummyAPIAccess.cs:line 74
Upon closer inspection, one of the tests in the scene instantiates a
`TestMultiplayerComponents` instance. `TestMultiplayerComponents`
registers a custom request handler onto `DummyAPIAccess`. Normally, this
is not an issue; however, because `TestSceneScreenNavigation` is an
`OsuGameTestScene`, and therefore has its storage recycled after every
test, this leads to the error above in the following scenario:
1. `TestPushMatchSubScreenAndPressBackButtonImmediately()` passes.
2. The test is cleaned up, and the test case's storage is recycled,
including the test case's realm database.
3. In a subsequent test, a web request handled by the dummy API request
handler is fired. The dummy API request handler subsequently attempts
to access a realm that does not exist anymore.
As the usage of `TestMultiplayerComponents` is highly unorthodox in this
particular case, I'm opting for a localised fix which ensures that the
request handler is cleaned up appropriately.