From 6cf78e32e6487538f79dabfe2d2abc0ca1c6773c Mon Sep 17 00:00:00 2001 From: Sachin Prabhu Date: Mon, 8 Apr 2024 21:21:20 +0100 Subject: [PATCH] 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 --- testcases/loading/test_loading.py | 38 ++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/testcases/loading/test_loading.py b/testcases/loading/test_loading.py index 0030a99..3bf8b85 100644 --- a/testcases/loading/test_loading.py +++ b/testcases/loading/test_loading.py @@ -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, @@ -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 @@ -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: @@ -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 @@ -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: @@ -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( @@ -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) @@ -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 ) @@ -340,6 +364,7 @@ def test_loading(hostname: str, sharename: str) -> None: ret_queue, mount_params, process_testdir, + tmpfile, ), ) processes.append(process) @@ -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 (