Skip to content
This repository has been archived by the owner on Oct 31, 2023. It is now read-only.

Commit

Permalink
Added unit test, lowered level of logs to debug, tweaked quit after f…
Browse files Browse the repository at this point in the history
…ailing test
  • Loading branch information
maaktweluit committed Sep 11, 2019
1 parent 4b06173 commit edc4ff8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
10 changes: 5 additions & 5 deletions golem/task/requestedtaskmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,20 +359,20 @@ async def abort_task(self, task_id):
await self._shutdown_app_client(task.app_id)

async def quit(self):
logger.info('quit()')
logger.debug('quit()')
# Abort active tasks?

# Shutdown registered app_clients
for app_id, app_client in self._app_clients:
for app_id, app_client in self._app_clients.items():
logger.info('Shutting down app. app_id=%r', app_id)
try:
await app_client.shutdown()
except Exception: # pylint: disable=broad-except
logger.warning("Failed to shutdown app. app_id=%r", app_id)
finally:
del self._app_clients[app_id]

logger.info('quit() - DONE')
self._app_clients.clear()

logger.debug('quit() - DONE')

async def _get_app_client(
self,
Expand Down
13 changes: 13 additions & 0 deletions tests/golem/task/test_requestedtaskmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,19 @@ async def test_task_timeout(self, mock_client):
await asyncio.sleep(task_timeout)
assert self.rtm.is_task_finished(task_id)

@pytest.mark.asyncio
async def test_quit(self, mock_client):
# given
task_id = self._create_task()
await self.rtm.init_task(task_id)

# when
await self.rtm.quit()

# then
mock_client.shutdown.assert_called_once_with()
assert not self.rtm._app_clients

def _build_golem_params(self, task_timeout=1) -> CreateTaskParams:
return CreateTaskParams(
app_id='a',
Expand Down

0 comments on commit edc4ff8

Please sign in to comment.