From 5bf47cfcedddb1d217e6c4ab0043686a2ab89f30 Mon Sep 17 00:00:00 2001 From: landaun Date: Tue, 11 Aug 2026 09:13:03 -0400 Subject: [PATCH] test(gateway): assert the channel-directory write leaves the event loop Mirrors test_discord_builder_runs_off_event_loop_thread. Verified to FAIL against unpatched v0.19.0 and pass with the fix. --- tests/gateway/test_channel_directory.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/gateway/test_channel_directory.py b/tests/gateway/test_channel_directory.py index 6c7e651322c08..e8ae5ad35e6ff 100644 --- a/tests/gateway/test_channel_directory.py +++ b/tests/gateway/test_channel_directory.py @@ -110,6 +110,27 @@ class TestBuildChannelDirectoryOffload: assert builder_threads assert all(tid != loop_thread for tid in builder_threads) + def test_directory_write_runs_off_event_loop_thread(self, tmp_path): + """The persist step calls os.fsync, which blocks the loop until the write + reaches stable storage. #60794 moved the builders off the loop; the write + stayed on it.""" + from gateway.config import Platform + + cache_file = tmp_path / "channel_directory.json" + loop_thread = threading.get_ident() + write_threads = [] + + def fake_write(path, data, *args, **kwargs): + write_threads.append(threading.get_ident()) + + with patch("gateway.channel_directory.atomic_json_write", side_effect=fake_write), \ + patch("gateway.channel_directory._build_discord", return_value=[]), \ + patch("gateway.channel_directory.DIRECTORY_PATH", cache_file): + asyncio.run(build_channel_directory({Platform.DISCORD: object()})) + + assert write_threads + assert all(tid != loop_thread for tid in write_threads) + class TestResolveChannelName: def _setup(self, tmp_path, platforms):