summaryrefslogtreecommitdiff
path: root/tests/functional-tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests/functional-tests')
-rwxr-xr-xtests/functional-tests/302-miner-on-demand.py121
-rw-r--r--tests/functional-tests/common/utils/configuration.py.in4
-rw-r--r--tests/functional-tests/common/utils/helpers.py11
-rw-r--r--tests/functional-tests/common/utils/minertest.py9
-rw-r--r--tests/functional-tests/common/utils/options.py1
5 files changed, 122 insertions, 24 deletions
diff --git a/tests/functional-tests/302-miner-on-demand.py b/tests/functional-tests/302-miner-on-demand.py
index 6f6e6af39..be29e361b 100755
--- a/tests/functional-tests/302-miner-on-demand.py
+++ b/tests/functional-tests/302-miner-on-demand.py
@@ -18,41 +18,84 @@
"""
Test on-demand indexing of locations.
-This feature exists so that applications can trigger the indexing of a
-removable device.
+This feature exists so that users can manually add files to the Tracker
+store, or trigger the indexing of a removable device.
-See: https://bugzilla.gnome.org/show_bug.cgi?id=680834
+Related bugs: https://bugzilla.gnome.org/show_bug.cgi?id=680834
"""
-from gi.repository import Gio
+from gi.repository import Gio, GLib
import time
import unittest2 as ut
from common.utils.helpers import log
-from common.utils.minertest import CommonTrackerMinerTest, uri
+from common.utils.minertest import CommonTrackerMinerTest, DEFAULT_TEXT, path, uri
class MinerOnDemandIndexingTest (CommonTrackerMinerTest):
# def test_01_index_file (self):
# """
-# Indexing a file outside the configured indexing locations.
+# Indexing and monitoring a file outside the configured locations.
#
# This can also be done from the commandline with `tracker index FILE`.
# """
#
+# store = self.system.store
+#
# # This is created by CommonTrackerMinerTest.setup() from
# # common.utils.minertest module.
# unmonitored_file = 'test-no-monitored/file0.txt'
-#
# self.assertFileMissing(uri(unmonitored_file))
#
# log("Queuing %s for indexing" % uri(unmonitored_file))
# self.system.miner_fs.index_iface.IndexFile(uri(unmonitored_file))
-# self.system.store.await_resource_inserted('nfo:TextDocument',
-# url=uri(unmonitored_file))
+# resource_id, resource_urn = store.await_resource_inserted(
+# 'nfo:TextDocument',
+# url=uri(unmonitored_file),
+# required_property='nie:plainTextContent')
+# self.assertFileContents(resource_urn, DEFAULT_TEXT)
+#
+# # When you pass a file to IndexFile, Tracker doesn't set up a monitor
+# # so changes to the file are ignored. This is a bit inconsistent
+# # compared to how directories are treated. The commented code will
+# # not work, because of that.
+#
+# #with open(path(unmonitored_file), 'w') as f:
+# # f.write('Version 2.0')
+# #store.await_property_changed(resource_id, 'nie:plainTextContent')
+# #self.assertFileContents(resource_urn, 'Version 2.0')
+#
+# def test_02_index_directory (self):
+# """
+# Indexing and monitoring a directory outside the configured locations.
#
- def test_02_index_file_for_process(self):
+# This can also be done from the commandline with `tracker index DIR`.
+# """
+#
+# store = self.system.store
+#
+# # These are created by CommonTrackerMinerTest.setup() from
+# # common.utils.minertest module.
+# unmonitored_dir = 'test-no-monitored'
+# unmonitored_file = 'test-no-monitored/file0.txt'
+# self.assertFileMissing(uri(unmonitored_dir))
+# self.assertFileMissing(uri(unmonitored_file))
+#
+# log("Queuing %s for indexing" % uri(unmonitored_dir))
+# self.system.miner_fs.index_iface.IndexFile(uri(unmonitored_dir))
+# resource_id, resource_urn = store.await_resource_inserted(
+# 'nfo:TextDocument',
+# url=uri(unmonitored_file),
+# required_property='nie:plainTextContent')
+# self.assertFileContents(resource_urn, DEFAULT_TEXT)
+#
+# with open(path(unmonitored_file), 'w') as f:
+# f.write('Version 2.0')
+# store.await_property_changed(resource_id, 'nie:plainTextContent')
+# self.assertFileContents(resource_urn, 'Version 2.0')
+
+ def test_04_index_directory_for_process(self):
"""
Indexing a directory tree for a specific D-Bus name.
@@ -60,29 +103,65 @@ class MinerOnDemandIndexingTest (CommonTrackerMinerTest):
that indexing of large removable devices can be tied to the lifetime of
certain applications that let users 'opt in' to indexing a device.
"""
+
+ miner = self.system.miner_fs
+
+ unmonitored_dir = 'test-no-monitored/'
unmonitored_file = 'test-no-monitored/file0.txt'
+ self.assertFileMissing(uri(unmonitored_dir))
self.assertFileMissing(uri(unmonitored_file))
- miner = self.system.miner_fs
+ # Open a separate connection to the session bus, so we can simulate the
+ # process ending again.
+ address = Gio.dbus_address_get_for_bus_sync(Gio.BusType.SESSION, None)
+ fake_app = Gio.DBusConnection.new_for_address_sync(
+ address,
+ Gio.DBusConnectionFlags.MESSAGE_BUS_CONNECTION |
+ Gio.DBusConnectionFlags.AUTHENTICATION_CLIENT,
+ None, None)
+ fake_app.init()
- fake_app = Gio.bus_get_sync(Gio.BusType.SESSION)
log("Opened D-Bus connection %s" % fake_app.get_unique_name())
+ # FIXME: there must be a better way of using GDBus in Python than
+ # this...
+
# Index a file for the fake_app process, but then close the fake_app
# straight away so the file doesn't get indexed. We do this while the
# miner is paused, because otherwise the file might get indexed before
# the app disappears, which would cause a spurious test failure.
- cookie = miner.miner_fs.PauseForProcess(
- fake_app.get_unique_name(),
- "Avoid test process racing with miner process.")
- miner.index_iface.IndexFile(uri(unmonitored_file))
- fake_app.close()
- log("Closed temporary D-Bus connection.")
-
+ DBUS_TIMEOUT = 5
+ pause_for_process_args = GLib.Variant('(ss)', (fake_app.get_unique_name(),
+ "Avoid test process racing with miner process."))
+ cookie = fake_app.call_sync(
+ 'org.freedesktop.Tracker1.Miner.Files',
+ '/org/freedesktop/Tracker1/Miner/Files',
+ 'org.freedesktop.Tracker1.Miner',
+ 'PauseForProcess',
+ pause_for_process_args, None, 0, DBUS_TIMEOUT, None)
+
+ index_file_for_process_args = GLib.Variant('(s)', (uri(unmonitored_dir),))
+ fake_app.call_sync(
+ 'org.freedesktop.Tracker1.Miner.Files.Index',
+ '/org/freedesktop/Tracker1/Miner/Files/Index',
+ 'org.freedesktop.Tracker1.Miner.Files.Index',
+ 'IndexFileForProcess',
+ index_file_for_process_args, None, 0, DBUS_TIMEOUT, None)
+
+ # This will cause Tracker to resume mining, and also stop indexing the
+ # file, possibly.
+ log("Closing temporary D-Bus connection.")
+ fake_app.close_sync()
+
+ bus2 = Gio.bus_get_sync(Gio.BusType.SESSION)
+ print bus2.call_sync('org.freedesktop.DBus', '/', 'org.freedesktop.DBus',
+ 'ListNames', None, None, 0, 1, None)
+
+ # We don't have to unpause the miner, it gets resumed
# The file should never get indexed, because the process disappeared.
- miner.miner_fs.Resume(cookie)
- time.sleep(5)
+ #miner.miner_fs.Resume(cookie)
#self.assertFileMissing(uri(unmonitored_file))
+ # Currently this passes, when it should actually fail!
self.system.store.await_resource_inserted('nfo:TextDocument',
url=uri(unmonitored_file))
self.assertFilePresent(uri(unmonitored_file))
diff --git a/tests/functional-tests/common/utils/configuration.py.in b/tests/functional-tests/common/utils/configuration.py.in
index d6f544140..7eb886f74 100644
--- a/tests/functional-tests/common/utils/configuration.py.in
+++ b/tests/functional-tests/common/utils/configuration.py.in
@@ -30,6 +30,10 @@ MINERFS_BUSNAME = "org.freedesktop.Tracker1.Miner.Files"
MINERFS_OBJ_PATH = "/org/freedesktop/Tracker1/Miner/Files"
MINER_IFACE = "org.freedesktop.Tracker1.Miner"
+MINERFS_INDEX_BUSNAME = "org.freedesktop.Tracker1.Miner.Files.Index"
+MINERFS_INDEX_OBJ_PATH = "/org/freedesktop/Tracker1/Miner/Files/Index"
+MINER_FILES_INDEX_IFACE = "org.freedesktop.Tracker1.Miner.Files.Index"
+
TRACKER_BACKUP_OBJ_PATH = "/org/freedesktop/Tracker1/Backup"
BACKUP_IFACE = "org.freedesktop.Tracker1.Backup"
diff --git a/tests/functional-tests/common/utils/helpers.py b/tests/functional-tests/common/utils/helpers.py
index 7b3ca88a9..4780ade3c 100644
--- a/tests/functional-tests/common/utils/helpers.py
+++ b/tests/functional-tests/common/utils/helpers.py
@@ -219,6 +219,10 @@ class Helper:
self.abort_if_process_exits_with_status_0 = False
def stop (self):
+ if options.is_manual_start():
+ log ("Manually stop %s" % self.PROCESS_NAME)
+ return
+
start = time.time()
if self.process.poll() == None:
# It should step out of this loop when the miner disappear from the bus
@@ -235,10 +239,15 @@ class Helper:
self.process.wait()
log ("[%s] stopped." % self.PROCESS_NAME)
+
# Disconnect the signals of the next start we get duplicated messages
self.bus._clean_up_signal_match (self.name_owner_match)
def kill (self):
+ if options.is_manual_start():
+ log ("Manually kill %s" % self.PROCESS_NAME)
+ return
+
self.process.kill ()
# Name owner changed callback should take us out from this loop
@@ -653,7 +662,7 @@ class MinerFsHelper (Helper):
index_bus_object = self.bus.get_object (cfg.MINERFS_INDEX_BUSNAME,
cfg.MINERFS_INDEX_OBJ_PATH)
self.index_iface = dbus.Interface (index_bus_object,
- dbus_interface = cfg.MINER_INDEX_IFACE)
+ dbus_interface = cfg.MINER_FILES_INDEX_IFACE)
def stop (self):
Helper.stop (self)
diff --git a/tests/functional-tests/common/utils/minertest.py b/tests/functional-tests/common/utils/minertest.py
index 1aa63ac1b..03aac88d3 100644
--- a/tests/functional-tests/common/utils/minertest.py
+++ b/tests/functional-tests/common/utils/minertest.py
@@ -45,13 +45,13 @@ CONF_OPTIONS = {
'index-single-directories': GLib.Variant.new_strv([]),
'index-optical-discs': GLib.Variant.new_boolean(False),
'index-removable-devices': GLib.Variant.new_boolean(False),
- 'throttle': GLib.Variant.new_int32(5),
+ 'throttle': GLib.Variant.new_int32(0),
+ 'verbosity': GLib.Variant.new_string('detailed'),
}
}
class CommonTrackerMinerTest (ut.TestCase):
-
def prepare_directories (self):
#
# ~/test-monitored/
@@ -130,3 +130,8 @@ class CommonTrackerMinerTest (ut.TestCase):
if self.tracker.ask (query) == True:
self.fail ("File <%s> should not be present in the database" %
file_url)
+
+ def assertFileContents(self, file_urn, expected_contents):
+ query = 'SELECT ?content { <%s> nie:plainTextContent ?content }' % file_urn
+ result = self.tracker.query(query)
+ self.assertEqual(result[0][0], expected_contents)
diff --git a/tests/functional-tests/common/utils/options.py b/tests/functional-tests/common/utils/options.py
index 6bc837905..4537e2db7 100644
--- a/tests/functional-tests/common/utils/options.py
+++ b/tests/functional-tests/common/utils/options.py
@@ -35,4 +35,5 @@ def is_manual_start ():
"""
False to start the processes automatically
"""
+ return True
return options.startmanually