Skip to content

Commit

Permalink
WIP: another attempt to fix unit tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
jirihnidek committed Nov 6, 2023
1 parent d8ea2cb commit 374b592
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
3 changes: 1 addition & 2 deletions src/rhsmlib/dbus/objects/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion src/rhsmlib/dbus/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,14 +353,15 @@ 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
crash, or it was terminated since it called Start() method.
"""
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:
Expand Down
7 changes: 7 additions & 0 deletions test/rhsmlib/dbus/test_register.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 374b592

Please sign in to comment.