Skip to content

Commit

Permalink
GPI-1232 Synchronous importer for local sizes
Browse files Browse the repository at this point in the history
  • Loading branch information
mbanczerowski committed Sep 16, 2020
1 parent 0cf447b commit 17b0542
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
13 changes: 13 additions & 0 deletions src/galaxy/api/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,16 @@ async def _import_element(self, id_, context_):
self._notification_failure(id_, UnknownError())
finally:
self._notification_partially_finished(id_)


class SynchroneousImporter(Importer):
async def _import_elements(self, ids_, context_):
try:
for id_ in ids_:
await self._import_element(id_, context_)
self._notification_finished()
self._complete()
except asyncio.CancelledError:
logger.debug("Importing %s cancelled", self._name)
finally:
self._import_in_progress = False
4 changes: 2 additions & 2 deletions src/galaxy/api/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
Subscription, SubscriptionGame
)
from galaxy.task_manager import TaskManager
from galaxy.api.importer import Importer, CollectionImporter
from galaxy.api.importer import Importer, CollectionImporter, SynchroneousImporter


logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -104,7 +104,7 @@ def __init__(self, platform, version, reader, writer, handshake_token):
self._user_presence_import_finished,
self.user_presence_import_complete
)
self._local_size_importer = Importer(
self._local_size_importer = SynchroneousImporter(
self._external_task_manager,
"local size",
self.get_local_size,
Expand Down
19 changes: 11 additions & 8 deletions tests/test_local_size.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ async def test_get_local_size_success(plugin, read, write):
}
read.side_effect = [async_return_value(create_message(request)), async_return_value(b"", 10)]
plugin.get_local_size.side_effect = [
async_return_value(100000000000),
async_return_value(100000000000, 1),
async_return_value(None),
async_return_value(3333333)
]
Expand Down Expand Up @@ -89,12 +89,15 @@ async def test_get_local_size_error(exception, code, message, plugin, read, writ
plugin.get_local_size.assert_called()
plugin.local_size_import_complete.assert_called_once_with()

assert get_messages(write) == [
{
"jsonrpc": "2.0",
"id": request_id,
"result": None
},
direct_response = {
"jsonrpc": "2.0",
"id": request_id,
"result": None
}
responses = get_messages(write)
assert direct_response in responses
responses.remove(direct_response)
assert responses == [
{
"jsonrpc": "2.0",
"method": "local_size_import_failure",
Expand Down Expand Up @@ -145,6 +148,7 @@ async def test_prepare_get_local_size_context_error(plugin, read, write):
@pytest.mark.asyncio
async def test_import_already_in_progress_error(plugin, read, write):
plugin.prepare_local_size_context.return_value = async_return_value(None)
plugin.get_local_size.return_value = async_return_value(100, 5)
requests = [
{
"jsonrpc": "2.0",
Expand Down Expand Up @@ -185,4 +189,3 @@ async def test_import_already_in_progress_error(plugin, read, write):
"message": "Import already in progress"
}
} in responses

0 comments on commit 17b0542

Please sign in to comment.