From 8e5c0a82f756111f00a63dde2172c80e4b921efa Mon Sep 17 00:00:00 2001 From: Josh Wu Date: Mon, 16 Oct 2023 14:12:03 +0800 Subject: [PATCH] Add timeout to all scan calls to avoid halt --- avatar/cases/le_host_test.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/avatar/cases/le_host_test.py b/avatar/cases/le_host_test.py index b6ab4aa..8af96fa 100644 --- a/avatar/cases/le_host_test.py +++ b/avatar/cases/le_host_test.py @@ -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: @@ -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)) @@ -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() @@ -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 @@ -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