python-discord / snekbox

Easy, safe evaluation of arbitrary Python code
https://pythondiscord.com
MIT License
214 stars 39 forks source link

Make test_multiprocessing_shared_memory_disabled compatible with newer versions of glibc #182

Closed MarkKoz closed 1 year ago

MarkKoz commented 1 year ago

The test test_multiprocessing_shared_memory_disabled asserts that ENOSYS occurs. This comes from SHM_GET_NAME which comes from shm_open which comes from here in CPython. This works with Debian Bullseye which is on glibc 2.31.

However, in glibc 2.34, behaviour of shm_open was changed to no longer return ENOSYS. With Debian Bookworm, which is on glibc 2.36, this test fails with ENOENT instead:

======================================================================
FAIL: test_multiprocessing_shared_memory_disabled (tests.test_nsjail.NsJailTests.test_multiprocessing_shared_memory_disabled)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/snekbox/tests/test_nsjail.py", line 366, in test_multiprocessing_shared_memory_disabled
    self.assertIn("Function not implemented", result.stdout)
AssertionError: 'Function not implemented' not found in 'Traceback (most recent call last):\n  File "/home/test.py", line 3, in <module>\n    SharedMemory(\'test\', create=True, size=16)\n  File "/usr/local/lib/python3.11/multiprocessing/shared_memory.py", line 104, in __init__\n    self._fd = _posixshmem.shm_open(\n               ^^^^^^^^^^^^^^^^^^^^^\nFileNotFoundError: [Errno 2] No such file or directory: \'/test\'\n'

Update the test to assert either ENOSYS or ENOENT is raised (support both scenarios). Alternatively, come up with a way to test this that isn't tied to glibc behaviour.

MarkKoz commented 1 year ago

Shared memory was enabled in #113, so this is no longer necessary.