@@ -19,9 +19,16 @@ def run_stress_test(
1919 with open (output_file , "a" ) as f :
2020 f .write (f"Stress testing with { num_submissions } submissions\n " )
2121 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" )
2229 command = [
2330 "python3" ,
24- os . path . join ( tango_path , "clients/tango-cli.py" ) ,
31+ tango_cli ,
2532 "-P" ,
2633 str (tango_port ),
2734 "-k" ,
@@ -33,18 +40,22 @@ def run_stress_test(
3340 "--image" ,
3441 autograder_image ,
3542 ]
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
3949 if submission_delay > 0 :
4050 time .sleep (submission_delay )
4151
42- sys .exit ()
52+ sys .exit (0 )
4353
4454
4555def get_metrics (output_file ):
46- if Config .LOGFILE == None :
56+ if Config .LOGFILE is None :
4757 print ("Make sure logs are recorded in a log file" )
58+ sys .exit (0 )
4859
4960 job_times = []
5061 with open (Config .LOGFILE , "r" ) as f :
@@ -59,9 +70,10 @@ def get_metrics(output_file):
5970 print ("No jobs have been completed" )
6071 else :
6172 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 " )
6375
64- sys .exit ()
76+ sys .exit (0 )
6577
6678
6779if __name__ == "__main__" :
0 commit comments