The device picker's rescan tests wait for scans, not for 50 ms

The fake splash ran the rescan for a fixed 50 ms and assumed several
rounds would fit. On Windows a 1 ms sleep lasts a whole ~15 ms timer tick
and each scan goes through a worker thread, so under a full run the
window sometimes held a single round and "a device going away" never got
its second scan. The fake now runs until the script's rounds, and a few
more, have actually been scanned, with a 10 s deadline that fails with
its own message rather than as a missing redraw.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Jean-Pierre MartineauandClaude Opus 5.5 committed 2026-10-04 13:27:25 -04:00
1 parent b6e7cd5c16
commit 8b742ea270
1 file changed
+12 -2
+12 -2
View File
@@ -3628,14 +3628,23 @@ def _drive_picker(tmp_path, monkeypatch, *, serial_rounds, ble_rounds=None, hide
store.hide(stable)
redraws: list = []
# Scans to let run: every scripted round, then enough more that the last round's redraw
# has happened (a round redraws before the next scan starts) and the Bluetooth duty
# cycle — one listen per few polls — has had room to show.
scans = len(serial) + 5
class _Ui:
async def select_startup( # noqa: ANN001, ANN201, ANN003
self, title, items, *, default=None, banner=None, footnote=None, live=None, **_kw
):
task = asyncio.ensure_future(live(redraws.append))
# Long enough for the script to run several times over at this cadence.
await asyncio.sleep(0.05)
# Wait for the scans themselves, never for a span of time: a fixed 50 ms held a
# handful of rounds on a quiet machine and sometimes only one under a full run,
# since Windows rounds each 1 ms sleep up to its ~15 ms timer tick.
loop = asyncio.get_running_loop()
deadline = loop.time() + 10.0
while calls["serial"] < scans and loop.time() < deadline:
await asyncio.sleep(0.001)
task.cancel()
try:
await task
@@ -3647,6 +3656,7 @@ def _drive_picker(tmp_path, monkeypatch, *, serial_rounds, ble_rounds=None, hide
raise AssertionError("verify should not run when selection is skipped")
asyncio.run(device_picker.prompt_device(_Ui(), list(serial[0]), store, _never))
assert calls["serial"] >= scans, f"the rescan ran {calls['serial']} of {scans} scans in 10 s"
return redraws, calls