aboutsummaryrefslogtreecommitdiffstats
path: root/backend
diff options
context:
space:
mode:
authorGravatar Matteo Bertucci <[email protected]>2021-02-25 14:28:51 +0100
committerGravatar Matteo Bertucci <[email protected]>2021-02-25 14:28:51 +0100
commit7d34cb8563d8c01e5f5d1b038e0fbd507063e853 (patch)
treef276a5e4f62645022dc27a892d810f623bdf4b37 /backend
parentAdd return code 6 for exceptions when loading module (diff)
Add return code 7 for processes killed by NsJail
Diffstat (limited to 'backend')
-rw-r--r--backend/routes/forms/unittesting.py47
1 files changed, 25 insertions, 22 deletions
diff --git a/backend/routes/forms/unittesting.py b/backend/routes/forms/unittesting.py
index c00fc4c..57bf5db 100644
--- a/backend/routes/forms/unittesting.py
+++ b/backend/routes/forms/unittesting.py
@@ -50,7 +50,7 @@ async def _post_eval(code: str) -> Optional[dict[str, str]]:
"""Post the eval to snekbox and return the response."""
async with httpx.AsyncClient() as client:
data = {"input": code}
- response = await client.post(SNEKBOX_URL, json=data)
+ response = await client.post(SNEKBOX_URL, json=data, timeout=10)
if not response.status_code == 200:
return
@@ -97,30 +97,33 @@ async def execute_unittest(form_response: FormResponse, form: Form) -> list[Unit
else:
return_code = int(response["returncode"])
+ # Parse the stdout if the tests ran successfully
+ if return_code == 0:
+ stdout = response["stdout"]
+ passed = bool(int(stdout[0]))
+
+ # If the test failed, we have to populate the result string.
+ if not passed:
+ failed_tests = stdout[1:].strip().split(";")
+
+ # Redact failed hidden tests
+ for i, failed_test in enumerate(failed_tests[:]):
+ if failed_test in hidden_tests:
+ failed_tests[i] = f"hidden_test_{hidden_tests[failed_test]}"
+
+ result = ";".join(failed_tests)
+ else:
+ result = ""
+ elif return_code in (5, 6, 99):
+ result = response["stdout"]
+ # Killed by NsJail
+ elif return_code == 137:
+ return_code = 7
+ result = "Timed out or ran out of memory."
# Another code has been returned by CPython because of another failure.
- if return_code not in (0, 5, 6, 99):
+ else:
return_code = 99
result = "Internal error."
- else:
- # Parse the stdout if the tests ran successfully
- if return_code == 0:
- stdout = response["stdout"]
- passed = bool(int(stdout[0]))
-
- # If the test failed, we have to populate the result string.
- if not passed:
- failed_tests = stdout[1:].strip().split(";")
-
- # Redact failed hidden tests
- for i, failed_test in enumerate(failed_tests[:]):
- if failed_test in hidden_tests:
- failed_tests[i] = f"hidden_test_{hidden_tests[failed_test]}"
-
- result = ";".join(failed_tests)
- else:
- result = ""
- else:
- result = response["stdout"]
unittest_results.append(UnittestResult(
question_id=question.id,