-
Notifications
You must be signed in to change notification settings - Fork 248
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[hailtop] ensure delete also deletes single files (#14345)
I rearranged some fixtures as well.
- Loading branch information
Showing
6 changed files
with
106 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
from typing import Tuple, AsyncIterator, Dict | ||
import secrets | ||
import os | ||
import pytest | ||
import asyncio | ||
import functools | ||
from hailtop.utils import bounded_gather2 | ||
from hailtop.aiotools.router_fs import RouterAsyncFS, AsyncFS | ||
|
||
|
||
@pytest.fixture(scope='module') | ||
async def router_filesystem() -> AsyncIterator[Tuple[asyncio.Semaphore, AsyncFS, Dict[str, str]]]: | ||
token = secrets.token_hex(16) | ||
|
||
async with RouterAsyncFS() as fs: | ||
file_base = f'/tmp/{token}/' | ||
await fs.mkdir(file_base) | ||
|
||
gs_bucket = os.environ['HAIL_TEST_GCS_BUCKET'] | ||
gs_base = f'gs://{gs_bucket}/tmp/{token}/' | ||
|
||
s3_bucket = os.environ['HAIL_TEST_S3_BUCKET'] | ||
s3_base = f's3://{s3_bucket}/tmp/{token}/' | ||
|
||
azure_account = os.environ['HAIL_TEST_AZURE_ACCOUNT'] | ||
azure_container = os.environ['HAIL_TEST_AZURE_CONTAINER'] | ||
azure_base = f'https://{azure_account}.blob.core.windows.net/{azure_container}/tmp/{token}/' | ||
|
||
bases = {'file': file_base, 'gs': gs_base, 's3': s3_base, 'azure-https': azure_base} | ||
|
||
sema = asyncio.Semaphore(50) | ||
async with sema: | ||
yield (sema, fs, bases) | ||
await bounded_gather2( | ||
sema, | ||
functools.partial(fs.rmtree, sema, file_base), | ||
functools.partial(fs.rmtree, sema, gs_base), | ||
functools.partial(fs.rmtree, sema, s3_base), | ||
functools.partial(fs.rmtree, sema, azure_base), | ||
) | ||
|
||
assert not await fs.isdir(file_base) | ||
assert not await fs.isdir(gs_base) | ||
assert not await fs.isdir(s3_base) | ||
assert not await fs.isdir(azure_base) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from typing import Tuple, Dict | ||
import asyncio | ||
import pytest | ||
|
||
from .utils import fresh_dir | ||
from hailtop.aiotools.fs import AsyncFS | ||
from hailtop.aiotools.delete import delete | ||
|
||
|
||
@pytest.fixture(params=['file', 'gs', 's3', 'azure-https']) | ||
async def test_delete_one_file(request, router_filesystem: Tuple[asyncio.Semaphore, AsyncFS, Dict[str, str]]): | ||
sema, fs, bases = router_filesystem | ||
scheme = request.param | ||
dirname = await fresh_dir(fs, bases, scheme) | ||
|
||
url = f'{dirname}/file' | ||
await fs.write(url, b'hello world') | ||
assert await fs.isfile(url) | ||
await delete(iter([url])) | ||
assert not await fs.isfile(url) | ||
|
||
|
||
@pytest.fixture(params=['file', 'gs', 's3', 'azure-https']) | ||
async def test_delete_folder(request, router_filesystem: Tuple[asyncio.Semaphore, AsyncFS, Dict[str, str]]): | ||
sema, fs, bases = router_filesystem | ||
scheme = request.param | ||
dirname = await fresh_dir(fs, bases, scheme) | ||
|
||
url = f'{dirname}/folder' | ||
await asyncio.gather( | ||
fs.write(f'{url}/1', b'hello world'), | ||
fs.write(f'{url}/2', b'hello world'), | ||
fs.write(f'{url}/3', b'hello world'), | ||
fs.write(f'{url}/4', b'hello world'), | ||
) | ||
assert await fs.isdir(url) | ||
await delete(iter([url])) | ||
assert not await fs.isdir(url) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from typing import Dict | ||
import secrets | ||
from hailtop.aiotools.fs import AsyncFS | ||
|
||
|
||
async def fresh_dir(fs: AsyncFS, bases: Dict[str, str], scheme: str): | ||
token = secrets.token_hex(16) | ||
dir = f'{bases[scheme]}{token}/' | ||
await fs.mkdir(dir) | ||
return dir |