Fix onboard K1 enrollment continuity and share named acquisition preparation
This commit is contained in:
@@ -28,8 +28,10 @@ def isolated_owner(tmp_path):
|
||||
|
||||
@pytest.mark.parametrize("operation", ["read", "provision"])
|
||||
@pytest.mark.parametrize("native", [
|
||||
"macos", "present", "vanished", "absent", "wrong-address", "wrong-adapter",
|
||||
"vanished-again", "owner-changed", "invalidated", "connect-failed", "write-failed",
|
||||
"macos", "present", "cache-cleanup-race", "vanished", "absent",
|
||||
"wrong-address", "wrong-adapter",
|
||||
"vanished-again", "owner-changed", "invalidated", "connect-failed",
|
||||
"connect-cancelled", "write-failed",
|
||||
])
|
||||
def test_selected_transport_survives_native_cache_loss(monkeypatch, operation, native):
|
||||
address = "AA:BB:CC:DD:EE:FF"
|
||||
@@ -42,7 +44,7 @@ def test_selected_transport_survives_native_cache_loss(monkeypatch, operation, n
|
||||
async def retrieve(selected_address, details):
|
||||
assert selected_address == address and details["path"] == path
|
||||
events.append("cache")
|
||||
present = native == "present" or (
|
||||
present = native in {"present", "cache-cleanup-race"} or (
|
||||
events.count("cache") == 2 and native != "vanished-again"
|
||||
)
|
||||
return device if present else None
|
||||
@@ -90,6 +92,12 @@ def test_selected_transport_survives_native_cache_loss(monkeypatch, operation, n
|
||||
|
||||
async def __aenter__(self):
|
||||
events.append("connect")
|
||||
if native == "cache-cleanup-race":
|
||||
await asyncio.sleep(0) # The D-Bus connection yields to BlueZ cleanup.
|
||||
if events.count("hold-discovery") <= events.count("release-discovery"):
|
||||
raise BleakError("selected device not found before watcher registration")
|
||||
if native == "connect-cancelled":
|
||||
raise asyncio.CancelledError()
|
||||
if native == "connect-failed":
|
||||
raise BleakError("synthetic native connection failure")
|
||||
return self
|
||||
@@ -99,6 +107,8 @@ def test_selected_transport_survives_native_cache_loss(monkeypatch, operation, n
|
||||
|
||||
async def read_gatt_char(self, characteristic):
|
||||
assert characteristic is status
|
||||
if native != "macos":
|
||||
assert "release-discovery" in events
|
||||
events.append("read")
|
||||
value = bytearray(52)
|
||||
value[0] = 11
|
||||
@@ -118,7 +128,20 @@ def test_selected_transport_survives_native_cache_loss(monkeypatch, operation, n
|
||||
platform="darwin" if native == "macos" else "linux",
|
||||
))
|
||||
monkeypatch.setattr(scanner, "_retrieve_bluez_device", retrieve)
|
||||
monkeypatch.setattr(scanner.BleakScanner, "find_device_by_address", find)
|
||||
class Scanner:
|
||||
find_device_by_address = staticmethod(find)
|
||||
|
||||
def __init__(self, *, bluez):
|
||||
assert bluez == {"adapter": "hci7"}
|
||||
|
||||
async def __aenter__(self):
|
||||
events.append("hold-discovery")
|
||||
return self
|
||||
|
||||
async def __aexit__(self, *_args):
|
||||
events.append("release-discovery")
|
||||
|
||||
monkeypatch.setattr(scanner, "BleakScanner", Scanner)
|
||||
monkeypatch.setattr(wifi, "BleakClient", Client)
|
||||
|
||||
async def scenario():
|
||||
@@ -142,7 +165,11 @@ def test_selected_transport_survives_native_cache_loss(monkeypatch, operation, n
|
||||
"absent", "wrong-address", "wrong-adapter", "vanished-again",
|
||||
"owner-changed", "invalidated",
|
||||
}
|
||||
if fails_before_connect or native == "connect-failed" or (
|
||||
if native == "connect-cancelled":
|
||||
with pytest.raises(asyncio.CancelledError):
|
||||
await action
|
||||
assert "read" not in events and "write" not in events
|
||||
elif fails_before_connect or native == "connect-failed" or (
|
||||
native == "write-failed" and operation == "provision"
|
||||
):
|
||||
with pytest.raises(BleakError) as raised:
|
||||
@@ -165,6 +192,8 @@ def test_selected_transport_survives_native_cache_loss(monkeypatch, operation, n
|
||||
assert scanner._runtime_handle_generation == generation # noqa: SLF001
|
||||
|
||||
asyncio.run(scenario())
|
||||
assert events.count("scan") == (native not in {"macos", "present"})
|
||||
assert events.count("scan") == (native not in {"macos", "present", "cache-cleanup-race"})
|
||||
assert events.count("hold-discovery") == events.count("release-discovery")
|
||||
assert events.count("hold-discovery") == (native != "macos")
|
||||
assert events.count("connect") <= 1
|
||||
assert events.count("write") <= 1
|
||||
|
||||
Reference in New Issue
Block a user