Skip to content

Commit

Permalink
Add tests for tracing down the issue with bluetoothctl version
Browse files Browse the repository at this point in the history
As it turned out, there was a regression in Python 3.11.1
related to loss of output from subprocesses.

Refs: hbldh/bleak#1183
      python/cpython#100133
  • Loading branch information
jeffsf committed Jan 23, 2023
1 parent 7c8a607 commit aa1a558
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
28 changes: 28 additions & 0 deletions tests/run_bleak_version_mp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import asyncio
import multiprocessing
import os

import bleak.backends.bluezdbus.version as bv

async def subprocess_task():
version_output = await bv._get_bluetoothctl_version()
if version_output:
major, minor = tuple(map(int, version_output.groups()))
print(major, minor)
else:
print("No version_output")
await asyncio.sleep(1.0)

def subprocess_work():
sploop = asyncio.new_event_loop()
print(f"Inner loop: {sploop} {os.getpid()} {sploop._selector}")
sploop.run_until_complete(subprocess_task())


if __name__ == '__main__':
multiprocessing.set_start_method('spawn', force=True)
loop = asyncio.new_event_loop()
print(f"Outer loop: {loop} {os.getpid()} {loop._selector}")
loop.run_until_complete(subprocess_task())
p = multiprocessing.Process(target=subprocess_work)
p.start()
14 changes: 14 additions & 0 deletions tests/test_bleak_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import bleak.backends.bluezdbus.version as bv

import pytest

@pytest.mark.asyncio
async def test_version():
version_output = await bv._get_bluetoothctl_version()
assert version_output
major, minor = tuple(map(int, version_output.groups()))
assert major == 5
assert minor == 55



0 comments on commit aa1a558

Please sign in to comment.