-
Notifications
You must be signed in to change notification settings - Fork 350
Allow empty notification when using "AcquireNotify" #1983
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
dlech
wants to merge
2
commits into
hbldh:develop
Choose a base branch
from
dlech:bluez-empty-notification
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+151
−4
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| import asyncio | ||
|
|
||
| import pytest | ||
| from bumble.att import Attribute | ||
| from bumble.device import Device | ||
| from bumble.gatt import Characteristic, Service | ||
| from bumble.hci import HCI_REMOTE_USER_TERMINATED_CONNECTION_ERROR | ||
|
|
||
| from bleak import BleakClient | ||
| from bleak.backends import BleakBackend, get_default_backend | ||
| from bleak.backends.characteristic import BleakGATTCharacteristic | ||
| from tests.integration.conftest import ( | ||
| configure_and_power_on_bumble_peripheral, | ||
| find_ble_device, | ||
| ) | ||
|
|
||
| TEST_SERVICE_UUID = "9d513f40-5c89-42dc-9688-2cfa30f2d9e7" | ||
| TEST_CHARACTERISTIC_UUID = "e809cb2f-34e3-42a1-ba92-22db2495cd6a" | ||
|
|
||
|
|
||
| @pytest.mark.skipif( | ||
| get_default_backend() != BleakBackend.BLUEZ_DBUS, | ||
| reason="issue present in BlueZ backend only", | ||
| ) | ||
| async def test_empty_notification_disconnect_disambiguation( | ||
| bumble_peripheral: Device, | ||
| ) -> None: | ||
| """ | ||
| Ensure disconnecting an active notification stream does not deliver EOF as b"". | ||
|
|
||
| This is a weird case that only affects BlueZ when use_start_notify is False. | ||
|
|
||
| Regression test for: https://github.com/hbldh/bleak/issues/1982 | ||
| """ | ||
|
|
||
| test_characteristic = Characteristic[bytes]( | ||
| TEST_CHARACTERISTIC_UUID, | ||
| Characteristic.Properties.NOTIFY, | ||
| Attribute.Permissions(0), | ||
| ) | ||
|
|
||
| await configure_and_power_on_bumble_peripheral( | ||
| bumble_peripheral, services=[Service(TEST_SERVICE_UUID, [test_characteristic])] | ||
| ) | ||
|
|
||
| device = await find_ble_device(bumble_peripheral) | ||
|
|
||
| async with BleakClient(device, services=[TEST_SERVICE_UUID]) as client: | ||
|
|
||
| notified_data: asyncio.Queue[bytes] = asyncio.Queue() | ||
|
|
||
| def notify_callback(characteristic: BleakGATTCharacteristic, data: bytearray): | ||
| assert characteristic.uuid.lower() == TEST_CHARACTERISTIC_UUID | ||
| notified_data.put_nowait(bytes(data)) | ||
|
|
||
| await client.start_notify( | ||
| TEST_CHARACTERISTIC_UUID, | ||
| notify_callback, | ||
| bluez={"use_start_notify": False}, | ||
| ) | ||
|
|
||
| connection = next(iter(bumble_peripheral.connections.values())) | ||
|
|
||
| await bumble_peripheral.disconnect( | ||
| connection, HCI_REMOTE_USER_TERMINATED_CONNECTION_ERROR | ||
| ) | ||
|
|
||
| # A closed AcquireNotify fd/disconnect must not be surfaced as an empty notification. | ||
| with pytest.raises(asyncio.TimeoutError): | ||
| await asyncio.wait_for(notified_data.get(), timeout=1) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.