test(e2e): the slot tests fill the free slots

Home Assistant holds a socket slot whenever it runs, so the tests that
needed every slot never ran on a device it uses. They now fill the slots
left and skip only when none is.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
cjkas 2026-10-27 22:24:48 +01:00
parent cfa298f053
commit c57b4bf432
2 changed files with 11 additions and 10 deletions

View file

@ -18,6 +18,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 web UI holds one of the device's 5 socket slots for each open tab, and Home Assistant holds one. The tests that fill every slot fill the ones left, so close the UI's tabs for the full load.
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

@ -31,9 +31,9 @@ def watch_heap(host, token):
@pytest.fixture @pytest.fixture
def all_slots_free(host, token): def free_slots(host, token):
"""Skips unless every socket slot is free. The web UI holds one per open """How many socket slots no other client holds. The web UI holds one per
tab, which would leave these tests a client short.""" open tab and Home Assistant one, so the tests fill what is left."""
clients = [ProtoClient(host, params={"apikey": token} if token else None) for _ in range(MAX_CLIENTS)] clients = [ProtoClient(host, params={"apikey": token} if token else None) for _ in range(MAX_CLIENTS)]
try: try:
time.sleep(1) time.sleep(1)
@ -43,14 +43,15 @@ def all_slots_free(host, token):
c.close() c.close()
# The device frees a slot when it sees the disconnect. # The device frees a slot when it sees the disconnect.
time.sleep(0.5) time.sleep(0.5)
if taken: if taken == MAX_CLIENTS:
pytest.skip("%u socket slot(s) in use, likely by the web UI: close its tabs" % taken) pytest.skip("every socket slot is in use: close the web UI's tabs")
return MAX_CLIENTS - taken
# watch_heap comes before connect so pytest tears connect down first: the # watch_heap comes before connect so pytest tears connect down first: the
# heap check after the test needs a free slot. # heap check after the test needs a free slot.
def test_every_client_reconnecting_at_once(watch_heap, all_slots_free, connect, schema): def test_every_client_reconnecting_at_once(watch_heap, free_slots, connect, schema):
clients = [connect() for _ in range(MAX_CLIENTS)] clients = [connect() for _ in range(free_slots)]
errors = [] errors = []
def sync(c): def sync(c):
@ -64,8 +65,8 @@ def test_every_client_reconnecting_at_once(watch_heap, all_slots_free, connect,
assert not errors, errors assert not errors, errors
def test_one_client_too_many_is_closed(connect, schema, all_slots_free): def test_one_client_too_many_is_closed(connect, schema, free_slots):
clients = [connect(schema=schema.hash) for _ in range(MAX_CLIENTS)] clients = [connect(schema=schema.hash) for _ in range(free_slots)]
for c in clients: for c in clients:
run_sync(c) run_sync(c)
extra = connect(schema=schema.hash) extra = connect(schema=schema.hash)