diff --git a/tests/run_bleak_version_mp.py b/tests/run_bleak_version_mp.py new file mode 100644 index 0000000..651b21e --- /dev/null +++ b/tests/run_bleak_version_mp.py @@ -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() diff --git a/tests/test_bleak_version.py b/tests/test_bleak_version.py new file mode 100644 index 0000000..63ff3e0 --- /dev/null +++ b/tests/test_bleak_version.py @@ -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 + + +