dbus unit tests
Alec Leamas
leamas.alec at gmail.com
Tue Dec 5 11:47:25 UTC 2023
Hi Simon,
On 05/12/2023 12:04, Simon McVittie wrote:
> On Tue, 05 Dec 2023 at 10:13:42 +0100, Alec Leamas wrote:
>> I'm working with a program (still opencpn) which is about to bring some unit
>> tests using dbus. These tests works outside the sandbox in a native build.
>>
>> However, they fail when applied in the flatpak build. The reason seems to be
>> that there is no dbus session bus, DBUS_SESSION_BUS_ADDRESS is undefined.
>
> The autobuilders used by Linux distributions for traditional, non-Flatpak
> packaging systems like dpkg and RPM typically do not provide a session
> bus either, so this is a problem that would have to be solved with or
> without Flatpak.
>
> The upstream project (opencpn) should probably use dbus-run-session(1)
Well, here I am the upstream project...
> from the reference implementation of D-Bus to start a temporary session
> bus, or start a temporary session bus manually some other way (for example
> GLib's GTestDBus, if it uses GLib). If it doesn't, the workaround would be
> for the Flatpak packaging (and dpkg packaging, and RPM packaging, etc.) to
> wrap the test suite in something like dbus-run-session.
hm... I'm just diving into the dbus stuff, so this is black magic.
dbus-run-session should work fine in a native build, but it is not
available in the sandbox?
Yes, we are using GLib, but not GTest (we are on googletest).
Seems to boil down to using dbus-run-session where it is available and
simply disable the tests otherwise when the session isn't available.
> It is usually wrong for unit tests to be on the "real" session bus
> anyway, because the test should usually to be communicating with a mock
> implementation of whatever services it wants (or the real implementation
> in a special mode that will operate on a mock data directory, or similar),
> not real services that will overwrite your real data.
That's what I do, I have simple python mock-ups for both the server and
the client side (opencpn does both). Being a newbie I havn't considered
the risks of using the global session bus. As you say, these risks are
of course obvious.
Cheers!
--alec
More information about the Flatpak
mailing list