Skip to content

Commit 6181713

Browse files
committed
pythongh-124213: Skip tests failing with --suppress-sync=true when inside systemd-nspawn container
Add a helper functon that checks whether the test suite is running inside a systemd-nspawn container, and skip the few tests failing with `--suppress-sync=true` in that case. The tests are failing because `--suppress-sync=true` stubs out `fsync()`, `fdatasync()` and `msync()` calls, and therefore they always return success without checking for invalid arguments. Technically, this means that the tests are also skipped when running inside systemd-nspawn container without `--suppress-sync=true`. However, to the best of my knowledge the only way to detect this option is to actually reproduce one of the unexpectedly-succeeding syscalls, and since this is precisely what we're testing for, the skip-test and the actual test would be doing the same thing. Signed-off-by: Michał Górny <[email protected]>
1 parent 9947ddb commit 6181713

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

Lib/test/support/__init__.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import types
2626
import unittest
2727
import warnings
28+
from pathlib import Path
2829

2930
from .testresult import get_test_runner
3031

@@ -72,6 +73,7 @@
7273
"run_with_tz", "PGO", "missing_compiler_executable", "fd_count",
7374
"ALWAYS_EQ", "NEVER_EQ", "LARGEST", "SMALLEST",
7475
"LOOPBACK_TIMEOUT", "INTERNET_TIMEOUT", "SHORT_TIMEOUT", "LONG_TIMEOUT",
76+
"in_systemd_nspawn",
7577
]
7678

7779

@@ -3305,3 +3307,11 @@ def adjust_int_max_str_digits(max_digits):
33053307
yield
33063308
finally:
33073309
sys.set_int_max_str_digits(current)
3310+
3311+
3312+
def in_systemd_nspawn() -> bool:
3313+
try:
3314+
return (Path("/run/systemd/container").read_bytes().rstrip() ==
3315+
b"systemd-nspawn")
3316+
except FileNotFoundError:
3317+
return False

Lib/test/test_mmap.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from test.support import (TESTFN, import_module, unlink,
2-
requires, _2G, _4G, gc_collect, cpython_only)
2+
requires, _2G, _4G, gc_collect, cpython_only,
3+
in_systemd_nspawn,)
34
import unittest
45
import os
56
import re
@@ -740,7 +741,7 @@ def test_flush_return_value(self):
740741
mm.write(b'python')
741742
result = mm.flush()
742743
self.assertIsNone(result)
743-
if sys.platform.startswith('linux'):
744+
if sys.platform.startswith('linux') and not in_systemd_nspawn():
744745
# 'offset' must be a multiple of mmap.PAGESIZE on Linux.
745746
# See bpo-34754 for details.
746747
self.assertRaises(OSError, mm.flush, 1, len(b'python'))

Lib/test/test_os.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1965,8 +1965,12 @@ def test_chmod(self):
19651965

19661966

19671967
class TestInvalidFD(unittest.TestCase):
1968-
singles = ["fchdir", "dup", "fdopen", "fdatasync", "fstat",
1969-
"fstatvfs", "fsync", "tcgetpgrp", "ttyname"]
1968+
singles = ["fchdir", "dup", "fdopen", "fstat",
1969+
"fstatvfs", "tcgetpgrp", "ttyname"]
1970+
# systemd-nspawn --suppress-sync=true does not verify fd passed
1971+
# fdatasync() and fsync(), and always returns success
1972+
if not support.in_systemd_nspawn():
1973+
singles += ["fdatasync", "fsync"]
19701974
#singles.append("close")
19711975
#We omit close because it doesn't raise an exception on some platforms
19721976
def get_single(f):

0 commit comments

Comments
 (0)