From 58d96af3484a2957fa6d982c8ade816aa0c4a42c Mon Sep 17 00:00:00 2001 From: Carlos Garnacho Date: Sat, 20 Feb 2021 21:55:49 +0100 Subject: tests: Add test for notifier events within a sandbox The propagation of events to a local TrackerSparqlConnection used to be broken. Add a test to ensure we don't regress here. --- tests/functional-tests/fixtures.py | 9 +++++++ tests/functional-tests/portal.py | 48 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/tests/functional-tests/fixtures.py b/tests/functional-tests/fixtures.py index 0f406a01e..2e338ed81 100644 --- a/tests/functional-tests/fixtures.py +++ b/tests/functional-tests/fixtures.py @@ -210,6 +210,7 @@ class TrackerPortalTest(ut.TestCase): extra_env = {} extra_env['TRACKER_TEST_PORTAL_FLATPAK_INFO'] = cfg.TEST_PORTAL_FLATPAK_INFO + self.loop = trackertestutils.mainloop.MainLoop() self.message_queues = {} self.connections = {} self.sandbox = trackertestutils.helpers.TrackerDBusSandbox( @@ -219,6 +220,7 @@ class TrackerPortalTest(ut.TestCase): self.bus = self.sandbox.get_session_bus_connection() self.dbus_address = self.sandbox.get_session_bus_address() + os.environ['DBUS_SESSION_BUS_ADDRESS'] = self.dbus_address try: log.info("Starting portal") @@ -272,6 +274,13 @@ class TrackerPortalTest(ut.TestCase): return store.query(sparql) + def create_local_connection(self): + return Tracker.SparqlConnection.new( + Tracker.SparqlConnectionFlags.NONE, + None, + Gio.File.new_for_path(cfg.ontologies_dir()), + None) + class CliError(Exception): pass diff --git a/tests/functional-tests/portal.py b/tests/functional-tests/portal.py index 194f4e86b..e292ce6af 100644 --- a/tests/functional-tests/portal.py +++ b/tests/functional-tests/portal.py @@ -20,7 +20,11 @@ Test portal """ +import gi +gi.require_version('Tracker', '3.0') from gi.repository import GLib +from gi.repository import Gio +from gi.repository import Tracker import unittest @@ -73,5 +77,49 @@ class TestPortal(fixtures.TrackerPortalTest): self.assertEqual(res[2][1], '6') self.assertEqual(len(res[2]), 2) + def __wait_for_notifier(self): + """ + In the callback of the signals, there should be a self.loop.quit () + """ + self.timeout_id = GLib.timeout_add_seconds( + configuration.DEFAULT_TIMEOUT, self.__timeout_on_idle) + self.loop.run_checked() + + def __timeout_on_idle(self): + self.loop.quit() + self.fail("Timeout, the signal never came after %i seconds!" % configuration.DEFAULT_TIMEOUT) + + def __notifier_event_cb(self, notifier, service, graph, events): + if self.timeout_id != 0: + GLib.source_remove(self.timeout_id) + self.timeout_id = 0 + self.loop.quit() + + def test_05_local_connection_notifier(self): + self.start_service('org.freedesktop.PortalTest') + + conn = self.create_local_connection() + notifier = conn.create_notifier(); + notifier.connect('events', self.__notifier_event_cb) + signalId = notifier.signal_subscribe( + self.bus, + 'org.freedesktop.PortalTest', + None, + None) + + self.update( + 'org.freedesktop.PortalTest', + 'INSERT { GRAPH tracker:Allowed { a nmm:MusicPiece } }') + + self.__wait_for_notifier() + notifier.signal_unsubscribe(signalId); + conn.close() + + res = self.query( + 'org.freedesktop.PortalTest', + 'select ?a { ?a a nmm:MusicPiece }') + self.assertEqual(len(res), 1) + self.assertEqual(res[0][0], 'b') + if __name__ == '__main__': fixtures.tracker_test_main() -- cgit v1.2.1