Skip to content

Conversation

mgorny
Copy link
Contributor

@mgorny mgorny commented Sep 18, 2024

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.

…n 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.
Add a docstring explaining the function in detail.  Switch from pathlib
to plain `open().read()`.  Update the news entry.
@mgorny
Copy link
Contributor Author

mgorny commented Sep 20, 2024

Thanks. Updated per your comments.

Thinking about it, I think I could make the skips a bit more specific — that is, detect systemd-nspawn + check whether os.open(…, os.O_RDONLY|os.O_SYNC) yields EINVAL.

Call `os.open("", os.O_RDONLY | os.O_SYNC)` and check the errno to
detect whether `--suppress-sync=true` is actually used, and skip
the tests only in that scenario.
Copy link
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@vstinner vstinner enabled auto-merge (squash) September 20, 2024 13:15
self.assertIsNone(result)
if sys.platform.startswith(('linux', 'android')):
if (sys.platform.startswith(('linux', 'android'))
and not in_systemd_nspawn_sync_suppressed()):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be honest, I wanted to avoid this because it's very confusing when the condition has the same indent as the code below.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah but the line was too long. That's the problem of long function names.

Comment on lines +843 to +844
if (sys.platform.startswith(('linux', 'android'))
and not in_systemd_nspawn_sync_suppressed()):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we could follow black here:

Suggested change
if (sys.platform.startswith(('linux', 'android'))
and not in_systemd_nspawn_sync_suppressed()):
if (
sys.platform.startswith(("linux", "android"))
and not in_systemd_nspawn_sync_suppressed()
):

@vstinner vstinner merged commit 342e654 into python:main Sep 20, 2024
34 checks passed
@vstinner
Copy link
Member

Merged, thanks.

@mgorny mgorny deleted the nspawn-skips branch September 20, 2024 15:02
@mgorny
Copy link
Contributor Author

mgorny commented Sep 20, 2024

Thanks!

savannahostrowski pushed a commit to savannahostrowski/cpython that referenced this pull request Sep 22, 2024
…sync=true (python#124215)

Add a helper function 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.

Call `os.open(__file__, os.O_RDONLY | os.O_SYNC)` and check the errno to
detect whether `--suppress-sync=true` is actually used, and skip
the tests only in that scenario.
savannahostrowski pushed a commit to savannahostrowski/cpython that referenced this pull request Sep 22, 2024
…sync=true (python#124215)

Add a helper function 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.

Call `os.open(__file__, os.O_RDONLY | os.O_SYNC)` and check the errno to
detect whether `--suppress-sync=true` is actually used, and skip
the tests only in that scenario.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants