From 474c321bf847c2b36a3c48f42e0cf002f5727db6 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 16 Oct 2026 21:53:30 +0000 Subject: [PATCH] test: retry the live head poll while r/all returns an empty listing fetch_head now returns None for an empty listing (#100), which the live comment reader test did not expect, so it failed with a TypeError and blocked the deploy of v3.1.1. Co-Authored-By: Toldry Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_019ddUNNyEKK7YQuAyfKfGwi --- tests/integration/test_reddit_integration.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/tests/integration/test_reddit_integration.py b/tests/integration/test_reddit_integration.py index 95e0e97..070a030 100644 --- a/tests/integration/test_reddit_integration.py +++ b/tests/integration/test_reddit_integration.py @@ -99,6 +99,19 @@ def test_live_main_startup_flow(monkeypatch): mock_start_bot.assert_called_once() +def fetch_head_with_retries(attempts=6, pause_seconds=5): + """Like comment_reader.fetch_head, but tries again while Reddit returns an empty r/all listing. + + The bot itself just skips such a poll (CommentReader.poll_head); the test needs a head to start from. + """ + for _ in range(attempts): + head = comment_reader.fetch_head() + if head is not None: + return head + time.sleep(pause_seconds) + pytest.fail(f'The r/all comment listing was empty {attempts} times in a row') + + @pytest.mark.integration def test_live_comment_reader_reads_recent_comments_by_id(): """Reads 4 blocks of comment IDs just below r/all's newest comment, one per bot account. @@ -108,7 +121,7 @@ def test_live_comment_reader_reads_recent_comments_by_id(): that would read nothing. """ block_count = len(reddit.BOT_NAMES) - first_block = comment_reader.fetch_head() - 10 * comment_reader.BLOCK_SIZE + first_block = fetch_head_with_retries() - 10 * comment_reader.BLOCK_SIZE comments = [] for index, bot_name in enumerate(reddit.BOT_NAMES): comments += comment_reader.fetch_block(bot_name, first_block + index * comment_reader.BLOCK_SIZE)