Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
bisgaard-itis committed Nov 19, 2024
1 parent 12c94fe commit 367728d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
2 changes: 1 addition & 1 deletion clients/python/src/osparc/_api_files_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ async def upload_file_async(
)
)
)
while (len(upload_tasks) > max_concurrent_uploads) or (
while (len(upload_tasks) >= max_concurrent_uploads) or (
chunk.is_last_chunk and len(upload_tasks) > 0
):
done, upload_tasks = await asyncio.wait(
Expand Down
12 changes: 10 additions & 2 deletions clients/python/test/e2e/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from packaging.version import Version
from pydantic import ByteSize
from typing import NamedTuple, Final
from memory_profiler import memory_usage

try:
from osparc._settings import ConfigurationEnvVars
Expand Down Expand Up @@ -140,6 +141,7 @@ def async_client() -> Iterable[AsyncClient]:
class ServerFile(NamedTuple):
server_file: osparc.File
local_file: Path
upload_ram_usage: int


@pytest.fixture(scope="session")
Expand All @@ -160,9 +162,15 @@ def large_server_file(
assert (
tmp_file.stat().st_size == _file_size
), f"Could not create file of size: {_file_size}"
uploaded_file: osparc.File = files_api.upload_file(tmp_file)
ram_statistics, uploaded_file = memory_usage(
(files_api.upload_file, (tmp_file,), {"max_concurrent_uploads": 5}), retval=True
)

yield ServerFile(local_file=tmp_file, server_file=uploaded_file)
yield ServerFile(
local_file=tmp_file,
server_file=uploaded_file,
upload_ram_usage=max(ram_statistics) - min(ram_statistics),
)

files_api.delete_file(uploaded_file.id)

Expand Down
21 changes: 9 additions & 12 deletions clients/python/test/e2e/test_files_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from osparc._utils import PaginationIterator
import pytest
from memory_profiler import memory_usage
from typing import Final, List, Callable
from typing import Final, Callable
from pydantic import ByteSize
from _utils import skip_if_osparc_version
from packaging.version import Version
Expand Down Expand Up @@ -52,25 +52,21 @@ def test_upload_download_file_ram_usage(
tmp_path: Path, large_server_file: ServerFile, files_api: osparc.FilesApi
) -> None:
"""Check RAM usage of upload/download fcns"""
_allowed_ram_usage_in_mb: Final[int] = 300 # 300MB
_allowed_ram_usage_in_mb: Final[int] = 1000 # 1000MB
assert (
large_server_file.local_file.stat().st_size
> _allowed_ram_usage_in_mb * 1024 * 1024
), f"For this test to make sense, {large_server_file.local_file.stat().st_size=} must be larger than {_allowed_ram_usage_in_mb=}."

def max_diff(data: List[int]) -> int:
return max(data) - min(data)
assert (
large_server_file.upload_ram_usage < _allowed_ram_usage_in_mb
), f"Used more than {_allowed_ram_usage_in_mb=} to upload file of size {large_server_file.local_file.stat().st_size=}"

upload_ram_usage_in_mb, uploaded_file = memory_usage(
(files_api.upload_file, (large_server_file.local_file,)), # type: ignore
retval=True,
)
uploaded_file = files_api.upload_file(large_server_file.local_file)
assert (
large_server_file.server_file.id == uploaded_file.id
), "could not detect that file was already on server"
assert (
max_diff(upload_ram_usage_in_mb) < _allowed_ram_usage_in_mb
), f"Used more than {_allowed_ram_usage_in_mb=} to upload file of size {large_server_file.local_file.stat().st_size=}"

download_ram_usage_in_mb, downloaded_file = memory_usage(
(
files_api.download_file,
Expand All @@ -81,7 +77,8 @@ def max_diff(data: List[int]) -> int:
)
assert Path(downloaded_file).parent == tmp_path
assert (
max_diff(download_ram_usage_in_mb) < _allowed_ram_usage_in_mb
max(download_ram_usage_in_mb) - min(download_ram_usage_in_mb)
< _allowed_ram_usage_in_mb
), f"Used more than {_allowed_ram_usage_in_mb=} to download file of size {Path(downloaded_file).stat().st_size=}"
assert _hash_file(Path(downloaded_file)) == _hash_file(large_server_file.local_file)

Expand Down

0 comments on commit 367728d

Please sign in to comment.