diff --git a/src/rhsmlib/dbus/objects/register.py b/src/rhsmlib/dbus/objects/register.py index 2d37edb47b..3b03419606 100644 --- a/src/rhsmlib/dbus/objects/register.py +++ b/src/rhsmlib/dbus/objects/register.py @@ -85,8 +85,7 @@ def stop(self, sender: str) -> bool: # If there is at least one sender using this server still running, then # only return False self.server.remove_sender(sender) - bus = dbus.SystemBus() - if self.server.are_other_senders_still_running(bus) is True: + if self.server.are_other_senders_still_running() is True: log.debug("Not stopping domain socket server, because some senders still uses it.") return False diff --git a/src/rhsmlib/dbus/server.py b/src/rhsmlib/dbus/server.py index 64de9a057a..909a2dfaa1 100644 --- a/src/rhsmlib/dbus/server.py +++ b/src/rhsmlib/dbus/server.py @@ -353,7 +353,7 @@ def remove_sender(self, sender: str) -> bool: log.debug(f"Sender {sender} removed from the set of senders") return True - def are_other_senders_still_running(self, bus) -> bool: + def are_other_senders_still_running(self) -> bool: """ Check if other users are still running. It sender in the set is not running, then remove sender from the set, because sender could @@ -361,6 +361,7 @@ def are_other_senders_still_running(self, bus) -> bool: """ is_one_sender_running = False not_running = set() + bus = dbus.SystemBus() for sender in self._senders: pid = pid_of_sender(bus, sender) if pid is None: diff --git a/test/rhsmlib/dbus/test_register.py b/test/rhsmlib/dbus/test_register.py index 5556d1fe4f..e4934e8849 100644 --- a/test/rhsmlib/dbus/test_register.py +++ b/test/rhsmlib/dbus/test_register.py @@ -347,6 +347,13 @@ def setUp(self) -> None: pid_of_sender_mock = pid_of_sender_patch.start() pid_of_sender_mock.return_value = 123456 + are_others_running_path = mock.patch( + "rhsmlib.dbus.server.DomainSocketServer.are_other_senders_still_running", + autospec=True, + ) + are_others_running_mock = are_others_running_path.start() + are_others_running_mock.return_value = False + dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) def tearDown(self) -> None: