Skip to content

Commit bb3dcee

Browse files
[Storage][Perf tests] Add file based perf tests to Blob (Azure#42687)
1 parent 51ada1f commit bb3dcee

File tree

4 files changed

+57
-21
lines changed

4 files changed

+57
-21
lines changed

sdk/storage/azure-storage-blob/tests/perfstress_tests/download.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,19 @@
33
# Licensed under the MIT License. See License.txt in the project root for license information.
44
# --------------------------------------------------------------------------------------------
55

6-
from devtools_testutils.perfstress_tests import get_random_bytes, WriteStream
6+
from devtools_testutils.perfstress_tests import RandomStream, WriteStream
77

8-
from ._test_base import _ContainerTest
8+
from ._test_base import _BlobTest
99

1010

11-
class DownloadTest(_ContainerTest):
11+
class DownloadTest(_BlobTest):
1212
def __init__(self, arguments):
1313
super().__init__(arguments)
14-
blob_name = "downloadtest"
15-
self.blob_client = self.container_client.get_blob_client(blob_name)
16-
self.async_blob_client = self.async_container_client.get_blob_client(blob_name)
1714
self.download_stream = WriteStream()
1815

1916
async def global_setup(self):
2017
await super().global_setup()
21-
data = get_random_bytes(self.args.size)
18+
data = RandomStream(self.args.size)
2219
await self.async_blob_client.upload_blob(data)
2320

2421
def run_sync(self):
@@ -30,7 +27,3 @@ async def run_async(self):
3027
self.download_stream.reset()
3128
stream = await self.async_blob_client.download_blob(max_concurrency=self.args.max_concurrency)
3229
await stream.readinto(self.download_stream)
33-
34-
async def close(self):
35-
await self.async_blob_client.close()
36-
await super().close()
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# --------------------------------------------------------------------------------------------
2+
# Copyright (c) Microsoft Corporation. All rights reserved.
3+
# Licensed under the MIT License. See License.txt in the project root for license information.
4+
# --------------------------------------------------------------------------------------------
5+
6+
import os
7+
import tempfile
8+
from typing import Optional
9+
10+
from devtools_testutils.perfstress_tests import RandomStream
11+
12+
from ._test_base import _BlobTest
13+
14+
class DownloadToFileTest(_BlobTest):
15+
_temp_file: Optional[str] = None
16+
17+
async def global_setup(self):
18+
await super().global_setup()
19+
data = RandomStream(self.args.size)
20+
await self.async_blob_client.upload_blob(data)
21+
22+
async def setup(self):
23+
await super().setup()
24+
with tempfile.NamedTemporaryFile(delete=False) as tf:
25+
self._temp_file = tf.name
26+
27+
async def cleanup(self):
28+
if self._temp_file and os.path.exists(self._temp_file):
29+
os.remove(self._temp_file)
30+
await super().cleanup()
31+
32+
def run_sync(self):
33+
with open(self._temp_file, 'wb') as f:
34+
stream = self.blob_client.download_blob(max_concurrency=self.args.max_concurrency)
35+
stream.readinto(f)
36+
37+
async def run_async(self):
38+
with open(self._temp_file, 'wb') as f:
39+
stream = await self.async_blob_client.download_blob(max_concurrency=self.args.max_concurrency)
40+
await stream.readinto(f)

sdk/storage/azure-storage-blob/tests/perfstress_tests/upload.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from ._test_base import _BlobTest
77

8-
from devtools_testutils.perfstress_tests import RandomStream, get_random_bytes
8+
from devtools_testutils.perfstress_tests import RandomStream
99
from devtools_testutils.perfstress_tests import AsyncRandomStream
1010

1111

sdk/storage/azure-storage-blob/tests/perfstress_tests/upload_from_file.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,36 @@
44
# --------------------------------------------------------------------------------------------
55

66
import os
7+
import shutil
78
import tempfile
9+
from typing import Optional
810

9-
from devtools_testutils.perfstress_tests import get_random_bytes
11+
from devtools_testutils.perfstress_tests import RandomStream
1012

1113
from ._test_base import _BlobTest
1214

1315

1416
class UploadFromFileTest(_BlobTest):
15-
temp_file = None
17+
_temp_file: Optional[str] = None
1618

1719
async def global_setup(self):
1820
await super().global_setup()
19-
data = get_random_bytes(self.args.size)
20-
with tempfile.NamedTemporaryFile(delete=False) as temp_file:
21-
UploadFromFileTest.temp_file = temp_file.name
22-
temp_file.write(data)
21+
data_stream = RandomStream(self.args.size)
22+
with tempfile.NamedTemporaryFile(delete=False) as tf:
23+
self._temp_file = tf.name
24+
shutil.copyfileobj(data_stream, tf)
2325

2426
async def global_cleanup(self):
25-
os.remove(UploadFromFileTest.temp_file)
27+
if self._temp_file and os.path.exists(self._temp_file):
28+
os.remove(self._temp_file)
2629
await super().global_cleanup()
2730

2831
def run_sync(self):
29-
with open(UploadFromFileTest.temp_file, 'rb') as fp:
32+
with open(self._temp_file, 'rb') as fp:
3033
self.blob_client.upload_blob(fp, max_concurrency=self.args.max_concurrency, overwrite=True)
3134

3235
async def run_async(self):
33-
with open(UploadFromFileTest.temp_file, 'rb') as fp:
36+
with open(self._temp_file, 'rb') as fp:
3437
await self.async_blob_client.upload_blob(
3538
fp,
3639
max_concurrency=self.args.max_concurrency,

0 commit comments

Comments
 (0)