@@ -19,9 +19,16 @@ def run_stress_test(
19
19
with open (output_file , "a" ) as f :
20
20
f .write (f"Stress testing with { num_submissions } submissions\n " )
21
21
for i in range (1 , num_submissions + 1 ):
22
+ tango_cli = os .path .join (tango_path , "clients/tango-cli.py" )
23
+ if not os .path .isfile (tango_cli ):
24
+ raise ValueError (f"Tango CLI not found at: { tango_cli } " )
25
+ if not os .path .exists (job_path ):
26
+ raise ValueError (f"Job path does not exist: { job_path } " )
27
+ if not isinstance (tango_port , int ) or not (1024 <= tango_port <= 65535 ):
28
+ raise ValueError ("Invalid port number" )
22
29
command = [
23
30
"python3" ,
24
- os . path . join ( tango_path , "clients/tango-cli.py" ) ,
31
+ tango_cli ,
25
32
"-P" ,
26
33
str (tango_port ),
27
34
"-k" ,
@@ -33,18 +40,22 @@ def run_stress_test(
33
40
"--image" ,
34
41
autograder_image ,
35
42
]
36
- subprocess .run (command , stdout = f , stderr = f )
37
- f .write (f"Submission { i } submitted \n " )
38
-
43
+ try :
44
+ subprocess .run (command , stdout = f , stderr = f )
45
+ f .write (f"Submission { i } submitted \n " )
46
+ except subprocess .CalledProcessError as e :
47
+ f .write (f"Error running submission { i } : { e } \n " )
48
+ continue
39
49
if submission_delay > 0 :
40
50
time .sleep (submission_delay )
41
51
42
- sys .exit ()
52
+ sys .exit (0 )
43
53
44
54
45
55
def get_metrics (output_file ):
46
- if Config .LOGFILE == None :
56
+ if Config .LOGFILE is None :
47
57
print ("Make sure logs are recorded in a log file" )
58
+ sys .exit (0 )
48
59
49
60
job_times = []
50
61
with open (Config .LOGFILE , "r" ) as f :
@@ -59,9 +70,10 @@ def get_metrics(output_file):
59
70
print ("No jobs have been completed" )
60
71
else :
61
72
avg = sum (job_times ) / len (job_times )
62
- f .write (f"Average job time is { avg } seconds \n " )
73
+ f .write (f"Total jobs completed: { len (job_times )} \n " )
74
+ f .write (f"Average job time: { avg } seconds \n " )
63
75
64
- sys .exit ()
76
+ sys .exit (0 )
65
77
66
78
67
79
if __name__ == "__main__" :
0 commit comments