Skip to content

Commit

Permalink
Task termination fix
Browse files Browse the repository at this point in the history
Sometimes the tasks are not terminated on the SIGINT call. This is
caused because termination process will leave tasks which are being
handled by starting method.

It happens when termination starts when some task has been removed from
state machine inside start method. In such case, the state machine will
falsely raise `complete` flag and the termination process will leave
this task untouched.

This commit will fix this issue by comparing the number of completed
tasks with the number of all tasks in suite, which will remove the false
`complete` flag.

Signed-off-by: Jan Richter <[email protected]>
  • Loading branch information
richtja committed Jun 20, 2023
1 parent 471ece1 commit ccb460d
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions avocado/core/task/statemachine.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def __init__(self, tasks, status_repo):
self._finished = []
self._lock = asyncio.Lock()
self._cache_lock = asyncio.Lock()
self._task_size = len(tasks)

self._tasks_by_id = {
str(runtime_task.task.identifier): runtime_task.task
Expand Down Expand Up @@ -62,6 +63,10 @@ def lock(self):
def cache_lock(self):
return self._cache_lock

@property
def task_size(self):
return self._task_size

@property
async def complete(self):
async with self._lock:
Expand Down Expand Up @@ -441,15 +446,17 @@ async def _terminate_tasks(self, task_status):
await self._state_machine.abort(task_status)
terminated = []
while True:
is_complete = await self._state_machine.complete
async with self._state_machine.lock:
try:
runtime_task = self._state_machine.monitored.pop(0)
await self._terminate_task(runtime_task, task_status)
terminated.append(runtime_task)
except IndexError:
if is_complete:
if (
len(self._state_machine.finished) + len(terminated)
== self._state_machine.task_size
):
break
await self._terminate_task(runtime_task, task_status)
terminated.append(runtime_task)
return terminated

async def terminate_tasks_timeout(self):
Expand Down

0 comments on commit ccb460d

Please sign in to comment.