Skip to content

Commit

Permalink
Add timeout to all scan calls to avoid halt
Browse files Browse the repository at this point in the history
  • Loading branch information
zxzxwu authored and uael committed Oct 23, 2023
1 parent 9f68bd2 commit 8e5c0a8
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions avatar/cases/le_host_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class LeHostTest(base_test.BaseTestClass): # type: ignore[misc]
def setup_class(self) -> None:
self.devices = PandoraDevices(self)
self.dut, self.ref, *_ = self.devices
self.scan_timeout = float(self.user_params.get('scan_timeout') or 15.0) # type: ignore

# Enable BR/EDR mode for Bumble devices.
for device in self.devices:
Expand Down Expand Up @@ -113,7 +114,7 @@ def test_scan(
own_address_type=PUBLIC,
)

scan = self.dut.host.Scan(legacy=False, passive=False, timeout=5.0)
scan = self.dut.host.Scan(legacy=False, passive=False, timeout=self.scan_timeout)
report = next((x for x in scan if x.public == self.ref.address))
try:
report = next((x for x in scan if x.public == self.ref.address))
Expand Down Expand Up @@ -173,7 +174,7 @@ def test_scan_response_data(self, data: Dict[str, Any]) -> None:
own_address_type=PUBLIC,
)

scan = self.dut.host.Scan(legacy=False, passive=False)
scan = self.dut.host.Scan(legacy=False, passive=False, timeout=self.scan_timeout)
report = next((x for x in scan if x.public == self.ref.address))

scan.cancel()
Expand All @@ -198,13 +199,13 @@ async def test_connect(self, ref_address_type: OwnAddressType) -> None:
data=DataTypes(manufacturer_specific_data=b'pause cafe'),
)

scan = self.dut.aio.host.Scan(own_address_type=RANDOM)
scan = self.dut.aio.host.Scan(own_address_type=RANDOM, timeout=self.scan_timeout)
ref = await anext((x async for x in scan if x.data.manufacturer_specific_data == b'pause cafe'))
scan.cancel()

ref_dut_res, dut_ref_res = await asyncio.gather(
anext(aiter(advertise)),
self.dut.aio.host.ConnectLE(**ref.address_asdict(), own_address_type=RANDOM),
self.dut.aio.host.ConnectLE(**ref.address_asdict(), own_address_type=RANDOM, timeout=self.scan_timeout),
)
assert_equal(dut_ref_res.result_variant(), 'connection')
dut_ref, ref_dut = dut_ref_res.connection, ref_dut_res.connection
Expand All @@ -226,13 +227,13 @@ async def test_disconnect(self, ref_address_type: OwnAddressType) -> None:
data=DataTypes(manufacturer_specific_data=b'pause cafe'),
)

scan = self.dut.aio.host.Scan(own_address_type=RANDOM)
scan = self.dut.aio.host.Scan(own_address_type=RANDOM, timeout=self.scan_timeout)
ref = await anext((x async for x in scan if x.data.manufacturer_specific_data == b'pause cafe'))
scan.cancel()

ref_dut_res, dut_ref_res = await asyncio.gather(
anext(aiter(advertise)),
self.dut.aio.host.ConnectLE(**ref.address_asdict(), own_address_type=RANDOM),
self.dut.aio.host.ConnectLE(**ref.address_asdict(), own_address_type=RANDOM, timeout=self.scan_timeout),
)
assert_equal(dut_ref_res.result_variant(), 'connection')
dut_ref, ref_dut = dut_ref_res.connection, ref_dut_res.connection
Expand Down

0 comments on commit 8e5c0a8

Please sign in to comment.