From cd5b70303755d5f952a41e13ab4624599a4ccc90 Mon Sep 17 00:00:00 2001 From: Leigh Morresi <275001+dgtlmoon@users.noreply.github.com> Date: Sun, 21 Feb 2021 20:54:15 +0100 Subject: [PATCH] Add wait for threads in test --- backend/tests/test_backend.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/backend/tests/test_backend.py b/backend/tests/test_backend.py index 23ae20f0..28ef91ac 100644 --- a/backend/tests/test_backend.py +++ b/backend/tests/test_backend.py @@ -38,7 +38,7 @@ def set_modified_response(): def test_check_basic_change_detection_functionality(client, live_server): - sleep_time_for_fetch_thread = 3 + sleep_time_for_fetch_thread = 5 @live_server.app.route('/test-endpoint') def test_endpoint(): @@ -70,12 +70,6 @@ def test_check_basic_change_detection_functionality(client, live_server): assert b'unviewed' not in res.data assert b'test-endpoint' in res.data - # Give the thread time to pick it up - time.sleep(sleep_time_for_fetch_thread) - res = client.get(url_for("index")) - - assert b'unviewed' not in res.data - ##################### # Make a change @@ -98,8 +92,10 @@ def test_check_basic_change_detection_functionality(client, live_server): res = client.get(url_for("diff_history_page", uuid="first") ) assert b'Compare newest' in res.data + time.sleep(2) + # Do this a few times.. ensures we dont accidently set the status - for n in range(2): + for n in range(3): client.get(url_for("api_watch_checknow"), follow_redirects=True) # Give the thread time to pick it up @@ -109,3 +105,11 @@ def test_check_basic_change_detection_functionality(client, live_server): res = client.get(url_for("index")) assert b'unviewed' not in res.data assert b'test-endpoint' in res.data + + + set_original_response() + + client.get(url_for("api_watch_checknow"), follow_redirects=True) + time.sleep(sleep_time_for_fetch_thread) + res = client.get(url_for("index")) + assert b'unviewed' in res.data \ No newline at end of file