Skip to content

Commit 5132168

Browse files
committed
fixing coderabbit
1 parent c4c6868 commit 5132168

File tree

3 files changed

+22
-10
lines changed

3 files changed

+22
-10
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@ pip-selfcheck.json
2626
.vscode
2727

2828
# Backup files
29-
*.bak
29+
*.bak

stressTest.py

+20-8
Original file line numberDiff line numberDiff line change
@@ -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

4555
def 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

6779
if __name__ == "__main__":

worker.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -376,4 +376,4 @@ def run(self):
376376
if self.preVM and not vm:
377377
vm = self.job.vm = self.preVM
378378
if vm:
379-
self.detachVM(return_vm=False, replace_vm=True)
379+
self.detachVM(return_vm=False, replace_vm=True)

0 commit comments

Comments
 (0)