diff --git a/changedetectionio/tests/fetchers/test_content.py b/changedetectionio/tests/fetchers/test_content.py index b68e71231..76b78ce82 100644 --- a/changedetectionio/tests/fetchers/test_content.py +++ b/changedetectionio/tests/fetchers/test_content.py @@ -28,8 +28,6 @@ def test_fetch_webdriver_content(client, live_server): ) assert b"1 Imported" in res.data - time.sleep(3) - wait_for_all_checks(client) diff --git a/changedetectionio/tests/proxy_list/test_proxy.py b/changedetectionio/tests/proxy_list/test_proxy.py index 1f4c5ff41..2da09fc0b 100644 --- a/changedetectionio/tests/proxy_list/test_proxy.py +++ b/changedetectionio/tests/proxy_list/test_proxy.py @@ -16,4 +16,4 @@ def test_check_basic_change_detection_functionality(client, live_server): ) assert b"1 Imported" in res.data - time.sleep(3) + wait_for_all_checks(client) diff --git a/changedetectionio/tests/restock/test_restock.py b/changedetectionio/tests/restock/test_restock.py index d00fed10f..77557918e 100644 --- a/changedetectionio/tests/restock/test_restock.py +++ b/changedetectionio/tests/restock/test_restock.py @@ -94,7 +94,7 @@ def test_restock_detection(client, live_server): assert b'not-in-stock' not in res.data # We should have a notification - time.sleep(2) + wait_for_all_checks(client) assert os.path.isfile("test-datastore/notification.txt") os.unlink("test-datastore/notification.txt") diff --git a/changedetectionio/tests/test_access_control.py b/changedetectionio/tests/test_access_control.py index b8063683a..2f6c403d1 100644 --- a/changedetectionio/tests/test_access_control.py +++ b/changedetectionio/tests/test_access_control.py @@ -1,4 +1,4 @@ -from . util import live_server_setup, extract_UUID_from_client +from .util import live_server_setup, extract_UUID_from_client, wait_for_all_checks from flask import url_for import time @@ -19,10 +19,10 @@ def test_check_access_control(app, client, live_server): ) assert b"1 Imported" in res.data - time.sleep(2) + wait_for_all_checks(client) res = client.get(url_for("form_watch_checknow"), follow_redirects=True) assert b'1 watches queued for rechecking.' in res.data - time.sleep(2) + wait_for_all_checks(client) # Enable password check and diff page access bypass res = c.post( diff --git a/changedetectionio/tests/test_add_replace_remove_filter.py b/changedetectionio/tests/test_add_replace_remove_filter.py index 4ad9ecf86..5562a23bd 100644 --- a/changedetectionio/tests/test_add_replace_remove_filter.py +++ b/changedetectionio/tests/test_add_replace_remove_filter.py @@ -41,7 +41,6 @@ def test_setup(client, live_server): def test_check_removed_line_contains_trigger(client, live_server): # Give the endpoint time to spin up - time.sleep(1) set_original() # Add our URL to the import page test_url = url_for('test_endpoint', _external=True) diff --git a/changedetectionio/tests/test_api.py b/changedetectionio/tests/test_api.py index c19812abc..3f2f53402 100644 --- a/changedetectionio/tests/test_api.py +++ b/changedetectionio/tests/test_api.py @@ -267,7 +267,7 @@ def test_api_watch_PUT_update(client, live_server): #live_server_setup(live_server) api_key = extract_api_key_from_UI(client) - time.sleep(1) + wait_for_all_checks(client) # Create a watch set_original_response() test_url = url_for('test_endpoint', _external=True, @@ -283,7 +283,7 @@ def test_api_watch_PUT_update(client, live_server): assert res.status_code == 201 - time.sleep(1) + wait_for_all_checks(client) # Get a listing, it will be the first one res = client.get( diff --git a/changedetectionio/tests/test_auth.py b/changedetectionio/tests/test_auth.py index b84f8cf71..40e208f07 100644 --- a/changedetectionio/tests/test_auth.py +++ b/changedetectionio/tests/test_auth.py @@ -19,7 +19,7 @@ def test_basic_auth(client, live_server): follow_redirects=True ) assert b"1 Imported" in res.data - time.sleep(1) + wait_for_all_checks(client) # Check form validation res = client.post( @@ -29,7 +29,7 @@ def test_basic_auth(client, live_server): ) assert b"Updated watch." in res.data - time.sleep(1) + wait_for_all_checks(client) res = client.get( url_for("preview_page", uuid="first"), follow_redirects=True diff --git a/changedetectionio/tests/test_automatic_follow_ldjson_price.py b/changedetectionio/tests/test_automatic_follow_ldjson_price.py index c95e8fcf0..026a791ea 100644 --- a/changedetectionio/tests/test_automatic_follow_ldjson_price.py +++ b/changedetectionio/tests/test_automatic_follow_ldjson_price.py @@ -2,7 +2,8 @@ import time from flask import url_for -from .util import live_server_setup, extract_UUID_from_client, extract_api_key_from_UI +from .util import live_server_setup, extract_UUID_from_client, extract_api_key_from_UI, wait_for_all_checks + def set_response_with_ldjson(): test_return_data = """ @@ -92,7 +93,7 @@ def test_check_ldjson_price_autodetect(client, live_server): follow_redirects=True ) assert b"1 Imported" in res.data - time.sleep(3) + wait_for_all_checks(client) # Should get a notice that it's available res = client.get(url_for("index")) @@ -102,11 +103,11 @@ def test_check_ldjson_price_autodetect(client, live_server): uuid = extract_UUID_from_client(client) client.get(url_for('price_data_follower.accept', uuid=uuid, follow_redirects=True)) - time.sleep(2) + wait_for_all_checks(client) # Trigger a check client.get(url_for("form_watch_checknow"), follow_redirects=True) - time.sleep(2) + wait_for_all_checks(client) # Offer should be gone res = client.get(url_for("index")) assert b'Embedded price data' not in res.data @@ -138,7 +139,7 @@ def test_check_ldjson_price_autodetect(client, live_server): follow_redirects=True ) assert b"1 Imported" in res.data - time.sleep(3) + wait_for_all_checks(client) res = client.get(url_for("index")) assert b'ldjson-price-track-offer' not in res.data diff --git a/changedetectionio/tests/test_backend.py b/changedetectionio/tests/test_backend.py index 03c135fcf..ea7212201 100644 --- a/changedetectionio/tests/test_backend.py +++ b/changedetectionio/tests/test_backend.py @@ -28,8 +28,7 @@ def test_check_basic_change_detection_functionality(client, live_server): ) assert b"1 Imported" in res.data - - time.sleep(sleep_time_for_fetch_thread) + wait_for_all_checks(client) # Do this a few times.. ensures we dont accidently set the status for n in range(3): diff --git a/changedetectionio/tests/test_backup.py b/changedetectionio/tests/test_backup.py index 89fd66a5d..777fbfc52 100644 --- a/changedetectionio/tests/test_backup.py +++ b/changedetectionio/tests/test_backup.py @@ -1,6 +1,6 @@ #!/usr/bin/python3 -from .util import set_original_response, set_modified_response, live_server_setup +from .util import set_original_response, set_modified_response, live_server_setup, wait_for_all_checks from flask import url_for from urllib.request import urlopen from zipfile import ZipFile @@ -24,7 +24,7 @@ def test_backup(client, live_server): ) assert b"1 Imported" in res.data - time.sleep(3) + wait_for_all_checks(client) res = client.get( url_for("get_backup"), diff --git a/changedetectionio/tests/test_css_selector.py b/changedetectionio/tests/test_css_selector.py index 0dfe2af78..fd40299d3 100644 --- a/changedetectionio/tests/test_css_selector.py +++ b/changedetectionio/tests/test_css_selector.py @@ -2,7 +2,7 @@ import time from flask import url_for -from . util import live_server_setup +from .util import live_server_setup, wait_for_all_checks from ..html_tools import * @@ -90,7 +90,7 @@ def test_check_markup_include_filters_restriction(client, live_server): assert b"1 Imported" in res.data # Give the thread time to pick it up - time.sleep(sleep_time_for_fetch_thread) + wait_for_all_checks(client) # Goto the edit page, add our ignore text # Add our URL to the import page @@ -100,7 +100,7 @@ def test_check_markup_include_filters_restriction(client, live_server): follow_redirects=True ) assert b"Updated watch." in res.data - time.sleep(1) + wait_for_all_checks(client) # Check it saved res = client.get( url_for("edit_page", uuid="first"), @@ -108,14 +108,14 @@ def test_check_markup_include_filters_restriction(client, live_server): assert bytes(include_filters.encode('utf-8')) in res.data # Give the thread time to pick it up - time.sleep(sleep_time_for_fetch_thread) + wait_for_all_checks(client) # Make a change set_modified_response() # Trigger a check client.get(url_for("form_watch_checknow"), follow_redirects=True) # Give the thread time to pick it up - time.sleep(sleep_time_for_fetch_thread) + wait_for_all_checks(client) # It should have 'unviewed' still # Because it should be looking at only that 'sametext' id @@ -139,7 +139,7 @@ def test_check_multiple_filters(client, live_server): """) # Give the endpoint time to spin up - time.sleep(1) + wait_for_all_checks(client) # Add our URL to the import page test_url = url_for('test_endpoint', _external=True) @@ -149,7 +149,7 @@ def test_check_multiple_filters(client, live_server): follow_redirects=True ) assert b"1 Imported" in res.data - time.sleep(1) + wait_for_all_checks(client) # Goto the edit page, add our ignore text # Add our URL to the import page @@ -165,7 +165,7 @@ def test_check_multiple_filters(client, live_server): assert b"Updated watch." in res.data # Give the thread time to pick it up - time.sleep(sleep_time_for_fetch_thread) + wait_for_all_checks(client) res = client.get( url_for("preview_page", uuid="first"), diff --git a/changedetectionio/tests/test_element_removal.py b/changedetectionio/tests/test_element_removal.py index 3c280d221..a084b6f2d 100644 --- a/changedetectionio/tests/test_element_removal.py +++ b/changedetectionio/tests/test_element_removal.py @@ -5,7 +5,7 @@ import time from flask import url_for from ..html_tools import * -from .util import live_server_setup +from .util import live_server_setup, wait_for_all_checks def test_setup(live_server): @@ -120,7 +120,7 @@ def test_element_removal_full(client, live_server): url_for("import_page"), data={"urls": test_url}, follow_redirects=True ) assert b"1 Imported" in res.data - time.sleep(1) + wait_for_all_checks(client) # Goto the edit page, add the filter data # Not sure why \r needs to be added - absent of the #changetext this is not necessary subtractive_selectors_data = "header\r\nfooter\r\nnav\r\n#changetext" @@ -147,7 +147,7 @@ def test_element_removal_full(client, live_server): client.get(url_for("form_watch_checknow"), follow_redirects=True) # Give the thread time to pick it up - time.sleep(sleep_time_for_fetch_thread) + wait_for_all_checks(client) # so that we set the state to 'unviewed' after all the edits client.get(url_for("diff_history_page", uuid="first")) diff --git a/changedetectionio/tests/test_errorhandling.py b/changedetectionio/tests/test_errorhandling.py index bd3d9d6f7..5054c69a4 100644 --- a/changedetectionio/tests/test_errorhandling.py +++ b/changedetectionio/tests/test_errorhandling.py @@ -3,7 +3,7 @@ import time from flask import url_for -from . util import live_server_setup +from .util import live_server_setup, wait_for_all_checks from ..html_tools import * @@ -30,7 +30,7 @@ def _runner_test_http_errors(client, live_server, http_code, expected_text): assert b"1 Imported" in res.data # Give the thread time to pick it up - time.sleep(2) + wait_for_all_checks(client) res = client.get(url_for("index")) # no change @@ -76,7 +76,7 @@ def test_DNS_errors(client, live_server): assert b"1 Imported" in res.data # Give the thread time to pick it up - time.sleep(3) + wait_for_all_checks(client) res = client.get(url_for("index")) found_name_resolution_error = b"Temporary failure in name resolution" in res.data or b"Name or service not known" in res.data @@ -90,7 +90,7 @@ def test_DNS_errors(client, live_server): def test_low_level_errors_clear_correctly(client, live_server): #live_server_setup(live_server) # Give the endpoint time to spin up - time.sleep(1) + #time.sleep(1) with open("test-datastore/endpoint-content.txt", "w") as f: f.write("
Hello world
") @@ -104,7 +104,7 @@ def test_low_level_errors_clear_correctly(client, live_server): follow_redirects=True ) assert b"1 Imported" in res.data - time.sleep(2) + wait_for_all_checks(client) # We should see the DNS error res = client.get(url_for("index")) @@ -121,7 +121,7 @@ def test_low_level_errors_clear_correctly(client, live_server): ) # Now the error should be gone - time.sleep(2) + wait_for_all_checks(client) res = client.get(url_for("index")) found_name_resolution_error = b"Temporary failure in name resolution" in res.data or b"Name or service not known" in res.data assert not found_name_resolution_error diff --git a/changedetectionio/tests/test_extract_regex.py b/changedetectionio/tests/test_extract_regex.py index fec939f1c..75a8e2ce0 100644 --- a/changedetectionio/tests/test_extract_regex.py +++ b/changedetectionio/tests/test_extract_regex.py @@ -2,7 +2,7 @@ import time from flask import url_for -from .util import live_server_setup +from .util import live_server_setup, wait_for_all_checks from ..html_tools import * @@ -82,7 +82,7 @@ def test_check_filter_multiline(client, live_server): ) assert b"1 Imported" in res.data - time.sleep(3) + wait_for_all_checks(client) # Goto the edit page, add our ignore text # Add our URL to the import page @@ -99,7 +99,7 @@ def test_check_filter_multiline(client, live_server): ) assert b"Updated watch." in res.data - time.sleep(3) + wait_for_all_checks(client) res = client.get( url_for("preview_page", uuid="first"), @@ -132,12 +132,12 @@ def test_check_filter_and_regex_extract(client, live_server): ) assert b"1 Imported" in res.data - time.sleep(1) + wait_for_all_checks(client) # Trigger a check client.get(url_for("form_watch_checknow"), follow_redirects=True) # Give the thread time to pick it up - time.sleep(sleep_time_for_fetch_thread) + wait_for_all_checks(client) # Goto the edit page, add our ignore text # Add our URL to the import page @@ -156,7 +156,7 @@ def test_check_filter_and_regex_extract(client, live_server): assert b"Updated watch." in res.data # Give the thread time to pick it up - time.sleep(sleep_time_for_fetch_thread) + wait_for_all_checks(client) # Make a change set_modified_response() @@ -164,7 +164,7 @@ def test_check_filter_and_regex_extract(client, live_server): # Trigger a check client.get(url_for("form_watch_checknow"), follow_redirects=True) # Give the thread time to pick it up - time.sleep(sleep_time_for_fetch_thread) + wait_for_all_checks(client) # It should have 'unviewed' still # Because it should be looking at only that 'sametext' id diff --git a/changedetectionio/tests/test_filter_exist_changes.py b/changedetectionio/tests/test_filter_exist_changes.py index 24f84455e..50d4c916b 100644 --- a/changedetectionio/tests/test_filter_exist_changes.py +++ b/changedetectionio/tests/test_filter_exist_changes.py @@ -4,7 +4,7 @@ import os import time from flask import url_for -from .util import set_original_response, live_server_setup +from .util import set_original_response, live_server_setup, wait_for_all_checks from changedetectionio.model import App @@ -62,7 +62,7 @@ def test_filter_doesnt_exist_then_exists_should_get_notification(client, live_se assert b"Watch added" in res.data # Give the thread time to pick up the first version - time.sleep(3) + wait_for_all_checks(client) # Goto the edit page, add our ignore text # Add our URL to the import page @@ -101,14 +101,14 @@ def test_filter_doesnt_exist_then_exists_should_get_notification(client, live_se follow_redirects=True ) assert b"Updated watch." in res.data - time.sleep(3) + wait_for_all_checks(client) # Shouldn't exist, shouldn't have fired assert not os.path.isfile("test-datastore/notification.txt") # Now the filter should exist set_response_with_filter() client.get(url_for("form_watch_checknow"), follow_redirects=True) - time.sleep(3) + wait_for_all_checks(client) assert os.path.isfile("test-datastore/notification.txt") diff --git a/changedetectionio/tests/test_ignorehyperlinks.py b/changedetectionio/tests/test_ignorehyperlinks.py index f917125f3..0ba7a57fb 100644 --- a/changedetectionio/tests/test_ignorehyperlinks.py +++ b/changedetectionio/tests/test_ignorehyperlinks.py @@ -3,7 +3,7 @@ import time from flask import url_for -from .util import live_server_setup +from .util import live_server_setup, wait_for_all_checks def test_setup(live_server): @@ -70,19 +70,19 @@ def test_render_anchor_tag_content_true(client, live_server): ) assert b"1 Imported" in res.data - time.sleep(sleep_time_for_fetch_thread) + wait_for_all_checks(client) # Trigger a check client.get(url_for("form_watch_checknow"), follow_redirects=True) # set a new html text with a modified link set_modified_ignore_response() - time.sleep(sleep_time_for_fetch_thread) + wait_for_all_checks(client) # Trigger a check client.get(url_for("form_watch_checknow"), follow_redirects=True) # Give the thread time to pick it up - time.sleep(sleep_time_for_fetch_thread) + wait_for_all_checks(client) # We should not see the rendered anchor tag res = client.get(url_for("preview_page", uuid="first")) @@ -104,7 +104,7 @@ def test_render_anchor_tag_content_true(client, live_server): client.get(url_for("form_watch_checknow"), follow_redirects=True) # Give the thread time to pick it up - time.sleep(sleep_time_for_fetch_thread) + wait_for_all_checks(client) diff --git a/changedetectionio/tests/test_ignorewhitespace.py b/changedetectionio/tests/test_ignorewhitespace.py index a0db9ead6..d9cff52c5 100644 --- a/changedetectionio/tests/test_ignorewhitespace.py +++ b/changedetectionio/tests/test_ignorewhitespace.py @@ -2,7 +2,8 @@ import time from flask import url_for -from . util import live_server_setup +from .util import live_server_setup, wait_for_all_checks + def test_setup(live_server): live_server_setup(live_server) @@ -50,7 +51,6 @@ def set_original_ignore_response(): # If there was only a change in the whitespacing, then we shouldnt have a change detected def test_check_ignore_whitespace(client, live_server): - sleep_time_for_fetch_thread = 3 # Give the endpoint time to spin up time.sleep(1) @@ -78,17 +78,17 @@ def test_check_ignore_whitespace(client, live_server): ) assert b"1 Imported" in res.data - time.sleep(sleep_time_for_fetch_thread) + wait_for_all_checks(client) # Trigger a check client.get(url_for("form_watch_checknow"), follow_redirects=True) set_original_ignore_response_but_with_whitespace() - time.sleep(sleep_time_for_fetch_thread) + wait_for_all_checks(client) # Trigger a check client.get(url_for("form_watch_checknow"), follow_redirects=True) # Give the thread time to pick it up - time.sleep(sleep_time_for_fetch_thread) + wait_for_all_checks(client) # It should report nothing found (no new 'unviewed' class) res = client.get(url_for("index")) diff --git a/changedetectionio/tests/test_rss.py b/changedetectionio/tests/test_rss.py index 30db6a209..ed01f9328 100644 --- a/changedetectionio/tests/test_rss.py +++ b/changedetectionio/tests/test_rss.py @@ -19,9 +19,9 @@ def test_rss_and_token(client, live_server): assert b"1 Imported" in res.data rss_token = extract_rss_token_from_UI(client) - time.sleep(2) + wait_for_all_checks(client) client.get(url_for("form_watch_checknow"), follow_redirects=True) - time.sleep(2) + wait_for_all_checks(client) # Add our URL to the import page res = client.get( diff --git a/changedetectionio/tests/test_xpath_selector.py b/changedetectionio/tests/test_xpath_selector.py index fa8f4e8d0..5802fe029 100644 --- a/changedetectionio/tests/test_xpath_selector.py +++ b/changedetectionio/tests/test_xpath_selector.py @@ -2,7 +2,7 @@ import time from flask import url_for -from . util import live_server_setup +from .util import live_server_setup, wait_for_all_checks from ..html_tools import * @@ -86,7 +86,7 @@ def test_check_xpath_filter_utf8(client, live_server): follow_redirects=True ) assert b"1 Imported" in res.data - time.sleep(1) + wait_for_all_checks(client) res = client.post( url_for("edit_page", uuid="first"), data={"include_filters": filter, "url": test_url, "tags": "", "headers": "", 'fetch_backend': "html_requests"}, @@ -140,14 +140,14 @@ def test_check_xpath_text_function_utf8(client, live_server): follow_redirects=True ) assert b"1 Imported" in res.data - time.sleep(1) + wait_for_all_checks(client) res = client.post( url_for("edit_page", uuid="first"), data={"include_filters": filter, "url": test_url, "tags": "", "headers": "", 'fetch_backend': "html_requests"}, follow_redirects=True ) assert b"Updated watch." in res.data - time.sleep(3) + wait_for_all_checks(client) res = client.get(url_for("index")) assert b'Unicode strings with encoding declaration are not supported.' not in res.data @@ -183,7 +183,7 @@ def test_check_markup_xpath_filter_restriction(client, live_server): assert b"1 Imported" in res.data # Give the thread time to pick it up - time.sleep(sleep_time_for_fetch_thread) + wait_for_all_checks(client) # Goto the edit page, add our ignore text # Add our URL to the import page @@ -195,7 +195,7 @@ def test_check_markup_xpath_filter_restriction(client, live_server): assert b"Updated watch." in res.data # Give the thread time to pick it up - time.sleep(sleep_time_for_fetch_thread) + wait_for_all_checks(client) # view it/reset state back to viewed client.get(url_for("diff_history_page", uuid="first"), follow_redirects=True) @@ -206,7 +206,7 @@ def test_check_markup_xpath_filter_restriction(client, live_server): # Trigger a check client.get(url_for("form_watch_checknow"), follow_redirects=True) # Give the thread time to pick it up - time.sleep(sleep_time_for_fetch_thread) + wait_for_all_checks(client) res = client.get(url_for("index")) assert b'unviewed' not in res.data @@ -216,9 +216,6 @@ def test_check_markup_xpath_filter_restriction(client, live_server): def test_xpath_validation(client, live_server): - # Give the endpoint time to spin up - time.sleep(1) - # Add our URL to the import page test_url = url_for('test_endpoint', _external=True) res = client.post( @@ -227,7 +224,7 @@ def test_xpath_validation(client, live_server): follow_redirects=True ) assert b"1 Imported" in res.data - time.sleep(2) + wait_for_all_checks(client) res = client.post( url_for("edit_page", uuid="first"), @@ -257,7 +254,7 @@ def test_check_with_prefix_include_filters(client, live_server): follow_redirects=True ) assert b"1 Imported" in res.data - time.sleep(3) + wait_for_all_checks(client) res = client.post( url_for("edit_page", uuid="first"), @@ -266,7 +263,7 @@ def test_check_with_prefix_include_filters(client, live_server): ) assert b"Updated watch." in res.data - time.sleep(3) + wait_for_all_checks(client) res = client.get( url_for("preview_page", uuid="first"), diff --git a/changedetectionio/tests/util.py b/changedetectionio/tests/util.py index 13e3fff9d..45ab204b3 100644 --- a/changedetectionio/tests/util.py +++ b/changedetectionio/tests/util.py @@ -107,7 +107,7 @@ def wait_for_all_checks(client): attempt=0 time.sleep(0.1) while attempt < 60: - time.sleep(1) + time.sleep(0.5) res = client.get(url_for("index")) if not b'Checking now' in res.data: break