|
24 | 24 | # TODO: replace this with a fixture once zonal bucket creation / deletion |
25 | 25 | # is supported in grpc client or json client client. |
26 | 26 | _ZONAL_BUCKET = os.getenv("ZONAL_BUCKET") |
| 27 | +_BYTES_TO_UPLOAD = b"dummy_bytes_to_write_read_and_delete_appendable_object" |
27 | 28 |
|
28 | 29 |
|
29 | 30 | @pytest.mark.asyncio |
30 | | -async def test_basic_wrd(storage_client, blobs_to_delete): |
31 | | - bytes_to_upload = b"dummy_bytes_to_write_read_and_delete_appendable_object" |
| 31 | +@pytest.mark.parametrize( |
| 32 | + "attempt_direct_path", |
| 33 | + [True, False], |
| 34 | +) |
| 35 | +async def test_basic_wrd(storage_client, blobs_to_delete, attempt_direct_path): |
32 | 36 | object_name = f"test_basic_wrd-{str(uuid.uuid4())}" |
33 | 37 |
|
34 | 38 | # Client instantiation; it cannot be part of fixture because. |
35 | 39 | # grpc_client's event loop and event loop of coroutine running it |
36 | 40 | # (i.e. this test) must be same. |
37 | 41 | # Note: |
38 | | - # 1. @pytest.mark.asyncio ensures new event for each test. |
| 42 | + # 1. @pytest.mark.asyncio ensures new event loop for each test. |
39 | 43 | # 2. we can keep the same event loop for entire module but that may |
40 | 44 | # create issues if tests are run in parallel and one test hogs the event |
41 | 45 | # loop slowing down other tests. |
42 | | - grpc_client = AsyncGrpcClient().grpc_client |
| 46 | + grpc_client = AsyncGrpcClient(attempt_direct_path=attempt_direct_path).grpc_client |
43 | 47 |
|
44 | 48 | writer = AsyncAppendableObjectWriter(grpc_client, _ZONAL_BUCKET, object_name) |
45 | 49 | await writer.open() |
46 | | - await writer.append(bytes_to_upload) |
| 50 | + await writer.append(_BYTES_TO_UPLOAD) |
47 | 51 | object_metadata = await writer.close(finalize_on_close=True) |
48 | | - assert object_metadata.size == len(bytes_to_upload) |
| 52 | + assert object_metadata.size == len(_BYTES_TO_UPLOAD) |
49 | 53 |
|
50 | 54 | mrd = AsyncMultiRangeDownloader(grpc_client, _ZONAL_BUCKET, object_name) |
51 | 55 | buffer = BytesIO() |
52 | 56 | await mrd.open() |
53 | 57 | # (0, 0) means read the whole object |
54 | 58 | await mrd.download_ranges([(0, 0, buffer)]) |
55 | 59 | await mrd.close() |
56 | | - assert buffer.getvalue() == bytes_to_upload |
| 60 | + assert buffer.getvalue() == _BYTES_TO_UPLOAD |
57 | 61 |
|
58 | 62 | # Clean up; use json client (i.e. `storage_client` fixture) to delete. |
59 | 63 | blobs_to_delete.append(storage_client.bucket(_ZONAL_BUCKET).blob(object_name)) |
0 commit comments