Skip to content

Commit

Permalink
test: Fix test_request_name_queue sometimes failing
Browse files Browse the repository at this point in the history
If D-Bus daemon is too slow test might try to check if the name
was acquired the name before bus managed to switch names.
  • Loading branch information
igo95862 committed Jan 21, 2023
1 parent 89e6c40 commit 18a1671
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion test/test_request_name.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
from __future__ import annotations

from asyncio import wait_for
from asyncio import get_running_loop, sleep, wait_for
from unittest import main

from sdbus.exceptions import (
Expand All @@ -31,6 +31,7 @@
)
from sdbus.sd_bus_internals import NameAllowReplacementFlag, NameQueueFlag
from sdbus.unittest import IsolatedDbusTestCase
from sdbus_async.dbus_daemon import FreedesktopDbus

from sdbus import (
request_default_bus_name,
Expand Down Expand Up @@ -199,8 +200,25 @@ async def test_request_name_queue(self) -> None:
queue=True,
)

async def catch_owner_changed() -> str:
dbus = FreedesktopDbus()
async for name, old, new in dbus.name_owner_changed:
if name != TEST_BUS_NAME:
continue

if old and new:
return new

raise RuntimeError

loop = get_running_loop()
owner_changed_task = loop.create_task(catch_owner_changed())
await sleep(0)

extra_bus.close()

await wait_for(owner_changed_task, timeout=0.5)

with self.assertRaises(SdBusRequestNameAlreadyOwnerError):
await request_default_bus_name_async(TEST_BUS_NAME)

Expand Down

0 comments on commit 18a1671

Please sign in to comment.