From 7be769b78acf3a0e0aff8d528476913571d79749 Mon Sep 17 00:00:00 2001 From: Judson Neer Date: Fri, 31 Mar 2023 02:59:14 +0000 Subject: [PATCH] Make all test threads daemons to keep CI/CD from hanging. --- tests/test_general.py | 12 ++++++++---- tests/test_memory_core.py | 24 ++++++++++++++++++------ tests/test_mongo_core.py | 8 ++++++-- tests/test_pickle_core.py | 16 ++++++++++++---- 4 files changed, 44 insertions(+), 16 deletions(-) diff --git a/tests/test_general.py b/tests/test_general.py index 3237ce74..11b0d7a3 100644 --- a/tests/test_general.py +++ b/tests/test_general.py @@ -86,10 +86,12 @@ def _calls_wait_for_calc_timeout_fast(res_queue): res_queue = queue.Queue() thread1 = threading.Thread( target=_calls_wait_for_calc_timeout_fast, - kwargs={'res_queue': res_queue}) + kwargs={'res_queue': res_queue}, + daemon=True) thread2 = threading.Thread( target=_calls_wait_for_calc_timeout_fast, - kwargs={'res_queue': res_queue}) + kwargs={'res_queue': res_queue}, + daemon=True) thread1.start() thread2.start() @@ -124,10 +126,12 @@ def _calls_wait_for_calc_timeout_slow(res_queue): res_queue = queue.Queue() thread1 = threading.Thread( target=_calls_wait_for_calc_timeout_slow, - kwargs={'res_queue': res_queue}) + kwargs={'res_queue': res_queue}, + daemon=True) thread2 = threading.Thread( target=_calls_wait_for_calc_timeout_slow, - kwargs={'res_queue': res_queue}) + kwargs={'res_queue': res_queue}, + daemon=True) thread1.start() thread2.start() diff --git a/tests/test_memory_core.py b/tests/test_memory_core.py index c3ecc5a7..2585b7da 100644 --- a/tests/test_memory_core.py +++ b/tests/test_memory_core.py @@ -172,9 +172,13 @@ def test_memory_being_calculated(): _takes_time.clear_cache() res_queue = queue.Queue() thread1 = threading.Thread( - target=_calls_takes_time, kwargs={'res_queue': res_queue}) + target=_calls_takes_time, + kwargs={'res_queue': res_queue}, + daemon=True) thread2 = threading.Thread( - target=_calls_takes_time, kwargs={'res_queue': res_queue}) + target=_calls_takes_time, + kwargs={'res_queue': res_queue}, + daemon=True) thread1.start() sleep(0.5) thread2.start() @@ -206,9 +210,13 @@ def test_being_calc_next_time(): sleep(1.1) res_queue = queue.Queue() thread1 = threading.Thread( - target=_calls_being_calc_next_time, kwargs={'res_queue': res_queue}) + target=_calls_being_calc_next_time, + kwargs={'res_queue': res_queue}, + daemon=True) thread2 = threading.Thread( - target=_calls_being_calc_next_time, kwargs={'res_queue': res_queue}) + target=_calls_being_calc_next_time, + kwargs={'res_queue': res_queue}, + daemon=True) thread1.start() sleep(0.5) thread2.start() @@ -240,9 +248,13 @@ def test_clear_being_calculated(): _takes_time.clear_cache() res_queue = queue.Queue() thread1 = threading.Thread( - target=_calls_takes_time, kwargs={'res_queue': res_queue}) + target=_calls_takes_time, + kwargs={'res_queue': res_queue}, + daemon=True) thread2 = threading.Thread( - target=_calls_takes_time, kwargs={'res_queue': res_queue}) + target=_calls_takes_time, + kwargs={'res_queue': res_queue}, + daemon=True) thread1.start() _takes_time.clear_being_calculated() sleep(0.5) diff --git a/tests/test_mongo_core.py b/tests/test_mongo_core.py index 340fba8d..5172a68a 100644 --- a/tests/test_mongo_core.py +++ b/tests/test_mongo_core.py @@ -144,9 +144,13 @@ def _takes_time(arg_1, arg_2): _takes_time.clear_cache() res_queue = queue.Queue() thread1 = threading.Thread( - target=_calls_takes_time, kwargs={'res_queue': res_queue}) + target=_calls_takes_time, + kwargs={'res_queue': res_queue}, + daemon=True) thread2 = threading.Thread( - target=_calls_takes_time, kwargs={'res_queue': res_queue}) + target=_calls_takes_time, + kwargs={'res_queue': res_queue}, + daemon=True) thread1.start() sleep(1) thread2.start() diff --git a/tests/test_pickle_core.py b/tests/test_pickle_core.py index 44cab5a4..6a5a7ce6 100644 --- a/tests/test_pickle_core.py +++ b/tests/test_pickle_core.py @@ -222,14 +222,16 @@ def test_pickle_being_calculated(separate_files): kwargs={ 'takes_time_func': _takes_time_decorated, 'res_queue': res_queue, - } + }, + daemon=True, ) thread2 = threading.Thread( target=_calls_takes_time, kwargs={ 'takes_time_func': _takes_time_decorated, 'res_queue': res_queue, - } + }, + daemon=True, ) thread1.start() sleep(0.5) @@ -271,14 +273,16 @@ def test_being_calc_next_time(separate_files): kwargs={ 'being_calc_func': _being_calc_next_time_decorated, 'res_queue': res_queue, - } + }, + daemon=True, ) thread2 = threading.Thread( target=_calls_being_calc_next_time, kwargs={ 'being_calc_func': _being_calc_next_time_decorated, 'res_queue': res_queue, - } + }, + daemon=True, ) thread1.start() sleep(0.5) @@ -339,6 +343,7 @@ def _helper_bad_cache_file(sleeptime, separate_files): 'trash_cache': True, 'separate_files': separate_files, }, + daemon=True, ) thread2 = threading.Thread( target=_calls_bad_cache, @@ -348,6 +353,7 @@ def _helper_bad_cache_file(sleeptime, separate_files): 'trash_cache': False, 'separate_files': separate_files, }, + daemon=True, ) thread1.start() sleep(sleeptime) @@ -427,6 +433,7 @@ def _helper_delete_cache_file(sleeptime, separate_files): 'del_cache': True, 'separate_files': separate_files, }, + daemon=True, ) thread2 = threading.Thread( target=_calls_delete_cache, @@ -436,6 +443,7 @@ def _helper_delete_cache_file(sleeptime, separate_files): 'del_cache': False, 'separate_files': separate_files, }, + daemon=True, ) thread1.start() sleep(sleeptime)