diff --git a/changedetectionio/tests/test_rss_group.py b/changedetectionio/tests/test_rss_group.py index 12d453de4..1f25d6784 100644 --- a/changedetectionio/tests/test_rss_group.py +++ b/changedetectionio/tests/test_rss_group.py @@ -2,7 +2,7 @@ import time from flask import url_for -from .util import live_server_setup, wait_for_all_checks, extract_rss_token_from_UI, get_UUID_for_tag_name, delete_all_watches +from .util import live_server_setup, wait_for_all_checks, wait_for_watch_history, extract_rss_token_from_UI, get_UUID_for_tag_name, delete_all_watches import os @@ -87,6 +87,9 @@ def test_rss_group(client, live_server, measure_memory_usage, datastore_path): # Wait for initial checks to complete wait_for_all_checks(client) + # Ensure initial snapshots are saved + assert wait_for_watch_history(client, min_history_count=1, timeout=10), "Watches did not save initial snapshots" + # Trigger a change set_modified_response(datastore_path=datastore_path) @@ -94,6 +97,9 @@ def test_rss_group(client, live_server, measure_memory_usage, datastore_path): res = client.get(url_for("ui.form_watch_checknow"), follow_redirects=True) wait_for_all_checks(client) + # Ensure all watches have sufficient history for RSS generation + assert wait_for_watch_history(client, min_history_count=2, timeout=10), "Watches did not accumulate sufficient history" + # Get RSS token rss_token = extract_rss_token_from_UI(client) assert rss_token is not None @@ -216,11 +222,13 @@ def test_rss_group_only_unviewed(client, live_server, measure_memory_usage, data assert b"Watch added" in res.data wait_for_all_checks(client) + assert wait_for_watch_history(client, min_history_count=1, timeout=10), "Initial snapshots not saved" # Trigger changes set_modified_response(datastore_path=datastore_path) res = client.get(url_for("ui.form_watch_checknow"), follow_redirects=True) wait_for_all_checks(client) + assert wait_for_watch_history(client, min_history_count=2, timeout=10), "History not accumulated" # Get RSS token rss_token = extract_rss_token_from_UI(client) diff --git a/changedetectionio/tests/util.py b/changedetectionio/tests/util.py index 03e6fa213..2b8dda989 100644 --- a/changedetectionio/tests/util.py +++ b/changedetectionio/tests/util.py @@ -164,8 +164,8 @@ def wait_for_all_checks(client=None): if q_length == 0 and not any_workers_busy: if empty_since is None: empty_since = time.time() - # Longer stabilization period to ensure async workers have finished all updates - elif time.time() - empty_since >= 0.5: # Increased from 0.15 to 0.5 + # Brief stabilization period for async workers + elif time.time() - empty_since >= 0.3: break else: empty_since = None @@ -173,6 +173,36 @@ def wait_for_all_checks(client=None): attempt += 1 time.sleep(0.3) +def wait_for_watch_history(client, min_history_count=2, timeout=10): + """ + Wait for watches to have sufficient history entries. + Useful after wait_for_all_checks() when you need to ensure history is populated. + + Args: + client: Test client with access to datastore + min_history_count: Minimum number of history entries required + timeout: Maximum time to wait in seconds + """ + datastore = client.application.config.get('DATASTORE') + start_time = time.time() + + while time.time() - start_time < timeout: + all_have_history = True + for uuid, watch in datastore.data['watching'].items(): + history_count = len(watch.history.keys()) + if history_count < min_history_count: + all_have_history = False + break + + if all_have_history: + return True + + time.sleep(0.2) + + # Timeout - return False + return False + + # Replaced by new_live_server_setup and calling per function scope in conftest.py def live_server_setup(live_server): return True