aboutsummaryrefslogtreecommitdiffstats
path: root/tests/test_nsjail.py
diff options
context:
space:
mode:
authorGravatar MarkKoz <[email protected]>2019-06-26 23:00:39 -0700
committerGravatar MarkKoz <[email protected]>2019-06-26 23:00:39 -0700
commit158915a953879639722ab3bc1074fec7276117ba (patch)
tree15d01c035d722ad4b834f8c67a9a71156327c4bd /tests/test_nsjail.py
parentDon't generate an HTML report because Azure already does it (diff)
Disable memory swapping and add a memory limit test
If memory swapping was enabled locally, the memory test would fail. Explicitly disabling swapping also removes reliance on the assumption that it'll be disabled in production. * Add a constant for the maximum memory * Simplify the timeout test; it'd otherwise first run out of memory now
Diffstat (limited to 'tests/test_nsjail.py')
-rw-r--r--tests/test_nsjail.py19
1 files changed, 13 insertions, 6 deletions
diff --git a/tests/test_nsjail.py b/tests/test_nsjail.py
index e3b8eb3..f1a60e6 100644
--- a/tests/test_nsjail.py
+++ b/tests/test_nsjail.py
@@ -2,7 +2,7 @@ import logging
import unittest
from textwrap import dedent
-from snekbox.nsjail import NsJail
+from snekbox.nsjail import MEM_MAX, NsJail
class NsJailTests(unittest.TestCase):
@@ -21,12 +21,8 @@ class NsJailTests(unittest.TestCase):
def test_timeout_returns_137(self):
code = dedent("""
- x = '*'
while True:
- try:
- x = x * 99
- except:
- continue
+ pass
""").strip()
with self.assertLogs(self.logger) as log:
@@ -37,6 +33,17 @@ class NsJailTests(unittest.TestCase):
self.assertEqual(result.stderr, None)
self.assertIn("run time >= time limit", "\n".join(log.output))
+ def test_memory_returns_137(self):
+ # Add a kilobyte just to be safe.
+ code = dedent(f"""
+ x = ' ' * {MEM_MAX + 1000}
+ """).strip()
+
+ result = self.nsjail.python3(code)
+ self.assertEqual(result.returncode, 137)
+ self.assertEqual(result.stdout, "")
+ self.assertEqual(result.stderr, None)
+
def test_subprocess_resource_unavailable(self):
code = dedent("""
import subprocess