Skip to content

Commit b5676b0

Browse files
authoredMar 22, 2024
perf_test: return 1 in case of ratio non 100% and in any fail reason (#118)
1 parent 14d41e0 commit b5676b0

File tree

1 file changed

+26
-23
lines changed

1 file changed

+26
-23
lines changed
 

‎perf/run_perf_tests.py

+26-23
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def usage(argv):
7171
print("-c,--run-vegeta-on-core <...> taskset format for vegeta (e.g. 0-1:2-3 or 0-2:3-4) [default: " + DEFAULT_DAEMON_VEGETA_ON_CORE +"]")
7272
print("-T,--response-timeout <timeout>: vegeta response timeout [default: " + DEFAULT_VEGETA_RESPONSE_TIMEOUT + "]")
7373
print("-M,--max-body-rsp <size>: max number of bytes to read from response bodies [default: " + DEFAULT_MAX_BODY_RSP + "]")
74-
sys.exit(-1)
74+
sys.exit(1)
7575

7676
def get_process(process_name: str):
7777
""" Return the running process having specified name or None if not exists """
@@ -207,7 +207,7 @@ def __parse_args(self, argv):
207207
# print help information and exit:
208208
print(err)
209209
usage(argv)
210-
sys.exit(-1)
210+
sys.exit(1)
211211

212212

213213
class PerfTest:
@@ -240,7 +240,7 @@ def copy_and_extract_pattern_file(self):
240240
""" Copy the vegeta pattern file into /tmp/run_tests_xyz/ and untar the file """
241241
if os.path.exists(self.config.vegeta_pattern_tar_file) == 0:
242242
print ("ERROR: invalid pattern file: ", self.config.vegeta_pattern_tar_file)
243-
sys.exit(-1)
243+
sys.exit(1)
244244
cmd = "mkdir " + RUN_TEST_DIRNAME
245245
status = os.system(cmd)
246246
cmd = "/bin/cp -f " + self.config.vegeta_pattern_tar_file + " " + VEGETA_TAR_FILE_NAME
@@ -249,15 +249,15 @@ def copy_and_extract_pattern_file(self):
249249
status = os.system(cmd)
250250
if int(status) != 0:
251251
print("Vegeta pattern copy failed. Test Aborted!")
252-
sys.exit(-1)
252+
sys.exit(1)
253253

254254
cmd = "cd " + RUN_TEST_DIRNAME + "; tar xvf " + VEGETA_TAR_FILE_NAME + " > /dev/null"
255255
if self.config.tracing:
256256
print(f"Extracting Vegeta pattern: {cmd}")
257257
status = os.system(cmd)
258258
if int(status) != 0:
259259
print("Vegeta pattern untar failed. Test Aborted!")
260-
sys.exit(-1)
260+
sys.exit(1)
261261

262262
# If address is provided substitute the address and port of daemon in the vegeta file
263263
if self.config.rpc_daemon_address != "localhost":
@@ -295,8 +295,8 @@ def execute(self, test_number, name, qps_value, duration):
295295
sys.stdout.flush()
296296
status = os.system(cmd)
297297
if int(status) != 0:
298-
print("vegeta test fails: Test Aborted!")
299-
return 0
298+
print("vegeta attach fails: Test Aborted!")
299+
return 1
300300

301301
while 1:
302302
time.sleep(3)
@@ -309,13 +309,13 @@ def execute(self, test_number, name, qps_value, duration):
309309
if pid == "" :
310310
# the server is dead; kill vegeta and returns fails
311311
os.system("kill -2 $(ps aux | grep 'vegeta' | grep -v 'grep' | grep -v 'python' | awk '{print $2}') 2> /dev/null")
312-
return 0
312+
print ("test failed: server is Dead")
313+
return 1
313314

314315
pid = os.popen("ps aux | grep 'vegeta report' | grep -v 'grep' | awk '{print $2}'").read()
315316
if pid == "":
316-
# Vegeta has completed its works, generate report and return OK
317-
self.get_result(test_number, name, qps_value, duration)
318-
return 1
317+
# Vegeta has completed its works, generate report
318+
return self.get_result(test_number, name, qps_value, duration)
319319

320320
def execute_sequence(self, sequence, tag):
321321
""" Execute the sequence of tests """
@@ -327,13 +327,12 @@ def execute_sequence(self, sequence, tag):
327327
test_name = "[{:d}.{:2d}] "
328328
test_name_formatted = test_name.format(test_number, test_rep+1)
329329
result = self.execute(test_name_formatted, tag, qps, duration)
330-
if result == 0:
331-
print("Server dead test Aborted!")
332-
return 0
330+
if result == 1:
331+
return 1
333332
time.sleep(self.config.waiting_time)
334333
test_number = test_number + 1
335334
print("")
336-
return 1
335+
return 0
337336

338337
def get_result(self, test_number, daemon_name, qps_value, duration):
339338
""" Processes the report file generated by vegeta and reads latency data """
@@ -348,7 +347,7 @@ def get_result(self, test_number, daemon_name, qps_value, duration):
348347
newline = file_raws[5].replace('\n', ' ')
349348
ratio = newline.split(' ')[34]
350349
if len(file_raws) > 8:
351-
error = file_raws[8]
350+
error = file_raws[8].rstrip()
352351
print(" [ Ratio="+ratio+", MaxLatency="+max_latency+ " Error: " + error +"]")
353352
else:
354353
error = ""
@@ -357,11 +356,17 @@ def get_result(self, test_number, daemon_name, qps_value, duration):
357356
finally:
358357
file.close()
359358

359+
if error != "" or ratio != "100.00%":
360+
print ("test failed: ratio is not 100.00%")
361+
return 1
362+
360363
if self.config.create_test_report:
361364
self.test_report.write_test_report(daemon_name, test_number, threads, qps_value, duration, min_latency, latency_values[7], latency_values[8], \
362365
latency_values[9], latency_values[10], latency_values[11], max_latency, ratio, error)
363366
os.system("/bin/rm " + test_report_filename)
364367

368+
return 0
369+
365370

366371
class Hardware:
367372
""" Extract hardware information from the underlying platform. """
@@ -517,27 +522,25 @@ def main(argv):
517522

518523
if config.test_mode in ("1", "3"):
519524
result = perf_test.execute_sequence(current_sequence, SILKRPC)
520-
if result == 0:
521-
print("Server dead test Aborted!")
525+
if result == 1:
522526
if config.create_test_report:
523527
test_report.close()
524-
sys.exit(-1)
528+
return 1
525529
if config.test_mode == "3":
526530
print("--------------------------------------------------------------------------------------------\n")
527531

528532
if config.test_mode in ("2", "3"):
529533
result = perf_test.execute_sequence(current_sequence, RPCDAEMON)
530-
if result == 0:
531-
print("Server dead test Aborted!")
534+
if result == 1:
532535
if config.create_test_report:
533536
test_report.close()
534-
sys.exit(-1)
537+
return 1
535538

536539
if config.create_test_report:
537540
test_report.close()
538541
perf_test.cleanup(0)
539542
print("Performance Test completed successfully.")
540-
543+
return 0
541544

542545
#
543546
# module as main

0 commit comments

Comments
 (0)