python-dbusmock icon indicating copy to clipboard operation
python-dbusmock copied to clipboard

EmitSignal does not support a destination

Open whot opened this issue 2 years ago • 5 comments

Note that this is an issue with dbusmock and the underlying dbus.service.signal. But since it's dbusmock that's the immediate consumer of my code, let's file a bug here :smile:

I ran into the case of libportal not receiving signals emitted by dbusmock. The reason is that libportal subscribes to signals like this:

    call->signal_id = g_dbus_connection_signal_subscribe (call->portal->bus,
                                                          PORTAL_BUS_NAME,
                                                          REQUEST_INTERFACE,
                                                          "Response",
                                                          call->request_path,
                                                          NULL,
                                                          DBUS_SIGNAL_FLAGS_NO_MATCH_RULE,  // <- the culprit                                                                                                                                                                           
                                                          response_received,
                                                          call,
                                                          NULL);

DBUS_SIGNAL_FLAGS_NO_MATCH_RULE means no AddMatch etc. is sent to the dbus server. For the normal use-case of libportal talking to xdg-desktop-portal this doesn't matter because that sends those Response signals like this:

        g_dbus_connection_emit_signal (connection,
                                       request->sender, // <- Destination argument
                                       g_dbus_interface_skeleton_get_object_path (G_DBUS_INTERFACE_SKELETON (skeleton)),
                                       "org.freedesktop.portal.Request",
                                       "Response",                                                     
                                       signal_variant,
                                       NULL);

But for dbusmock's EmitSignal(), the destination is always (null) and those signals get filtered (somewhere, not 100% sure where) and never arrive in libportal.

The libportal use-case is justified, this is a single-use object and only one destination will ever need that signal, and the object is destroyed immediately after anyway. But the problem is that I cannot test this with dbusmock.

The use of the dbus.service.signal decorator makes this dependent on python-dbus for which I've filed an MR now: https://gitlab.freedesktop.org/dbus/dbus-python/-/merge_requests/18, so we'd need this first before attempting to fix it here.

whot avatar May 27 '22 01:05 whot

Is this fixed with 4a191d8 ? If so, can we get a release of python-dbusmock with this addition to the API? I need EmitSignalDetailed for the tests I'm writing for https://phabricator.services.mozilla.com/D140803, and I'd rather refer to a released version on pypi than vendoring an unreleased version into the firefox source tree.

oSoMoN avatar Jun 16 '22 16:06 oSoMoN

Following up on my previous comment. In the context of the unit tests I'm writing for firefox that talk to a mocked WebExtensions portal, I pulled the latest changes from python-dbusmock into my virtualenv, making the EmitSignalDetailed available. I used it in my tests, and I verified that the destination was correctly set on the emitted signal (using dbus-monitor), but the code talking to the portal still wasn't notified of the signal. So it looks like something else is missing for this to work.

oSoMoN avatar Jun 16 '22 16:06 oSoMoN

At least for the tests I wrote in libportal, this patch was sufficient, at least for the dbusmock bit. The only other issue was convincing libportal to connect with the right address, the default g_bus_get_sync() and similar methods don't work if you keep switching the bus address. see the libportal/portal.c hunks in that MR.

whot avatar Jun 17 '22 02:06 whot

I was still working on #131, but there's really no urgency to that. I released 0.28.0, it's also on PyPI. Fedora and Debian updates are coming.

martinpitt avatar Jun 19 '22 13:06 martinpitt

Thanks @martinpitt !

oSoMoN avatar Jun 20 '22 19:06 oSoMoN

This was released months ago. I'm closing this, please yell if there's still something left here. Thanks!

martinpitt avatar Oct 11 '22 15:10 martinpitt