Skip to content

Commit 6cf78e3

Browse files
committed
testcases/loading: use 4K files for testing
For generating a better small file load, instead of a simple text string, use a 4K files to generate the read/write loads. Also educe number of threads/processs to 50 resulting in 50 x 10 = 500 simultaneous connections. Signed-off-by: Sachin Prabhu <[email protected]>
1 parent ffdd261 commit 6cf78e3

File tree

1 file changed

+32
-6
lines changed

1 file changed

+32
-6
lines changed

testcases/loading/test_loading.py

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,21 @@
2626
# total number of processes
2727
total_processes: int = 10
2828
# each with this number of threads
29-
per_process_threads: int = 100
29+
per_process_threads: int = 50
3030
# running the connection test for this many seconds
3131
test_runtime: int = 30
32+
# size of test files
33+
test_file_size = 4 * 1024 # 4k size
34+
# number of files each thread creates
35+
test_file_number = 10
3236

3337

3438
class SimpleLoadTest:
3539
"""A helper class to generate a simple load on a SMB server"""
3640

37-
instance_num = 0
38-
max_files = 10
39-
test_string = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
41+
instance_num: int = 0
42+
max_files: int = test_file_number
43+
test_string: str = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
4044

4145
def __init__(
4246
self,
@@ -45,10 +49,12 @@ def __init__(
4549
username: str,
4650
passwd: str,
4751
testdir: str,
52+
testfile: str = "",
4853
):
4954
self.idnum: int = type(self).instance_num
5055
type(self).instance_num += 1
5156

57+
self.testfile = testfile
5258
self.rootpath: str = f"{testdir}/test{self.idnum}"
5359
self.files: typing.List[str] = []
5460
self.thread = None
@@ -122,13 +128,23 @@ def _simple_run(self, op=""):
122128
self._simple_run(op="write")
123129
return
124130
self.stats["read"] += 1
125-
self.smbclient.read_text(file)
131+
if self.testfile:
132+
tfile = testhelper.get_tmp_file()
133+
with open(tfile, "wb") as fd:
134+
self.smbclient.read(file, fd)
135+
os.unlink(tfile)
136+
else:
137+
self.smbclient.read_text(file)
126138
elif op == "write":
127139
file = self._new_file()
128140
if not file:
129141
return
130142
self.stats["write"] += 1
131-
self.smbclient.write_text(file, type(self).test_string)
143+
if self.testfile:
144+
with open(self.testfile, "rb") as fd:
145+
self.smbclient.write(file, fd)
146+
else:
147+
self.smbclient.write_text(file, type(self).test_string)
132148
elif op == "delete":
133149
file = self._del_file()
134150
if not file:
@@ -202,12 +218,15 @@ def __init__(
202218
username: str,
203219
passwd: str,
204220
testdir: str,
221+
testfile: str = "",
205222
):
206223
self.server: str = hostname
207224
self.share: str = share
208225
self.username: str = username
209226
self.password: str = passwd
210227
self.testdir: str = testdir
228+
self.testfile = testfile
229+
211230
self.connections: typing.List[SimpleLoadTest] = []
212231
self.start_time: float = 0
213232
self.stop_time: float = 0
@@ -225,6 +244,7 @@ def set_connection_num(self, num: int) -> None:
225244
self.username,
226245
self.password,
227246
self.testdir,
247+
self.testfile,
228248
)
229249
self.connections.append(smbclient)
230250
elif cnum > num:
@@ -281,6 +301,7 @@ def start_process(
281301
ret_queue: Queue,
282302
mount_params: typing.Dict[str, str],
283303
testdir: str,
304+
testfile: str = "",
284305
) -> None:
285306
"""Start function for test processes"""
286307
loadtest: LoadTest = LoadTest(
@@ -289,6 +310,7 @@ def start_process(
289310
mount_params["username"],
290311
mount_params["password"],
291312
testdir,
313+
testfile,
292314
)
293315
loadtest.set_connection_num(numcons)
294316
loadtest.start_tests(test_runtime)
@@ -311,6 +333,8 @@ def generate_loading_check() -> typing.List[tuple[str, str]]:
311333

312334
@pytest.mark.parametrize("hostname,sharename", generate_loading_check())
313335
def test_loading(hostname: str, sharename: str) -> None:
336+
# Get a tmp file of size 4K
337+
tmpfile = testhelper.get_tmp_file(size=test_file_size)
314338
mount_params: dict[str, str] = testhelper.get_mount_parameters(
315339
test_info, sharename
316340
)
@@ -340,6 +364,7 @@ def test_loading(hostname: str, sharename: str) -> None:
340364
ret_queue,
341365
mount_params,
342366
process_testdir,
367+
tmpfile,
343368
),
344369
)
345370
processes.append(process)
@@ -377,6 +402,7 @@ def test_loading(hostname: str, sharename: str) -> None:
377402

378403
smbclient.rmdir(testdir)
379404
smbclient.disconnect()
405+
os.unlink(tmpfile)
380406

381407
print_stats("Total:", total_stats)
382408
assert (

0 commit comments

Comments
 (0)