26
26
# total number of processes
27
27
total_processes : int = 10
28
28
# each with this number of threads
29
- per_process_threads : int = 100
29
+ per_process_threads : int = 50
30
30
# running the connection test for this many seconds
31
31
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
32
36
33
37
34
38
class SimpleLoadTest :
35
39
"""A helper class to generate a simple load on a SMB server"""
36
40
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"
40
44
41
45
def __init__ (
42
46
self ,
@@ -45,10 +49,12 @@ def __init__(
45
49
username : str ,
46
50
passwd : str ,
47
51
testdir : str ,
52
+ testfile : str = "" ,
48
53
):
49
54
self .idnum : int = type (self ).instance_num
50
55
type (self ).instance_num += 1
51
56
57
+ self .testfile = testfile
52
58
self .rootpath : str = f"{ testdir } /test{ self .idnum } "
53
59
self .files : typing .List [str ] = []
54
60
self .thread = None
@@ -122,13 +128,23 @@ def _simple_run(self, op=""):
122
128
self ._simple_run (op = "write" )
123
129
return
124
130
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 )
126
138
elif op == "write" :
127
139
file = self ._new_file ()
128
140
if not file :
129
141
return
130
142
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 )
132
148
elif op == "delete" :
133
149
file = self ._del_file ()
134
150
if not file :
@@ -202,12 +218,15 @@ def __init__(
202
218
username : str ,
203
219
passwd : str ,
204
220
testdir : str ,
221
+ testfile : str = "" ,
205
222
):
206
223
self .server : str = hostname
207
224
self .share : str = share
208
225
self .username : str = username
209
226
self .password : str = passwd
210
227
self .testdir : str = testdir
228
+ self .testfile = testfile
229
+
211
230
self .connections : typing .List [SimpleLoadTest ] = []
212
231
self .start_time : float = 0
213
232
self .stop_time : float = 0
@@ -225,6 +244,7 @@ def set_connection_num(self, num: int) -> None:
225
244
self .username ,
226
245
self .password ,
227
246
self .testdir ,
247
+ self .testfile ,
228
248
)
229
249
self .connections .append (smbclient )
230
250
elif cnum > num :
@@ -281,6 +301,7 @@ def start_process(
281
301
ret_queue : Queue ,
282
302
mount_params : typing .Dict [str , str ],
283
303
testdir : str ,
304
+ testfile : str = "" ,
284
305
) -> None :
285
306
"""Start function for test processes"""
286
307
loadtest : LoadTest = LoadTest (
@@ -289,6 +310,7 @@ def start_process(
289
310
mount_params ["username" ],
290
311
mount_params ["password" ],
291
312
testdir ,
313
+ testfile ,
292
314
)
293
315
loadtest .set_connection_num (numcons )
294
316
loadtest .start_tests (test_runtime )
@@ -311,6 +333,8 @@ def generate_loading_check() -> typing.List[tuple[str, str]]:
311
333
312
334
@pytest .mark .parametrize ("hostname,sharename" , generate_loading_check ())
313
335
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 )
314
338
mount_params : dict [str , str ] = testhelper .get_mount_parameters (
315
339
test_info , sharename
316
340
)
@@ -340,6 +364,7 @@ def test_loading(hostname: str, sharename: str) -> None:
340
364
ret_queue ,
341
365
mount_params ,
342
366
process_testdir ,
367
+ tmpfile ,
343
368
),
344
369
)
345
370
processes .append (process )
@@ -377,6 +402,7 @@ def test_loading(hostname: str, sharename: str) -> None:
377
402
378
403
smbclient .rmdir (testdir )
379
404
smbclient .disconnect ()
405
+ os .unlink (tmpfile )
380
406
381
407
print_stats ("Total:" , total_stats )
382
408
assert (
0 commit comments