Basic integrationtests for BleakClient#1888
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #1888 +/- ##
===========================================
+ Coverage 46.26% 48.24% +1.97%
===========================================
Files 38 38
Lines 3839 3839
Branches 463 463
===========================================
+ Hits 1776 1852 +76
+ Misses 1953 1864 -89
- Partials 110 123 +13
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
According to the BlueZ source code, it should only be 2 seconds. #define DISCONNECT_TIMER 2
...
void device_request_disconnect(struct btd_device *device, DBusMessage *msg)
{
...
device->disconn_timer = timeout_add_seconds(DISCONNECT_TIMER,
disconnect_all,
device, NULL);
...
}There are 3 possible implementations for |
dlech
left a comment
There was a problem hiding this comment.
Looks like a good start.
I wouldn't mind splitting this up into a few files already (connecting, characteristics, descriptors, pairing, properties) as I expect we will eventually add many more tests to cover error paths. Doing that in a single file would make the file too long.
| virtual_characteristic = Characteristic( | ||
| READ_CHARACTERISITC_UUID, | ||
| Characteristic.Properties.READ, | ||
| Characteristic.READABLE, |
There was a problem hiding this comment.
| Characteristic.READABLE, | |
| Attribute.Permission.READABLE, |
Bumble source code says: Permission flags(legacy-use only) on Characteristic.READABLE.
There was a problem hiding this comment.
I think Characteristic.Permission.READABLE is more readable than Attribute.Permission.READABLE
| assert isinstance(client.mtu_size, int) | ||
|
|
||
|
|
||
| @pytest.mark.skipif( |
There was a problem hiding this comment.
Rather than two different tests where one gets skipped, I would write it as one.
There was a problem hiding this comment.
I don't think it makes sense to combine these two cases. To get around the question, I've completely removed the unimplemented case for now. Then we can think about it again later when we add the pairing tests.
I just tried running tests locally with |
|
Profiling shows that it is spending all of it's time on |
|
The problem seems to be in the Linux kernel. Running We can see the expected 2 second delay from However, there is an 18 second delay between the MGMT command to the kernel and actually sending the HCI command. |
|
OK, the disconnect is actually coming from a 20 second timeout in I think the kernel is expecting |
diff --git a/tests/integration/bluez_controller.py b/tests/integration/bluez_controller.py
index f8f5142..07168c4 100644
--- a/tests/integration/bluez_controller.py
+++ b/tests/integration/bluez_controller.py
@@ -147,6 +147,7 @@ async def open_bluez_bluetooth_controller_link(
host_sink=hci_transport.sink,
link=link,
)
+ bluez_controller.le_features = bytes.fromhex("0000000000000000")
bluez_controller.manufacturer_name = BLEAK_TEST_MANUFACTURER_ID
# Wait up to 5 seconds for the new adapter to appear via InterfacesAddedSeems to do the trick. I just set it to all 0s and didn't check to see what else I was disabling yet though. |
d1c4201 to
e8d8dc8
Compare
e8d8dc8 to
8b38834
Compare
|
Thanks for your investigations in the timing problem and fixing it in #1890. I would never have found it so quickly. I have addressed all your points, so this PR is ready for a new review. |
|
I have addressed all your points, so this PR is ready for a new review. |
|
Thanks! |
Lock in the current BlueZ and WinRT pair()/unpair() contract before the pairing-agent series reworks it, so later refactors cannot silently regress today's behavior. - winrt: idempotent already-paired return, can_pair guard, Just Works success + handler detach, result-status failure, the deprecated protection_level keyword, and unpair status handling. - bluez: already-paired return, Trusted-then-Pair + resolvable-private- address refresh, D-Bus failure propagation (no agent is registered on develop, so a real Pair fails, cf. hbldh#1380 / hbldh#1434), and unpair RemoveDevice / DoesNotExist mapping. - integration: a connect/disconnect/unpair smoke test for the existing unpair path. Expands the integration harness from hbldh#1888. Addresses dlech's request on hbldh#1990 to split the work and add tests for existing pairing functions first. Part of the pairing series continuing hbldh#1864. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This PR adds basic integration tests for the
BleakClient.Unfortunately, there is a problem in the Alpine VM where terminating a
BleakClientconnection always takes 20 seconds. This greatly increases the testing time in CI... Locally on my Ubuntu, terminating the connection always takes a constant 4 seconds. I find that long too, but it's still reasonably tolerable. However, I can't explain why it takes 20 seconds in Alpine VM. @dlech, do you have any idea what could be causing this?My last commit adds additional logging output, enables the log output in CI and only executes one test case because the log output is huge... Searching for
Disconnected from device afterhelps :) I will revert that changes once the problem is found.E.g this run outputs: