Skip to content

Commit

Permalink
testcases/loading: use 4K files for testing
Browse files Browse the repository at this point in the history
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 <sp@spui.uk>
  • Loading branch information
spuiuk committed Apr 15, 2024
1 parent ffdd261 commit 6cf78e3
Showing 1 changed file with 32 additions and 6 deletions.
38 changes: 32 additions & 6 deletions testcases/loading/test_loading.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,21 @@
# total number of processes
total_processes: int = 10
# each with this number of threads
per_process_threads: int = 100
per_process_threads: int = 50
# running the connection test for this many seconds
test_runtime: int = 30
# size of test files
test_file_size = 4 * 1024 # 4k size
# number of files each thread creates
test_file_number = 10


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

instance_num = 0
max_files = 10
test_string = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
instance_num: int = 0
max_files: int = test_file_number
test_string: str = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"

def __init__(
self,
Expand All @@ -45,10 +49,12 @@ def __init__(
username: str,
passwd: str,
testdir: str,
testfile: str = "",
):
self.idnum: int = type(self).instance_num
type(self).instance_num += 1

self.testfile = testfile
self.rootpath: str = f"{testdir}/test{self.idnum}"
self.files: typing.List[str] = []
self.thread = None
Expand Down Expand Up @@ -122,13 +128,23 @@ def _simple_run(self, op=""):
self._simple_run(op="write")
return
self.stats["read"] += 1
self.smbclient.read_text(file)
if self.testfile:
tfile = testhelper.get_tmp_file()
with open(tfile, "wb") as fd:
self.smbclient.read(file, fd)
os.unlink(tfile)
else:
self.smbclient.read_text(file)
elif op == "write":
file = self._new_file()
if not file:
return
self.stats["write"] += 1
self.smbclient.write_text(file, type(self).test_string)
if self.testfile:
with open(self.testfile, "rb") as fd:
self.smbclient.write(file, fd)
else:
self.smbclient.write_text(file, type(self).test_string)
elif op == "delete":
file = self._del_file()
if not file:
Expand Down Expand Up @@ -202,12 +218,15 @@ def __init__(
username: str,
passwd: str,
testdir: str,
testfile: str = "",
):
self.server: str = hostname
self.share: str = share
self.username: str = username
self.password: str = passwd
self.testdir: str = testdir
self.testfile = testfile

self.connections: typing.List[SimpleLoadTest] = []
self.start_time: float = 0
self.stop_time: float = 0
Expand All @@ -225,6 +244,7 @@ def set_connection_num(self, num: int) -> None:
self.username,
self.password,
self.testdir,
self.testfile,
)
self.connections.append(smbclient)
elif cnum > num:
Expand Down Expand Up @@ -281,6 +301,7 @@ def start_process(
ret_queue: Queue,
mount_params: typing.Dict[str, str],
testdir: str,
testfile: str = "",
) -> None:
"""Start function for test processes"""
loadtest: LoadTest = LoadTest(
Expand All @@ -289,6 +310,7 @@ def start_process(
mount_params["username"],
mount_params["password"],
testdir,
testfile,
)
loadtest.set_connection_num(numcons)
loadtest.start_tests(test_runtime)
Expand All @@ -311,6 +333,8 @@ def generate_loading_check() -> typing.List[tuple[str, str]]:

@pytest.mark.parametrize("hostname,sharename", generate_loading_check())
def test_loading(hostname: str, sharename: str) -> None:
# Get a tmp file of size 4K
tmpfile = testhelper.get_tmp_file(size=test_file_size)
mount_params: dict[str, str] = testhelper.get_mount_parameters(
test_info, sharename
)
Expand Down Expand Up @@ -340,6 +364,7 @@ def test_loading(hostname: str, sharename: str) -> None:
ret_queue,
mount_params,
process_testdir,
tmpfile,
),
)
processes.append(process)
Expand Down Expand Up @@ -377,6 +402,7 @@ def test_loading(hostname: str, sharename: str) -> None:

smbclient.rmdir(testdir)
smbclient.disconnect()
os.unlink(tmpfile)

print_stats("Total:", total_stats)
assert (
Expand Down

0 comments on commit 6cf78e3

Please sign in to comment.