Skip to content

Commit

Permalink
test_retry_task_map: minor update for faster test
Browse files Browse the repository at this point in the history
  • Loading branch information
Bodong-Yang committed Dec 3, 2024
1 parent 262cffb commit 3639c5f
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion tests/test_otaclient_common/test_retry_task_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
MAX_CONCURRENT = 128
MAX_WAIT_BEFORE_SUCCESS = 10
THREAD_INIT_MSG = "thread init message"
BACKOFF_FACTOR = 0.001 # for faster test
BACKOFF_MAX = 0.1


class _RetryTaskMapTestErr(Exception):
Expand All @@ -47,7 +49,7 @@ def _thread_initializer(msg: str) -> None:
class TestRetryTaskMap:

@pytest.fixture(autouse=True)
def setup(self):
def setup(self) -> None:
self._start_time = time.time()
self._success_wait_dict = {
idx: random.randint(0, MAX_WAIT_BEFORE_SUCCESS)
Expand Down Expand Up @@ -83,6 +85,8 @@ def _exit_on_exceed_max_count():
watchdog_func=_exit_on_exceed_max_count,
initializer=_thread_initializer,
initargs=(THREAD_INIT_MSG,),
backoff_factor=BACKOFF_FACTOR,
backoff_max=BACKOFF_MAX,
) as executor:
with pytest.raises(retry_task_map.TasksEnsureFailed):
for _fut in executor.ensure_tasks(
Expand All @@ -99,6 +103,8 @@ def test_retry_exceed_retry_limit(self):
max_total_retry=MAX_TOTAL_RETRY,
initializer=_thread_initializer,
initargs=(THREAD_INIT_MSG,),
backoff_factor=BACKOFF_FACTOR,
backoff_max=BACKOFF_MAX,
) as executor:
with pytest.raises(retry_task_map.TasksEnsureFailed):
for _fut in executor.ensure_tasks(
Expand All @@ -115,6 +121,8 @@ def test_retry_finally_succeeded(self):
max_concurrent=MAX_CONCURRENT,
initializer=_thread_initializer,
initargs=(THREAD_INIT_MSG,),
backoff_factor=BACKOFF_FACTOR,
backoff_max=BACKOFF_MAX,
) as executor:
for _fut in executor.ensure_tasks(
self.workload_failed_and_then_succeed, range(TASKS_COUNT)
Expand All @@ -130,6 +138,8 @@ def test_succeeded_in_one_try(self):
max_concurrent=MAX_CONCURRENT,
initializer=_thread_initializer,
initargs=(THREAD_INIT_MSG,),
backoff_factor=BACKOFF_FACTOR,
backoff_max=BACKOFF_MAX,
) as executor:
for _fut in executor.ensure_tasks(
self.workload_succeed, range(TASKS_COUNT)
Expand Down

0 comments on commit 3639c5f

Please sign in to comment.