mirror of
https://github.com/google/bumble.git
synced 2026-04-18 00:45:32 +00:00
release command semaphore after timeout
This commit is contained in:
@@ -692,10 +692,8 @@ class Host(utils.EventEmitter):
|
|||||||
finally:
|
finally:
|
||||||
self.pending_command = None
|
self.pending_command = None
|
||||||
self.pending_response = None
|
self.pending_response = None
|
||||||
if (
|
if response is None or (
|
||||||
response is not None
|
response.num_hci_command_packets and self.command_semaphore.locked()
|
||||||
and response.num_hci_command_packets
|
|
||||||
and self.command_semaphore.locked()
|
|
||||||
):
|
):
|
||||||
self.command_semaphore.release()
|
self.command_semaphore.release()
|
||||||
|
|
||||||
|
|||||||
@@ -171,14 +171,15 @@ class Source:
|
|||||||
|
|
||||||
|
|
||||||
class Sink:
|
class Sink:
|
||||||
response: HCI_Event
|
response: HCI_Event | None
|
||||||
|
|
||||||
def __init__(self, source: Source, response: HCI_Event) -> None:
|
def __init__(self, source: Source, response: HCI_Event | None) -> None:
|
||||||
self.source = source
|
self.source = source
|
||||||
self.response = response
|
self.response = response
|
||||||
|
|
||||||
def on_packet(self, packet: bytes) -> None:
|
def on_packet(self, packet: bytes) -> None:
|
||||||
self.source.sink.on_packet(bytes(self.response))
|
if self.response is not None:
|
||||||
|
self.source.sink.on_packet(bytes(self.response))
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
@@ -228,6 +229,23 @@ async def test_send_sync_command() -> None:
|
|||||||
assert isinstance(response3.return_parameters, HCI_GenericReturnParameters)
|
assert isinstance(response3.return_parameters, HCI_GenericReturnParameters)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
async def test_send_sync_command_timeout() -> None:
|
||||||
|
source = Source()
|
||||||
|
sink = Sink(source, None)
|
||||||
|
|
||||||
|
host = Host(source, sink)
|
||||||
|
host.ready = True
|
||||||
|
|
||||||
|
with pytest.raises(asyncio.TimeoutError):
|
||||||
|
await host.send_sync_command(HCI_Reset_Command(), response_timeout=0.01)
|
||||||
|
|
||||||
|
# The sending semaphore should have been released, so this should not block
|
||||||
|
# indefinitely
|
||||||
|
with pytest.raises(asyncio.TimeoutError):
|
||||||
|
await host.send_sync_command(hci.HCI_Reset_Command(), response_timeout=0.01)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_send_async_command() -> None:
|
async def test_send_async_command() -> None:
|
||||||
source = Source()
|
source = Source()
|
||||||
|
|||||||
Reference in New Issue
Block a user