test: survival tests skip while a web UI tab holds a socket slot

The web UI now uses /ws, one slot per open tab. The tests that fill all 5
slots failed with a timeout while a tab was open; they now skip and say
to close it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
cjkas 2026-10-25 21:21:05 +01:00
parent 2ae2dd8af0
commit 2fc45a13b2
2 changed files with 22 additions and 2 deletions

View file

@ -17,4 +17,6 @@ Runs against a real device on your network, by hand, never in CI. It checks sock
A plain run sends nothing on air, changes no setting (it saves only values the device already has) and doesn't reboot the device. The command tests send ops that are refused before they reach the radio, and one `setPositions` that sets a shade to the position the sync gave: that drops the fraction of a percent the shade's believed position may have had. The edit tests send edits that are refused, and one shade sort order set to the order it has, which saves the shades again unchanged. The settings tests send saves that are refused, and one that saves the NTP server and time zone the device already has. The frequency scan test pauses the radio's sending for a second or two, as a scan does. It does fill every socket slot for a few seconds, and replays a page load. A plain run sends nothing on air, changes no setting (it saves only values the device already has) and doesn't reboot the device. The command tests send ops that are refused before they reach the radio, and one `setPositions` that sets a shade to the position the sync gave: that drops the fraction of a percent the shade's believed position may have had. The edit tests send edits that are refused, and one shade sort order set to the order it has, which saves the shades again unchanged. The settings tests send saves that are refused, and one that saves the NTP server and time zone the device already has. The frequency scan test pauses the radio's sending for a second or two, as a scan does. It does fill every socket slot for a few seconds, and replays a page load.
The web UI holds one of the device's 5 socket slots for each open tab. The tests that fill every slot skip while one is taken, so close the UI's tabs before a run.
The tests run in whatever security mode the device is in; the suite never changes it. To test both modes, run the suite once in each. The tests run in whatever security mode the device is in; the suite never changes it. To test both modes, run the suite once in each.

View file

@ -2,6 +2,7 @@
(docs/adr/0005-one-websocket-protocol.md): every client reconnecting at once, (docs/adr/0005-one-websocket-protocol.md): every client reconnecting at once,
and a browser loading the page.""" and a browser loading the page."""
import threading import threading
import time
import urllib.request import urllib.request
import pytest import pytest
@ -29,7 +30,24 @@ def watch_heap(host):
assert after["min"] >= HEAP_FLOOR, "the heap fell to %u bytes (floor %u)" % (after["min"], HEAP_FLOOR) assert after["min"] >= HEAP_FLOOR, "the heap fell to %u bytes (floor %u)" % (after["min"], HEAP_FLOOR)
def test_every_client_reconnecting_at_once(connect, schema, watch_heap): @pytest.fixture
def all_slots_free(host, token):
"""Skips unless every socket slot is free. The web UI holds one per open
tab, which would leave these tests a client short."""
clients = [ProtoClient(host, params={"apikey": token} if token else None) for _ in range(MAX_CLIENTS)]
try:
time.sleep(1)
taken = sum(1 for c in clients if c.closed.is_set())
finally:
for c in clients:
c.close()
# The device frees a slot when it sees the disconnect.
time.sleep(0.5)
if taken:
pytest.skip("%u socket slot(s) in use, likely by the web UI: close its tabs" % taken)
def test_every_client_reconnecting_at_once(connect, schema, watch_heap, all_slots_free):
clients = [connect() for _ in range(MAX_CLIENTS)] clients = [connect() for _ in range(MAX_CLIENTS)]
errors = [] errors = []
@ -44,7 +62,7 @@ def test_every_client_reconnecting_at_once(connect, schema, watch_heap):
assert not errors, errors assert not errors, errors
def test_one_client_too_many_is_closed(connect, schema): def test_one_client_too_many_is_closed(connect, schema, all_slots_free):
clients = [connect(schema=schema.hash) for _ in range(MAX_CLIENTS)] clients = [connect(schema=schema.hash) for _ in range(MAX_CLIENTS)]
for c in clients: for c in clients:
run_sync(c) run_sync(c)