diff options
author | Sam Thursfield <sam@afuera.me.uk> | 2014-08-02 02:20:11 +0100 |
---|---|---|
committer | Sam Thursfield <sam@afuera.me.uk> | 2014-12-26 00:00:15 +0000 |
commit | 315dd05bbe37100ac76dfce14b57e7e358956188 (patch) | |
tree | b956844dd10fc98166df40efd9364ba24a6ee879 | |
parent | 34d360d0e5d17062027fa60a2ba989afc4b71987 (diff) | |
download | tracker-315dd05bbe37100ac76dfce14b57e7e358956188.tar.gz |
functional-tests: Add await_property_changed() method
This allows detecting when a file move has been done, and probably other
useful things too.
-rw-r--r-- | tests/functional-tests/common/utils/helpers.py | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/tests/functional-tests/common/utils/helpers.py b/tests/functional-tests/common/utils/helpers.py index 5ad4a4fef..d90196dda 100644 --- a/tests/functional-tests/common/utils/helpers.py +++ b/tests/functional-tests/common/utils/helpers.py @@ -431,6 +431,46 @@ class StoreHelper (Helper): 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): try: return self.resources.SparqlQuery (query, timeout=timeout) |