From 0df610b411123f1f3e0a67cfe25942d3ff0b5a28 Mon Sep 17 00:00:00 2001 From: Athitheya Gobinathan Date: Fri, 19 Jul 2024 14:58:03 -0400 Subject: [PATCH 01/18] refactor: use signal decorator for timeouts --- tests/tasks/test_tasks.py | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/tests/tasks/test_tasks.py b/tests/tasks/test_tasks.py index 8587683..d884374 100644 --- a/tests/tasks/test_tasks.py +++ b/tests/tasks/test_tasks.py @@ -1,9 +1,11 @@ """Tests for I/O and decryption tasks""" -from time import sleep import json -import requests +import signal +from time import sleep + import pytest +import requests from task_bodies import ( output_dir, @@ -19,6 +21,20 @@ TIME_LIMIT = 60 +def timeout(func): + """Decorator that enforces a time limit on a function.""" + def handler(signum, frame): + raise TimeoutError(f"Task did not complete within {TIME_LIMIT} seconds") + + def wrapper(*args, **kwargs): + signal.signal(signal.SIGALRM, handler) + signal.alarm(TIME_LIMIT) + func(*args, **kwargs) + signal.alarm(0) + + return wrapper + + def create_task(tasks_body): """Creates task with the given task body.""" return requests.post( @@ -35,16 +51,13 @@ def get_task(task_id): def get_task_state(task_id): """Retrieves state of task until completion.""" + @timeout def wait_for_task_completion(): nonlocal task_state - elapsed_seconds = 0 get_response = get_task(task_id) task_state = json.loads(get_response.text)["state"] while task_state in WAIT_STATUSES: - if elapsed_seconds >= TIME_LIMIT: - raise requests.Timeout(f"Task did not complete within {TIME_LIMIT} seconds.") sleep(1) - elapsed_seconds += 1 get_response = get_task(task_id) task_state = json.loads(get_response.text)["state"] @@ -76,14 +89,12 @@ def test_task(post_response, task_state, filename, expected_output): assert post_response.status_code == 200 assert task_state == "COMPLETE" - elapsed_seconds = 0 - while not (output_dir/filename).exists(): - if elapsed_seconds == TIME_LIMIT: - raise FileNotFoundError(f"{filename} did not download to {output_dir} " - f"within {TIME_LIMIT} seconds.") - sleep(1) - elapsed_seconds += 1 + @timeout + def wait_for_file_to_download(): + while not (output_dir/filename).exists(): + sleep(1) + wait_for_file_to_download() with open(output_dir/filename, encoding="utf-8") as f: output = f.read() assert output == expected_output From 59f0b33e23c2b15e298f9d87e3b5b6a66665f8b1 Mon Sep 17 00:00:00 2001 From: Athitheya Gobinathan Date: Fri, 19 Jul 2024 15:00:05 -0400 Subject: [PATCH 02/18] refactor: remove extra whitespace --- tests/tasks/test_tasks.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/tasks/test_tasks.py b/tests/tasks/test_tasks.py index d884374..3451a35 100644 --- a/tests/tasks/test_tasks.py +++ b/tests/tasks/test_tasks.py @@ -34,7 +34,6 @@ def wrapper(*args, **kwargs): return wrapper - def create_task(tasks_body): """Creates task with the given task body.""" return requests.post( From df091c833e062b8e8f7f6ac3d183e358348a2841 Mon Sep 17 00:00:00 2001 From: Athitheya Gobinathan Date: Fri, 19 Jul 2024 15:00:33 -0400 Subject: [PATCH 03/18] revert: add back whitespace --- tests/tasks/test_tasks.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/tasks/test_tasks.py b/tests/tasks/test_tasks.py index 3451a35..d884374 100644 --- a/tests/tasks/test_tasks.py +++ b/tests/tasks/test_tasks.py @@ -34,6 +34,7 @@ def wrapper(*args, **kwargs): return wrapper + def create_task(tasks_body): """Creates task with the given task body.""" return requests.post( From 66e6277fe415dbc9dd3c94398d44cc5ddb99cd0c Mon Sep 17 00:00:00 2001 From: Athitheya Gobinathan Date: Fri, 19 Jul 2024 15:03:05 -0400 Subject: [PATCH 04/18] refactor: move loop out of test --- tests/tasks/test_tasks.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/tests/tasks/test_tasks.py b/tests/tasks/test_tasks.py index d884374..54bf64a 100644 --- a/tests/tasks/test_tasks.py +++ b/tests/tasks/test_tasks.py @@ -66,6 +66,11 @@ def wait_for_task_completion(): return task_state +@timeout +def wait_for_file_to_download(filename): + while not (output_dir/filename).exists(): + sleep(1) + @pytest.fixture(name="post_response") def fixture_post_response(request): """Returns response received after creating task.""" @@ -89,12 +94,8 @@ def test_task(post_response, task_state, filename, expected_output): assert post_response.status_code == 200 assert task_state == "COMPLETE" - @timeout - def wait_for_file_to_download(): - while not (output_dir/filename).exists(): - sleep(1) + wait_for_file_to_download(filename) - wait_for_file_to_download() with open(output_dir/filename, encoding="utf-8") as f: output = f.read() assert output == expected_output From 0900b7ae7ee8cd14946f42db3cd55b51ab5e0c03 Mon Sep 17 00:00:00 2001 From: Athitheya Gobinathan Date: Fri, 19 Jul 2024 15:04:20 -0400 Subject: [PATCH 05/18] docs: add docstring --- tests/tasks/test_tasks.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/tasks/test_tasks.py b/tests/tasks/test_tasks.py index 54bf64a..519bba9 100644 --- a/tests/tasks/test_tasks.py +++ b/tests/tasks/test_tasks.py @@ -68,9 +68,11 @@ def wait_for_task_completion(): @timeout def wait_for_file_to_download(filename): + """Waits for file with given filename to download.""" while not (output_dir/filename).exists(): sleep(1) + @pytest.fixture(name="post_response") def fixture_post_response(request): """Returns response received after creating task.""" From 064ef7b1337ce940f4a61e1fdcfbfb98aff43d0d Mon Sep 17 00:00:00 2001 From: Athitheya Gobinathan Date: Wed, 24 Jul 2024 18:22:39 -0400 Subject: [PATCH 06/18] refactor: remove function --- tests/tasks/test_tasks.py | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/tests/tasks/test_tasks.py b/tests/tasks/test_tasks.py index 519bba9..ecd9e4b 100644 --- a/tests/tasks/test_tasks.py +++ b/tests/tasks/test_tasks.py @@ -35,13 +35,6 @@ def wrapper(*args, **kwargs): return wrapper -def create_task(tasks_body): - """Creates task with the given task body.""" - return requests.post( - url=f"{TES_URL}/tasks", headers=HEADERS, json=tasks_body, timeout=TIME_LIMIT - ) - - def get_task(task_id): """Retrieves list of tasks.""" return requests.get( @@ -76,7 +69,9 @@ def wait_for_file_to_download(filename): @pytest.fixture(name="post_response") def fixture_post_response(request): """Returns response received after creating task.""" - return create_task(request.param) + return requests.post( + url=f"{TES_URL}/tasks", headers=HEADERS, json=request.param, timeout=TIME_LIMIT + ) @pytest.fixture(name="task_state") From 48e1e49da3c8b21bb51eed71251248b7d79f3c38 Mon Sep 17 00:00:00 2001 From: Athitheya Gobinathan Date: Wed, 24 Jul 2024 18:54:54 -0400 Subject: [PATCH 07/18] refactor: merge get_task_state into fixture --- tests/tasks/test_tasks.py | 43 ++++++++++++++++----------------------- 1 file changed, 18 insertions(+), 25 deletions(-) diff --git a/tests/tasks/test_tasks.py b/tests/tasks/test_tasks.py index ecd9e4b..7df34e4 100644 --- a/tests/tasks/test_tasks.py +++ b/tests/tasks/test_tasks.py @@ -35,30 +35,6 @@ def wrapper(*args, **kwargs): return wrapper -def get_task(task_id): - """Retrieves list of tasks.""" - return requests.get( - url=f"{TES_URL}/tasks/{task_id}", headers=HEADERS, timeout=TIME_LIMIT - ) - - -def get_task_state(task_id): - """Retrieves state of task until completion.""" - @timeout - def wait_for_task_completion(): - nonlocal task_state - get_response = get_task(task_id) - task_state = json.loads(get_response.text)["state"] - while task_state in WAIT_STATUSES: - sleep(1) - get_response = get_task(task_id) - task_state = json.loads(get_response.text)["state"] - - task_state = "" - wait_for_task_completion() - return task_state - - @timeout def wait_for_file_to_download(filename): """Waits for file with given filename to download.""" @@ -77,8 +53,25 @@ def fixture_post_response(request): @pytest.fixture(name="task_state") def fixture_task_state(post_response): """Returns state of task after completion.""" + def get_task(): + return requests.get( + url=f"{TES_URL}/tasks/{task_id}", headers=HEADERS, timeout=TIME_LIMIT + ) + + @timeout + def wait_for_task_completion(): + nonlocal task_state + get_response = get_task() + task_state = json.loads(get_response.text)["state"] + while task_state in WAIT_STATUSES: + sleep(1) + get_response = get_task() + task_state = json.loads(get_response.text)["state"] + task_id = json.loads(post_response.text)["id"] - return get_task_state(task_id) + task_state = "" + wait_for_task_completion() + return task_state @pytest.mark.parametrize("post_response,filename,expected_output", [ From f1f464f3a4d10715dd4a7c9227cc3e25cf7f1434 Mon Sep 17 00:00:00 2001 From: Athitheya Gobinathan Date: Thu, 25 Jul 2024 09:38:33 -0400 Subject: [PATCH 08/18] refactor: change post_response to task --- tests/tasks/test_tasks.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/tasks/test_tasks.py b/tests/tasks/test_tasks.py index 7df34e4..f721163 100644 --- a/tests/tasks/test_tasks.py +++ b/tests/tasks/test_tasks.py @@ -42,8 +42,8 @@ def wait_for_file_to_download(filename): sleep(1) -@pytest.fixture(name="post_response") -def fixture_post_response(request): +@pytest.fixture(name="task") +def fixture_task(request): """Returns response received after creating task.""" return requests.post( url=f"{TES_URL}/tasks", headers=HEADERS, json=request.param, timeout=TIME_LIMIT @@ -51,7 +51,7 @@ def fixture_post_response(request): @pytest.fixture(name="task_state") -def fixture_task_state(post_response): +def task_state(task): """Returns state of task after completion.""" def get_task(): return requests.get( @@ -68,20 +68,20 @@ def wait_for_task_completion(): get_response = get_task() task_state = json.loads(get_response.text)["state"] - task_id = json.loads(post_response.text)["id"] + task_id = json.loads(task.text)["id"] task_state = "" wait_for_task_completion() return task_state -@pytest.mark.parametrize("post_response,filename,expected_output", [ +@pytest.mark.parametrize("task,filename,expected_output", [ (uppercase_task_body, "hello-upper.txt", INPUT_TEXT.upper()), (decryption_task_body, "hello-decrypted.txt", INPUT_TEXT), (uppercase_task_with_decryption_body, "hello-upper-decrypt.txt", INPUT_TEXT.upper()) -], indirect=['post_response']) -def test_task(post_response, task_state, filename, expected_output): +], indirect=['task']) +def test_task(task, task_state, filename, expected_output): """Test tasks for successful completion and intended behavior.""" - assert post_response.status_code == 200 + assert task.status_code == 200 assert task_state == "COMPLETE" wait_for_file_to_download(filename) From 9345b2f52494535dd30152757cf85d76bab59cd9 Mon Sep 17 00:00:00 2001 From: Athitheya Gobinathan Date: Thu, 25 Jul 2024 09:41:14 -0400 Subject: [PATCH 09/18] refactor: rename task_state to final_task_state --- tests/tasks/test_tasks.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/tasks/test_tasks.py b/tests/tasks/test_tasks.py index f721163..b342064 100644 --- a/tests/tasks/test_tasks.py +++ b/tests/tasks/test_tasks.py @@ -50,8 +50,8 @@ def fixture_task(request): ) -@pytest.fixture(name="task_state") -def task_state(task): +@pytest.fixture(name="final_task_state") +def fixture_final_task_state(task): """Returns state of task after completion.""" def get_task(): return requests.get( @@ -60,18 +60,18 @@ def get_task(): @timeout def wait_for_task_completion(): - nonlocal task_state + nonlocal final_task_state get_response = get_task() - task_state = json.loads(get_response.text)["state"] - while task_state in WAIT_STATUSES: + final_task_state = json.loads(get_response.text)["state"] + while final_task_state in WAIT_STATUSES: sleep(1) get_response = get_task() - task_state = json.loads(get_response.text)["state"] + final_task_state = json.loads(get_response.text)["state"] task_id = json.loads(task.text)["id"] - task_state = "" + final_task_state = "" wait_for_task_completion() - return task_state + return final_task_state @pytest.mark.parametrize("task,filename,expected_output", [ @@ -79,10 +79,10 @@ def wait_for_task_completion(): (decryption_task_body, "hello-decrypted.txt", INPUT_TEXT), (uppercase_task_with_decryption_body, "hello-upper-decrypt.txt", INPUT_TEXT.upper()) ], indirect=['task']) -def test_task(task, task_state, filename, expected_output): +def test_task(task, final_task_state, filename, expected_output): """Test tasks for successful completion and intended behavior.""" assert task.status_code == 200 - assert task_state == "COMPLETE" + assert final_task_state == "COMPLETE" wait_for_file_to_download(filename) From 4f36f5561a8e235d27b27917494d0743ecf25b5f Mon Sep 17 00:00:00 2001 From: Athitheya Gobinathan Date: Thu, 25 Jul 2024 09:42:09 -0400 Subject: [PATCH 10/18] refactor: remove 'to' --- tests/tasks/test_tasks.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/tasks/test_tasks.py b/tests/tasks/test_tasks.py index b342064..7a21ca6 100644 --- a/tests/tasks/test_tasks.py +++ b/tests/tasks/test_tasks.py @@ -36,7 +36,7 @@ def wrapper(*args, **kwargs): @timeout -def wait_for_file_to_download(filename): +def wait_for_file_download(filename): """Waits for file with given filename to download.""" while not (output_dir/filename).exists(): sleep(1) From ae39209d2f37a2e6db3ae1ded9531b97cd401082 Mon Sep 17 00:00:00 2001 From: Athitheya Gobinathan Date: Thu, 25 Jul 2024 09:45:47 -0400 Subject: [PATCH 11/18] refactor: remove get_task and rename get_response --- tests/tasks/test_tasks.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/tests/tasks/test_tasks.py b/tests/tasks/test_tasks.py index 7a21ca6..93aba76 100644 --- a/tests/tasks/test_tasks.py +++ b/tests/tasks/test_tasks.py @@ -53,20 +53,19 @@ def fixture_task(request): @pytest.fixture(name="final_task_state") def fixture_final_task_state(task): """Returns state of task after completion.""" - def get_task(): - return requests.get( - url=f"{TES_URL}/tasks/{task_id}", headers=HEADERS, timeout=TIME_LIMIT - ) - @timeout def wait_for_task_completion(): nonlocal final_task_state - get_response = get_task() - final_task_state = json.loads(get_response.text)["state"] + task_info = requests.get( + url=f"{TES_URL}/tasks/{task_id}", headers=HEADERS, timeout=TIME_LIMIT + ) + final_task_state = json.loads(task_info.text)["state"] while final_task_state in WAIT_STATUSES: sleep(1) - get_response = get_task() - final_task_state = json.loads(get_response.text)["state"] + task_info = requests.get( + url=f"{TES_URL}/tasks/{task_id}", headers=HEADERS, timeout=TIME_LIMIT + ) + final_task_state = json.loads(task_info.text)["state"] task_id = json.loads(task.text)["id"] final_task_state = "" @@ -84,7 +83,7 @@ def test_task(task, final_task_state, filename, expected_output): assert task.status_code == 200 assert final_task_state == "COMPLETE" - wait_for_file_to_download(filename) + wait_for_file_download(filename) with open(output_dir/filename, encoding="utf-8") as f: output = f.read() From 5c7ed0b8c9932c2851896b5a8f7e90dc3d75cd86 Mon Sep 17 00:00:00 2001 From: Athitheya Gobinathan Date: Thu, 25 Jul 2024 09:56:38 -0400 Subject: [PATCH 12/18] refactor: remove wait_for_task_completion --- tests/tasks/test_tasks.py | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/tests/tasks/test_tasks.py b/tests/tasks/test_tasks.py index 93aba76..7a3a0e7 100644 --- a/tests/tasks/test_tasks.py +++ b/tests/tasks/test_tasks.py @@ -53,24 +53,18 @@ def fixture_task(request): @pytest.fixture(name="final_task_state") def fixture_final_task_state(task): """Returns state of task after completion.""" - @timeout - def wait_for_task_completion(): - nonlocal final_task_state + task_id = json.loads(task.text)["id"] + task_state = "UNKNOWN" + for _ in range(30): task_info = requests.get( url=f"{TES_URL}/tasks/{task_id}", headers=HEADERS, timeout=TIME_LIMIT ) - final_task_state = json.loads(task_info.text)["state"] - while final_task_state in WAIT_STATUSES: - sleep(1) - task_info = requests.get( - url=f"{TES_URL}/tasks/{task_id}", headers=HEADERS, timeout=TIME_LIMIT - ) - final_task_state = json.loads(task_info.text)["state"] + task_state = json.loads(task_info.text)["state"] + if task_state not in WAIT_STATUSES: + break + sleep(1) - task_id = json.loads(task.text)["id"] - final_task_state = "" - wait_for_task_completion() - return final_task_state + return task_state @pytest.mark.parametrize("task,filename,expected_output", [ From 0a8d54fe6dd155ffc56267dc938daed1c6ecadd5 Mon Sep 17 00:00:00 2001 From: Athitheya Gobinathan Date: Thu, 25 Jul 2024 11:39:32 -0400 Subject: [PATCH 13/18] refactor: make fixture and test more concise --- tests/tasks/test_tasks.py | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/tests/tasks/test_tasks.py b/tests/tasks/test_tasks.py index 7a3a0e7..8c6a097 100644 --- a/tests/tasks/test_tasks.py +++ b/tests/tasks/test_tasks.py @@ -50,11 +50,11 @@ def fixture_task(request): ) -@pytest.fixture(name="final_task_state") -def fixture_final_task_state(task): - """Returns state of task after completion.""" +@pytest.fixture(name="final_task_info") +def fixture_final_task_info(task): + """Returns task information after completion.""" task_id = json.loads(task.text)["id"] - task_state = "UNKNOWN" + task_info = None for _ in range(30): task_info = requests.get( url=f"{TES_URL}/tasks/{task_id}", headers=HEADERS, timeout=TIME_LIMIT @@ -64,24 +64,23 @@ def fixture_final_task_state(task): break sleep(1) - return task_state + return json.loads(task_info.text) @pytest.mark.parametrize("task,filename,expected_output", [ (uppercase_task_body, "hello-upper.txt", INPUT_TEXT.upper()), (decryption_task_body, "hello-decrypted.txt", INPUT_TEXT), (uppercase_task_with_decryption_body, "hello-upper-decrypt.txt", INPUT_TEXT.upper()) -], indirect=['task']) -def test_task(task, final_task_state, filename, expected_output): +], indirect=["task"]) +def test_task(task, final_task_info, filename, expected_output): """Test tasks for successful completion and intended behavior.""" assert task.status_code == 200 - assert final_task_state == "COMPLETE" + assert final_task_info["state"] == "COMPLETE" wait_for_file_download(filename) with open(output_dir/filename, encoding="utf-8") as f: output = f.read() assert output == expected_output - assert len(output) == len(expected_output) - if "upper" in filename: - assert output.isupper() + true_result = output.isupper() if "upper" in filename else not output.isupper() + assert true_result From 97af38b41b4e13ef4d68581b6fb97e5f82080822 Mon Sep 17 00:00:00 2001 From: Athitheya Gobinathan Date: Thu, 25 Jul 2024 12:13:04 -0400 Subject: [PATCH 14/18] refactor: move timeout to utils module --- tests/utils.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 tests/utils.py diff --git a/tests/utils.py b/tests/utils.py new file mode 100644 index 0000000..b32edfb --- /dev/null +++ b/tests/utils.py @@ -0,0 +1,20 @@ +""" Utility functions for tests.""" +from functools import wraps +import signal + + +def timeout(time_limit): + """Decorator that enforces a time limit on a function.""" + def handler(signum, frame): + raise TimeoutError(f"Task did not complete within {time_limit} seconds.") + + def decorator(func): + @wraps(func) + def wrapper(*args, **kwargs): + signal.signal(signal.SIGALRM, handler) + signal.alarm(time_limit) + func(*args, **kwargs) + signal.alarm(0) + return wrapper + + return decorator From bc7e1b242cd2d7669531ac55bcc8014f7bce3307 Mon Sep 17 00:00:00 2001 From: Athitheya Gobinathan Date: Thu, 25 Jul 2024 12:14:43 -0400 Subject: [PATCH 15/18] refactor: move timeout decorators to test and fixture --- tests/tasks/test_tasks.py | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-) diff --git a/tests/tasks/test_tasks.py b/tests/tasks/test_tasks.py index 8c6a097..f0c6c57 100644 --- a/tests/tasks/test_tasks.py +++ b/tests/tasks/test_tasks.py @@ -1,7 +1,6 @@ """Tests for I/O and decryption tasks""" import json -import signal from time import sleep import pytest @@ -13,29 +12,14 @@ decryption_task_body, uppercase_task_with_decryption_body ) +from tests.utils import timeout TES_URL = "http://localhost:8090/ga4gh/tes/v1" HEADERS = {"accept": "application/json", "Content-Type": "application/json"} WAIT_STATUSES = ("UNKNOWN", "INITIALIZING", "RUNNING", "QUEUED") INPUT_TEXT = "hello world from the input!" -TIME_LIMIT = 60 -def timeout(func): - """Decorator that enforces a time limit on a function.""" - def handler(signum, frame): - raise TimeoutError(f"Task did not complete within {TIME_LIMIT} seconds") - - def wrapper(*args, **kwargs): - signal.signal(signal.SIGALRM, handler) - signal.alarm(TIME_LIMIT) - func(*args, **kwargs) - signal.alarm(0) - - return wrapper - - -@timeout def wait_for_file_download(filename): """Waits for file with given filename to download.""" while not (output_dir/filename).exists(): @@ -46,18 +30,19 @@ def wait_for_file_download(filename): def fixture_task(request): """Returns response received after creating task.""" return requests.post( - url=f"{TES_URL}/tasks", headers=HEADERS, json=request.param, timeout=TIME_LIMIT + url=f"{TES_URL}/tasks", headers=HEADERS, json=request.param ) @pytest.fixture(name="final_task_info") +@timeout(time_limit=60) def fixture_final_task_info(task): """Returns task information after completion.""" task_id = json.loads(task.text)["id"] task_info = None for _ in range(30): task_info = requests.get( - url=f"{TES_URL}/tasks/{task_id}", headers=HEADERS, timeout=TIME_LIMIT + url=f"{TES_URL}/tasks/{task_id}", headers=HEADERS ) task_state = json.loads(task_info.text)["state"] if task_state not in WAIT_STATUSES: @@ -72,6 +57,7 @@ def fixture_final_task_info(task): (decryption_task_body, "hello-decrypted.txt", INPUT_TEXT), (uppercase_task_with_decryption_body, "hello-upper-decrypt.txt", INPUT_TEXT.upper()) ], indirect=["task"]) +@timeout(time_limit=10) def test_task(task, final_task_info, filename, expected_output): """Test tasks for successful completion and intended behavior.""" assert task.status_code == 200 From cb3e43b3e1d60ee9239a39f6f52174ae393d779a Mon Sep 17 00:00:00 2001 From: Athitheya Gobinathan Date: Thu, 25 Jul 2024 12:25:36 -0400 Subject: [PATCH 16/18] fix: return value of func --- tests/utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/utils.py b/tests/utils.py index b32edfb..fbc38d6 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -13,8 +13,8 @@ def decorator(func): def wrapper(*args, **kwargs): signal.signal(signal.SIGALRM, handler) signal.alarm(time_limit) - func(*args, **kwargs) + result = func(*args, **kwargs) signal.alarm(0) + return result return wrapper - return decorator From 3792d50eefe66055cc0d3630b4893cf4f92565e2 Mon Sep 17 00:00:00 2001 From: Athitheya Gobinathan Date: Thu, 25 Jul 2024 12:28:38 -0400 Subject: [PATCH 17/18] fix: ignore missing timeout error --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 1cbdd35..5e39927 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -22,4 +22,4 @@ pylint = "*" mypy = "*" [tool.pylint."MESSAGES CONTROL"] -disable = ["logging-fstring-interpolation"] +disable = ["logging-fstring-interpolation", "missing-timeout"] From b97f02b43636d0d58909796254519f502c0260f5 Mon Sep 17 00:00:00 2001 From: Athitheya Gobinathan Date: Thu, 25 Jul 2024 13:01:33 -0400 Subject: [PATCH 18/18] refactor: move assertion to fixture --- tests/tasks/test_tasks.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/tasks/test_tasks.py b/tests/tasks/test_tasks.py index f0c6c57..3e6660f 100644 --- a/tests/tasks/test_tasks.py +++ b/tests/tasks/test_tasks.py @@ -38,6 +38,7 @@ def fixture_task(request): @timeout(time_limit=60) def fixture_final_task_info(task): """Returns task information after completion.""" + assert task.status_code == 200 task_id = json.loads(task.text)["id"] task_info = None for _ in range(30): @@ -58,9 +59,8 @@ def fixture_final_task_info(task): (uppercase_task_with_decryption_body, "hello-upper-decrypt.txt", INPUT_TEXT.upper()) ], indirect=["task"]) @timeout(time_limit=10) -def test_task(task, final_task_info, filename, expected_output): +def test_task(task, final_task_info, filename, expected_output): # pylint: disable=unused-argument """Test tasks for successful completion and intended behavior.""" - assert task.status_code == 200 assert final_task_info["state"] == "COMPLETE" wait_for_file_download(filename)