tests: the refused-port checks of the network tests allow Windows' own refusal time (lane 15)

On the owner PC five of the new network tests failed: a refused loopback connection takes 2.03-2.04 s to be reported on Windows (measured, five runs,
ConnectionRefusedError 10061: Windows tries the connection again before it reports the refusal), longer than the tests' scaled windows of 0.4 and
0.8 s, so the refused port looked like a timeout ("no_answer" instead of "offline", a waiting line, an elapsed time over the 0.5 s "at once" limit).
On Linux and macOS the refusal is immediate.

The refused-port tests (test_netpolicy.ClearFailuresAreImmediate, test_net_transfer.TransferRule and FeedRule, test_net_launch_waits.SetupDownloadWaits)
now use windows of 3 / 6 s, a waiting-line delay of 3 s and an "at once" limit of 4 s on Windows (tests/terminal/test_netpolicy.py: REFUSED_WINDOW,
REFUSED_WAIT_LINE_S, AT_ONCE_S). Linux and macOS keep 0.4 / 0.8 s and 0.5 s. The launch check that the step's own sentence comes before setup says
anything no longer uses a stopwatch (0.2 s failed at 0.25 s on a slow runner): it checks the order of the two sentences. Product code is unchanged: every production window (12 s, 30 s, 5 s for the optional reads)
is longer than the 2.04 s, so a refused connection is still reported as offline on Windows.

The owner PC run of the four files (these three plus test_net_guard.py): 47 passed, 2 skipped.
This commit is contained in:
Niko1221 committed 2026-11-10 20:19:14 +01:00
1 parent 70bfa88d66
commit f88ea5bb00
3 files changed
+21 -10

No files matched your search

+7 -4
View File
@@ -16,7 +16,7 @@ from strata_cli.launch import cmd
from strata_cli.launch.runner import Event, LaunchError, Runner, capital
from strata_control import netpolicy, progress_words
from tests.terminal.test_flow2_022 import Base as FlowBase
from tests.terminal.test_netpolicy import BlackHole, Server, ok_body, refused_port
from tests.terminal.test_netpolicy import AT_ONCE_S, REFUSED_WAIT_LINE_S, REFUSED_WINDOW, BlackHole, Server, ok_body, refused_port
def scaled():
@@ -94,9 +94,10 @@ class SetupDownloadWaits(unittest.TestCase):
def test_a_refusing_port_fails_at_once_with_no_waiting_line(self):
port = refused_port()
code, out, took = self.download(f"http://127.0.0.1:{port}/m/model-00001-of-00002.gguf")
with mock.patch.object(netpolicy, "CONNECT_LIMITS", REFUSED_WINDOW), mock.patch.object(netpolicy, "WAIT_LINE_AFTER_S", REFUSED_WAIT_LINE_S):
code, out, took = self.download(f"http://127.0.0.1:{port}/m/model-00001-of-00002.gguf")
self.assertEqual(code, 1)
self.assertLess(took, 0.5)
self.assertLess(took, AT_ONCE_S)
self.assertNotIn("Waiting for", out)
self.assertIn("[X] This computer could not connect to 127.0.0.1 (it looks offline), so the model files could not be downloaded.", out)
@@ -143,7 +144,9 @@ class LaunchShowsTheWait(FlowBase):
texts = [x for _t, x in seen]
self.assertIn("Waiting for huggingface.co to answer (5 s so far)", texts)
self.assertIn("Waiting for huggingface.co to answer (15 s so far)", texts)
self.assertLess(seen[0][0], 0.2) # the step's own sentence at once, before setup says anything
# the step's own sentence comes first, before setup has said anything (an order, not a stopwatch: a slow or loaded machine only moves both)
self.assertFalse(seen[0][1].startswith("Waiting for"), seen[0])
self.assertLess(seen[0][0], next(t for t, x in seen if x.startswith("Waiting for")))
self.assertIn("The model could not be installed. huggingface.co did not answer within 44 seconds, so the model files could not "
"be downloaded.", err.text)
self.assertIn("Check that this computer can open https://huggingface.co", err.next)
+4 -4
View File
@@ -16,7 +16,7 @@ from pathlib import Path
from unittest import mock
from strata_control import feed, netpolicy, transfer
from tests.terminal.test_netpolicy import BlackHole, Server, refused_port
from tests.terminal.test_netpolicy import AT_ONCE_S, REFUSED_WINDOW, BlackHole, Server, refused_port
BODY = bytes(range(256)) * 40 # 10,240 bytes
SHA = hashlib.sha256(BODY).hexdigest()
@@ -94,9 +94,9 @@ class TransferRule(Scaled):
def test_a_refused_port_fails_at_once(self):
t0 = time.monotonic()
with self.assertRaises(transfer.Unreachable) as cm:
with mock.patch.object(netpolicy, "CONNECT_LIMITS", REFUSED_WINDOW), self.assertRaises(transfer.Unreachable) as cm:
self.fetch(f"http://127.0.0.1:{refused_port()}/e.tar.gz")
self.assertLess(time.monotonic() - t0, 0.5)
self.assertLess(time.monotonic() - t0, AT_ONCE_S)
self.assertEqual(cm.exception.failure.kind, "offline")
def test_a_working_download(self):
@@ -183,7 +183,7 @@ class FeedRule(Scaled):
t0 = time.monotonic()
with self.assertRaises(feed.FeedError) as cm:
feed.fetch(f"http://127.0.0.1:{refused_port()}/strata-feed.json", {"k": b"x" * 32}, timeout=30)
self.assertLess(time.monotonic() - t0, 0.5) # no wait and no retry for an offline user (owner 11-01)
self.assertLess(time.monotonic() - t0, AT_ONCE_S) # no wait and no retry for an offline user (owner 11-01)
self.assertEqual(str(cm.exception), "this computer could not connect to 127.0.0.1 (it looks offline), so the update check could not run. "
"Strata keeps working with what is installed.")
+10 -2
View File
@@ -44,6 +44,14 @@ class BlackHole:
self.sock.close()
#: "fails at once" for a refused connection. Windows itself reports a refused loopback port only after 2.03-2.04 s (measured on the owner PC: it tries the
#: connection again first), longer than the scaled test windows, so there the refused-port tests use windows of 3 / 6 s, a waiting-line delay of 3 s and
#: a limit of 4 s; on Linux and macOS the refusal is immediate (0.4 / 0.8 s windows, 0.5 s). Either way far under the rule's 12 s / 44 s windows.
AT_ONCE_S = 4.0 if os.name == "nt" else 0.5
REFUSED_WINDOW = (3.0, 6.0) if os.name == "nt" else (0.4, 0.8)
REFUSED_WAIT_LINE_S = 3.0 if os.name == "nt" else 0.5
def refused_port() -> int:
s = socket.socket()
s.bind(("127.0.0.1", 0))
@@ -242,8 +250,8 @@ class ClearFailuresAreImmediate(Base):
port = refused_port()
t0 = time.monotonic()
with self.assertRaises(N.NetFailure) as cm:
self.open(f"http://127.0.0.1:{port}/f", wait_after=0.5)
self.assertLess(time.monotonic() - t0, 0.5)
self.open(f"http://127.0.0.1:{port}/f", limits=REFUSED_WINDOW, wait_after=REFUSED_WAIT_LINE_S)
self.assertLess(time.monotonic() - t0, AT_ONCE_S)
self.assertEqual(cm.exception.kind, "offline")
self.assertFalse(self.memory.failed_recently("127.0.0.1"))
self.assertIn("This computer could not connect to 127.0.0.1 (it looks offline)", cm.exception.headline("the model files"))