Skip to content

Commit 28c95c8

Browse files
committed
Update test_forkbomb_resource_unavailable to disable memory limits
This was still producing unpredictable behaviour in CI (sometimes being killed and exiting with 137/OOM kill). Disabling the memory limit ensures that the only reason this test case will kill the executing code is because of PID exhaustion.
1 parent 1ed5b1b commit 28c95c8

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

tests/test_nsjail.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -213,12 +213,19 @@ def test_write_hidden_exclude(self):
213213
self.assertEqual(result.files[0].content, b"a")
214214

215215
def test_forkbomb_resource_unavailable(self):
216-
# Using the production max PIDs causes processes to be killed due to memory instead of
217-
# PID allocation exhaustion. For this test case, the PID limit is reduced to ensure
218-
# that PID exhaustion is still something that is guarded against.
219-
220-
previous_pids_max = self.nsjail.config.cgroup_pids_max
216+
# Using the production max PIDs causes processes to be killed due to
217+
# memory instead of PID allocation exhaustion.
218+
#
219+
# For this test, we disable the cgroup memory limit & lower the PID
220+
# limit so that the only reason the test code should be killed is due to
221+
# PID exhaustion.
222+
223+
previous_pids_max, previous_mem_max = (
224+
self.nsjail.config.cgroup_pids_max,
225+
self.nsjail.config.cgroup_mem_max,
226+
)
221227
self.nsjail.config.cgroup_pids_max = 5
228+
self.nsjail.config.cgroup_mem_max = 0
222229

223230
code = dedent(
224231
"""
@@ -235,6 +242,7 @@ def test_forkbomb_resource_unavailable(self):
235242
self.assertEqual(result.stderr, None)
236243
finally:
237244
self.nsjail.config.cgroup_pids_max = previous_pids_max
245+
self.nsjail.config.cgroup_mem_max = previous_mem_max
238246

239247
def test_file_parsing_timeout(self):
240248
code = dedent(

0 commit comments

Comments
 (0)