test(gateway): run the TCP-witness Windows arm natively via windows_only
test_loop_tick_witness_arms_over_tcp_on_windows swapped the module's `os` binding for a proxy reporting name="nt" so a Linux interpreter would take the non-POSIX branch. That is the "Don't fake the host OS" case: the test only passes if the interpreter believes it is on another OS. Mark it windows_only so the tests-os lane runs it on windows-latest for real; scripts/ci/list_os_marked_tests.py picks the file up by marker name and it is skipped (not errored) on Linux/macOS. The create=True tripwire from the earlier salvage commit is what makes it runnable there.
This commit is contained in:
@@ -123,25 +123,15 @@ def short_home():
|
||||
shutil.rmtree(path, ignore_errors=True)
|
||||
|
||||
|
||||
@pytest.mark.windows_only
|
||||
@pytest.mark.asyncio
|
||||
async def test_loop_tick_witness_arms_over_tcp_on_windows(
|
||||
short_home, caplog, monkeypatch
|
||||
):
|
||||
"""Non-POSIX never touches AF_UNIX; the witness arms over TCP loopback."""
|
||||
async def test_loop_tick_witness_arms_over_tcp_on_windows(short_home, caplog):
|
||||
"""Non-POSIX never touches AF_UNIX; the witness arms over TCP loopback.
|
||||
|
||||
Runs on native Windows (``os.name == "nt"`` for real) rather than faking
|
||||
the platform from Linux — see "Don't fake the host OS" in AGENTS.md.
|
||||
"""
|
||||
tmp_path = short_home
|
||||
# Pretend the platform is Windows as seen from the module under test.
|
||||
# A plain monkeypatch of the global os.name would flip pathlib.Path
|
||||
# dispatch (Path.__new__ reads os.name at runtime) and crash pytest's
|
||||
# own tmp-dir machinery, so swap the module's `os` binding for a proxy
|
||||
# whose `.name` is "nt" and which delegates everything else to real os.
|
||||
class _WindowsOsProxy:
|
||||
name = "nt"
|
||||
|
||||
def __getattr__(self, item):
|
||||
return getattr(os, item)
|
||||
|
||||
monkeypatch.setattr(shutdown_watchdog_module, "os", _WindowsOsProxy())
|
||||
|
||||
start_unix_server_calls = []
|
||||
|
||||
def _forbid_start_unix_server(*args, **kwargs):
|
||||
@@ -152,12 +142,10 @@ async def test_loop_tick_witness_arms_over_tcp_on_windows(
|
||||
shutdown_watchdog_module.asyncio,
|
||||
"start_unix_server",
|
||||
side_effect=_forbid_start_unix_server,
|
||||
# ``asyncio.start_unix_server`` only exists where an AF_UNIX event loop
|
||||
# does. On native Windows the attribute is absent, so without create=True
|
||||
# patch.object itself raises AttributeError — the test could only ever
|
||||
# pass on POSIX, the platform it pretends not to be. create=True arms
|
||||
# the forbidden-call tripwire everywhere and mock deletes the created
|
||||
# attribute on exit.
|
||||
# ``asyncio.start_unix_server`` does not exist on native Windows, so
|
||||
# without create=True patch.object itself raises AttributeError.
|
||||
# create=True arms the forbidden-call tripwire anyway and mock
|
||||
# deletes the created attribute on exit.
|
||||
create=True,
|
||||
), caplog.at_level(logging.DEBUG, logger="gateway.shutdown_watchdog"):
|
||||
payload = await _run_heartbeat_until_payload(tmp_path)
|
||||
|
||||
Reference in New Issue
Block a user