summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Thursfield <sam@afuera.me.uk>2018-07-21 18:46:24 +0200
committerSam Thursfield <sam@afuera.me.uk>2018-07-21 18:46:24 +0200
commit2bcf53a209c5bfc413af177cfd783f87d82d3e76 (patch)
tree18857a500daf2dd4300e656aa1fcf7961331eba1
parentda971357f43f1f1168950cbe980e1d95561ca891 (diff)
downloadtracker-2bcf53a209c5bfc413af177cfd783f87d82d3e76.tar.gz
functional-tests: Remove unused code from helpers.py
This functionality is alive and well in the tracker-miners.git fork of this code, and has seen lots of fixes. Rather than let this version get out of sync, let's remove it until something actually needs it.
-rw-r--r--tests/functional-tests/common/utils/helpers.py227
1 files changed, 1 insertions, 226 deletions
diff --git a/tests/functional-tests/common/utils/helpers.py b/tests/functional-tests/common/utils/helpers.py
index a900b8b0a..2b328846f 100644
--- a/tests/functional-tests/common/utils/helpers.py
+++ b/tests/functional-tests/common/utils/helpers.py
@@ -49,9 +49,7 @@ class Helper:
The process is watched using a timed GLib main loop source. If the process
exits with an error code, the test will abort the next time the main loop
- is entered (or straight away if currently running the main loop). Tests
- that block waiting for results in time.sleep() won't benefit from this, but
- it works for those that use await_resource_inserted()/deleted() and others.
+ is entered (or straight away if currently running the main loop).
"""
BUS_NAME = None
@@ -223,8 +221,6 @@ class StoreHelper (Helper):
PROCESS_PATH = cfg.TRACKER_STORE_PATH
BUS_NAME = cfg.TRACKER_BUSNAME
- graph_updated_handler_id = 0
-
def start (self, env=None):
Helper.start (self, env=env)
@@ -248,230 +244,9 @@ class StoreHelper (Helper):
self.status_iface.Wait ()
log ("[%s] ready." % self.PROCESS_NAME)
- self.reset_graph_updates_tracking ()
-
- def signal_handler(proxy, sender_name, signal_name, parameters):
- if signal_name == 'GraphUpdated':
- self._graph_updated_cb(*parameters.unpack())
-
- self.graph_updated_handler_id = self.resources.connect(
- 'g-signal', signal_handler)
-
def stop (self):
Helper.stop (self)
- if self.graph_updated_handler_id != 0:
- self.resources.disconnect(self.graph_updated_handler_id)
-
- # A system to follow GraphUpdated and make sure all changes are tracked.
- # This code saves every change notification received, and exposes methods
- # to await insertion or deletion of a certain resource which first check
- # the list of events already received and wait for more if the event has
- # not yet happened.
-
- def reset_graph_updates_tracking (self):
- self.inserts_list = []
- self.deletes_list = []
- self.inserts_match_function = None
- self.deletes_match_function = None
- self.graph_updated_timed_out = False
-
- def _graph_updated_timeout_cb (self):
- # Don't fail here, exceptions don't get propagated correctly
- # from the GMainLoop
- self.graph_updated_timed_out = True
- self.loop.quit ()
-
- def _graph_updated_cb (self, class_name, deletes_list, inserts_list):
- """
- Process notifications from tracker-store on resource changes.
- """
- exit_loop = False
-
- if inserts_list is not None:
- if self.inserts_match_function is not None:
- # The match function will remove matched entries from the list
- (exit_loop, inserts_list) = self.inserts_match_function (inserts_list)
- self.inserts_list += inserts_list
-
- if deletes_list is not None:
- if self.deletes_match_function is not None:
- (exit_loop, deletes_list) = self.deletes_match_function (deletes_list)
- self.deletes_list += deletes_list
-
- if exit_loop:
- GLib.source_remove(self.graph_updated_timeout_id)
- self.graph_updated_timeout_id = 0
- self.loop.quit ()
-
- def _enable_await_timeout (self):
- self.graph_updated_timeout_id = GLib.timeout_add_seconds (REASONABLE_TIMEOUT,
- self._graph_updated_timeout_cb)
-
- def await_resource_inserted (self, rdf_class, url = None, title = None, required_property = None):
- """
- Block until a resource matching the parameters becomes available
- """
- assert (self.inserts_match_function == None)
-
- self.matched_resource_urn = None
- self.matched_resource_id = None
-
- log ("Await new %s (%i existing inserts)" % (rdf_class, len (self.inserts_list)))
-
- if required_property is not None:
- required_property_id = self.get_resource_id_by_uri(required_property)
- log ("Required property %s id %i" % (required_property, required_property_id))
-
- def find_resource_insertion (inserts_list):
- matched_creation = (self.matched_resource_id is not None)
- matched_required_property = False
- remaining_events = []
-
- # FIXME: this could be done in an easier way: build one query that filters
- # based on every subject id in inserts_list, and returns the id of the one
- # that matched :)
- for insert in inserts_list:
- id = insert[1]
-
- if not matched_creation:
- where = " ?urn a %s " % rdf_class
-
- if url is not None:
- where += "; nie:url \"%s\"" % url
-
- if title is not None:
- where += "; nie:title \"%s\"" % title
-
- query = "SELECT ?urn WHERE { %s FILTER (tracker:id(?urn) = %s)}" % (where, insert[1])
- result_set = self.query (query)
-
- if len (result_set) > 0:
- matched_creation = True
- self.matched_resource_urn = result_set[0][0]
- self.matched_resource_id = insert[1]
- log ("Matched creation of resource %s (%i)" %
- (self.matched_resource_urn,
- self.matched_resource_id))
- if required_property is not None:
- log ("Waiting for property %s (%i) to be set" %
- (required_property, required_property_id))
-
- if required_property is not None and matched_creation and not matched_required_property:
- if id == self.matched_resource_id and insert[2] == required_property_id:
- matched_required_property = True
- log ("Matched %s %s" % (self.matched_resource_urn, required_property))
-
- if not matched_creation or id != self.matched_resource_id:
- remaining_events += [insert]
-
- matched = matched_creation if required_property is None else matched_required_property
- return matched, remaining_events
-
- def match_cb (inserts_list):
- matched, remaining_events = find_resource_insertion (inserts_list)
- exit_loop = matched
- return exit_loop, remaining_events
-
- # Check the list of previously received events for matches
- (existing_match, self.inserts_list) = find_resource_insertion (self.inserts_list)
-
- if not existing_match:
- self._enable_await_timeout ()
- self.inserts_match_function = match_cb
- # Run the event loop until the correct notification arrives
- self.loop.run ()
- self.inserts_match_function = None
-
- if self.graph_updated_timed_out:
- raise Exception ("Timeout waiting for resource: class %s, URL %s, title %s" % (rdf_class, url, title))
-
- return (self.matched_resource_id, self.matched_resource_urn)
-
- def await_resource_deleted (self, id, fail_message = None):
- """
- Block until we are notified of a resources deletion
- """
- assert (self.deletes_match_function == None)
-
- def find_resource_deletion (deletes_list):
- log ("find_resource_deletion: looking for %i in %s" % (id, deletes_list))
-
- matched = False
- remaining_events = []
-
- for delete in deletes_list:
- if delete[1] == id:
- matched = True
- else:
- remaining_events += [delete]
-
- return matched, remaining_events
-
- def match_cb (deletes_list):
- matched, remaining_events = find_resource_deletion(deletes_list)
- exit_loop = matched
- return exit_loop, remaining_events
-
- log ("Await deletion of %i (%i existing)" % (id, len (self.deletes_list)))
-
- (existing_match, self.deletes_list) = find_resource_deletion (self.deletes_list)
-
- if not existing_match:
- self._enable_await_timeout ()
- self.deletes_match_function = match_cb
- # Run the event loop until the correct notification arrives
- self.loop.run ()
- self.deletes_match_function = None
-
- if self.graph_updated_timed_out:
- if fail_message is not None:
- raise Exception (fail_message)
- else:
- raise Exception ("Resource %i has not been deleted." % id)
-
- return
-
- def await_property_changed (self, subject_id, property_uri):
- """
- Block until a property of a resource is updated or inserted.
- """
- assert (self.inserts_match_function == None)
-
- property_id = self.get_resource_id_by_uri(property_uri)
-
- def find_property_change (inserts_list):
- matched = False
- remaining_events = []
-
- for insert in inserts_list:
- if insert[1] == subject_id and insert[2] == property_id:
- log("Matched property change: %s" % str(insert))
- matched = True
- else:
- remaining_events += [insert]
-
- return matched, remaining_events
-
- def match_cb (inserts_list):
- matched, remaining_events = find_property_change (inserts_list)
- exit_loop = matched
- return exit_loop, remaining_events
-
- # Check the list of previously received events for matches
- (existing_match, self.inserts_list) = find_property_change (self.inserts_list)
-
- if not existing_match:
- self._enable_await_timeout ()
- self.inserts_match_function = match_cb
- # Run the event loop until the correct notification arrives
- self.loop.run ()
- self.inserts_match_function = None
-
- if self.graph_updated_timed_out:
- raise Exception ("Timeout waiting for property change, subject %i "
- "property %s" % (subject_id, property_uri))
-
def query (self, query, timeout=5000, **kwargs):
return self.resources.SparqlQuery ('(s)', query, timeout=timeout, **kwargs)