2025-02-04 19:18:58 -03:00
|
|
|
from io import BytesIO
|
|
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
from urllib3.util import parse_url
|
|
|
|
|
|
|
|
|
|
from benchmarks.codex.client.async_client import AsyncCodexClientImpl
|
2025-04-18 11:49:43 -03:00
|
|
|
from benchmarks.core.concurrency import await_predicate_async
|
2025-02-04 19:18:58 -03:00
|
|
|
from benchmarks.core.utils.random import random_data
|
|
|
|
|
from benchmarks.core.utils.units import megabytes
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.codex_integration
|
|
|
|
|
@pytest.mark.asyncio
|
|
|
|
|
async def test_should_upload_file(codex_node_1_url: str):
|
|
|
|
|
client = AsyncCodexClientImpl(parse_url(codex_node_1_url))
|
|
|
|
|
|
|
|
|
|
data = BytesIO()
|
|
|
|
|
random_data(megabytes(1), data)
|
|
|
|
|
|
2025-04-16 12:56:34 -03:00
|
|
|
cid = client.upload(
|
|
|
|
|
"test.txt", "application/octet-stream", BytesIO(data.getvalue())
|
|
|
|
|
)
|
2025-02-04 19:18:58 -03:00
|
|
|
assert cid is not None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.codex_integration
|
|
|
|
|
@pytest.mark.asyncio
|
|
|
|
|
async def test_should_download_file(codex_node_1_url: str):
|
|
|
|
|
client = AsyncCodexClientImpl(parse_url(codex_node_1_url))
|
|
|
|
|
|
2025-04-16 12:56:34 -03:00
|
|
|
data = BytesIO()
|
2025-04-18 11:49:43 -03:00
|
|
|
random_data(megabytes(5), data)
|
2025-02-04 19:18:58 -03:00
|
|
|
|
2025-04-16 12:56:34 -03:00
|
|
|
cid = await client.upload(
|
|
|
|
|
"test.txt", "application/octet-stream", BytesIO(data.getvalue())
|
|
|
|
|
)
|
2025-02-04 19:18:58 -03:00
|
|
|
assert cid is not None
|
|
|
|
|
|
2025-04-18 11:49:43 -03:00
|
|
|
manifest = await client.manifest(cid)
|
|
|
|
|
dataset_cid = await client.download(manifest)
|
|
|
|
|
|
|
|
|
|
async def is_complete():
|
|
|
|
|
status = await client.download_status(dataset_cid)
|
|
|
|
|
assert status.total == manifest.block_count
|
|
|
|
|
return status.is_complete()
|
|
|
|
|
|
|
|
|
|
await await_predicate_async(is_complete, timeout=10)
|
2025-02-04 19:18:58 -03:00
|
|
|
|
2025-04-18 11:49:43 -03:00
|
|
|
await client.leave_swarm(dataset_cid)
|