diff --git a/test/e2e/README.md b/test/e2e/README.md index e18355f..a42e530 100644 --- a/test/e2e/README.md +++ b/test/e2e/README.md @@ -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. +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. diff --git a/test/e2e/test_survival.py b/test/e2e/test_survival.py index a6dcae9..8c56d29 100644 --- a/test/e2e/test_survival.py +++ b/test/e2e/test_survival.py @@ -2,6 +2,7 @@ (docs/adr/0005-one-websocket-protocol.md): every client reconnecting at once, and a browser loading the page.""" import threading +import time import urllib.request 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) -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)] errors = [] @@ -44,7 +62,7 @@ def test_every_client_reconnecting_at_once(connect, schema, watch_heap): 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)] for c in clients: run_sync(c)