[tracker-miners/sam/increase-timeouts: 1/2] tests: Add TRACKER_TEST_AWAIT_TIMEOUT
- From: Sam Thursfield <sthursfield src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker-miners/sam/increase-timeouts: 1/2] tests: Add TRACKER_TEST_AWAIT_TIMEOUT
- Date: Sat, 13 Jun 2020 18:48:04 +0000 (UTC)
commit fb63c81e340f01ebfb7642d13dd0865c3305e24c
Author: Sam Thursfield <sam afuera me uk>
Date: Sat Jun 13 20:45:51 2020 +0200
tests: Add TRACKER_TEST_AWAIT_TIMEOUT
This allows us to use a longer timeout in CI, without forcing long
timeouts on developers.
Fixes https://gitlab.gnome.org/GNOME/tracker-miners/-/issues/110
tests/functional-tests/configuration.py | 9 ++++++---
tests/functional-tests/extractor-decorator.py | 7 +++++--
tests/functional-tests/fixtures.py | 16 +++++++++-------
tests/functional-tests/fts-file-operations.py | 2 +-
tests/functional-tests/miner-basic.py | 12 ++++++------
tests/functional-tests/miner-resource-removal.py | 7 +++++--
tests/functional-tests/minerhelper.py | 5 ++++-
7 files changed, 36 insertions(+), 22 deletions(-)
---
diff --git a/tests/functional-tests/configuration.py b/tests/functional-tests/configuration.py
index 3f3d96c0e..72e035b8c 100644
--- a/tests/functional-tests/configuration.py
+++ b/tests/functional-tests/configuration.py
@@ -30,9 +30,6 @@ import tempfile
import sys
-DEFAULT_TIMEOUT = 10
-
-
if 'TRACKER_FUNCTIONAL_TEST_CONFIG' not in os.environ:
raise RuntimeError("The TRACKER_FUNCTIONAL_TEST_CONFIG environment "
"variable must be set to point to the location of "
@@ -124,6 +121,12 @@ def tests_verbose():
return get_environment_boolean('TRACKER_TESTS_VERBOSE')
+# Timeout when awaiting resources. For developers, we want a short default
+# so they don't spend a long time waiting for tests to fail. For CI we want
+# to set a longer timeout so we don't see failures on slow CI runners.
+AWAIT_TIMEOUT = get_environment_int('TRACKER_TESTS_AWAIT_TIMEOUT', default=10)
+
+
DEBUG_TESTS_NO_CLEANUP = 1
_debug_flags = None
diff --git a/tests/functional-tests/extractor-decorator.py b/tests/functional-tests/extractor-decorator.py
index da9d7f834..41c8eec17 100755
--- a/tests/functional-tests/extractor-decorator.py
+++ b/tests/functional-tests/extractor-decorator.py
@@ -24,6 +24,7 @@ import os
import shutil
import unittest as ut
+import configuration as cfg
import fixtures
@@ -44,7 +45,8 @@ class ExtractorDecoratorTest(fixtures.TrackerMinerTest):
# Insert a valid file and wait extraction of its metadata.
file_path = os.path.join(self.indexed_dir, os.path.basename(VALID_FILE))
expected = f'a nmm:MusicPiece ; nie:title "{VALID_FILE_TITLE}"'
- with self.tracker.await_insert(fixtures.AUDIO_GRAPH, expected) as resource:
+ with self.tracker.await_insert(fixtures.AUDIO_GRAPH, expected,
+ timeout=cfg.AWAIT_TIMEOUT) as resource:
shutil.copy(VALID_FILE, file_path)
file_urn = resource.urn
@@ -62,7 +64,8 @@ class ExtractorDecoratorTest(fixtures.TrackerMinerTest):
# Request re-indexing (same as `tracker index --file ...`)
# The extractor should reindex the file and re-add the metadata that we
# deleted, so we should see the nie:title property change.
- with self.tracker.await_insert(fixtures.AUDIO_GRAPH, f'nie:title "{VALID_FILE_TITLE}"'):
+ with self.tracker.await_insert(fixtures.AUDIO_GRAPH, f'nie:title "{VALID_FILE_TITLE}"',
+ timeout=cfg.AWAIT_TIMEOUT):
miner_fs.index_file(file_uri)
title_result = store.query('SELECT ?title { <%s> nie:interpretedAs/nie:title ?title }' %
file_uri)
diff --git a/tests/functional-tests/fixtures.py b/tests/functional-tests/fixtures.py
index ac332fd56..f6efe7adb 100644
--- a/tests/functional-tests/fixtures.py
+++ b/tests/functional-tests/fixtures.py
@@ -150,7 +150,7 @@ class TrackerMinerTest(ut.TestCase):
content_escaped = Tracker.sparql_escape_string(content)
expected += [f'nie:plainTextContent "{content_escaped}"']
- return self.tracker.await_insert(DOCUMENTS_GRAPH, '; '.join(expected))
+ return self.tracker.await_insert(DOCUMENTS_GRAPH, '; '.join(expected), timeout=cfg.AWAIT_TIMEOUT)
def await_document_uri_change(self, resource_id, from_path, to_path):
"""Wraps await_update() context manager."""
@@ -159,7 +159,8 @@ class TrackerMinerTest(ut.TestCase):
return self.tracker.await_property_update(DOCUMENTS_GRAPH,
resource_id,
f'nie:isStoredAs <{from_url}>',
- f'nie:isStoredAs <{to_url}>')
+ f'nie:isStoredAs <{to_url}>',
+ timeout=cfg.AWAIT_TIMEOUT)
def await_photo_inserted(self, path):
url = self.uri(path)
@@ -169,7 +170,7 @@ class TrackerMinerTest(ut.TestCase):
f'nie:isStoredAs <{url}>',
]
- return self.tracker.await_insert(PICTURES_GRAPH, '; '.join(expected))
+ return self.tracker.await_insert(PICTURES_GRAPH, '; '.join(expected), timeout=cfg.AWAIT_TIMEOUT)
class TrackerMinerFTSTest (TrackerMinerTest):
@@ -197,12 +198,13 @@ class TrackerMinerFTSTest (TrackerMinerTest):
with self.tracker.await_content_update(DOCUMENTS_GRAPH,
resource_id,
f'nie:plainTextContent "{old_text_escaped}"',
- f'nie:plainTextContent "{text_escaped}"'):
+ f'nie:plainTextContent "{text_escaped}"',
+ timeout=cfg.AWAIT_TIMEOUT):
path.write_text(text)
else:
url = self.uri(self.testfile)
expected = f'a nfo:Document; nie:isStoredAs <{url}>; nie:plainTextContent "{text_escaped}"'
- with self.tracker.await_insert(DOCUMENTS_GRAPH, expected):
+ with self.tracker.await_insert(DOCUMENTS_GRAPH, expected, timeout=cfg.AWAIT_TIMEOUT):
path.write_text(text)
def search_word(self, word):
@@ -423,7 +425,7 @@ class TrackerWritebackTest (TrackerMinerTest):
# Copy and wait.
expected = f'nie:url <{url}>'
- with self.tracker.await_insert(FILESYSTEM_GRAPH, expected):
+ with self.tracker.await_insert(FILESYSTEM_GRAPH, expected, timeout=cfg.AWAIT_TIMEOUT):
shutil.copy(filename, self.indexed_dir)
return path
@@ -433,7 +435,7 @@ class TrackerWritebackTest (TrackerMinerTest):
# Copy and wait.
expected = f'nie:url <{url}>'
- with self.tracker.await_insert(FILESYSTEM_GRAPH, expected):
+ with self.tracker.await_insert(FILESYSTEM_GRAPH, expected, timeout=cfg.AWAIT_TIMEOUT):
shutil.copy(source_path, self.indexed_dir)
return dest_path
diff --git a/tests/functional-tests/fts-file-operations.py b/tests/functional-tests/fts-file-operations.py
index 3323100fb..4af78dc71 100755
--- a/tests/functional-tests/fts-file-operations.py
+++ b/tests/functional-tests/fts-file-operations.py
@@ -55,7 +55,7 @@ class MinerFTSFileOperationsTest(fixtures.TrackerMinerFTSTest):
self.basic_test(TEXT, "automobile")
id = self._query_id(self.uri(self.testfile))
- with self.tracker.await_delete(fixtures.DOCUMENTS_GRAPH, id):
+ with self.tracker.await_delete(fixtures.DOCUMENTS_GRAPH, id, timeout=cfg.AWAIT_TIMEOUT):
os.remove(self.path(self.testfile))
results = self.search_word("automobile")
diff --git a/tests/functional-tests/miner-basic.py b/tests/functional-tests/miner-basic.py
index 396d7c662..7c5a5d687 100755
--- a/tests/functional-tests/miner-basic.py
+++ b/tests/functional-tests/miner-basic.py
@@ -162,7 +162,7 @@ class MinerCrawlTest(fixtures.TrackerMinerTest):
self.assertIn(self.uri("test-monitored/file0.txt"), unpacked_result)
# Clean the new file so the test directory is as before
- with self.tracker.await_delete(fixtures.DOCUMENTS_GRAPH, dest_id):
+ with self.tracker.await_delete(fixtures.DOCUMENTS_GRAPH, dest_id, timeout=cfg.AWAIT_TIMEOUT):
os.remove(dest)
def test_03_copy_from_monitored_to_unmonitored(self):
@@ -207,7 +207,7 @@ class MinerCrawlTest(fixtures.TrackerMinerTest):
self.assertIn(self.uri("test-monitored/dir1/dir2/file3.txt"), unpacked_result)
self.assertIn(self.uri("test-monitored/dir1/dir2/file-test04.txt"), unpacked_result)
- with self.tracker.await_delete(fixtures.DOCUMENTS_GRAPH, dest_id):
+ with self.tracker.await_delete(fixtures.DOCUMENTS_GRAPH, dest_id, timeout=cfg.AWAIT_TIMEOUT):
os.remove(dest)
self.assertEqual(3, self.tracker.count_instances("nfo:TextDocument"))
@@ -232,7 +232,7 @@ class MinerCrawlTest(fixtures.TrackerMinerTest):
self.assertIn(self.uri("test-monitored/dir1/dir2/file3.txt"), unpacked_result)
self.assertIn(self.uri("test-monitored/dir1/file-test05.txt"), unpacked_result)
- with self.tracker.await_delete(fixtures.DOCUMENTS_GRAPH, dest_id):
+ with self.tracker.await_delete(fixtures.DOCUMENTS_GRAPH, dest_id, timeout=cfg.AWAIT_TIMEOUT):
os.remove(dest)
self.assertEqual(3, self.tracker.count_instances("nfo:TextDocument"))
@@ -247,7 +247,7 @@ class MinerCrawlTest(fixtures.TrackerMinerTest):
source = self.path("test-monitored/dir1/file2.txt")
dest = self.path("test-no-monitored/file2.txt")
source_id = self.tracker.get_content_resource_id(self.uri(source))
- with self.tracker.await_delete(fixtures.DOCUMENTS_GRAPH, source_id):
+ with self.tracker.await_delete(fixtures.DOCUMENTS_GRAPH, source_id, timeout=cfg.AWAIT_TIMEOUT):
shutil.move(source, dest)
result = self.__get_text_documents()
@@ -305,7 +305,7 @@ class MinerCrawlTest(fixtures.TrackerMinerTest):
"""
victim = self.path("test-monitored/dir1/file2.txt")
victim_id = self.tracker.get_content_resource_id(self.uri(victim))
- with self.tracker.await_delete(fixtures.DOCUMENTS_GRAPH, victim_id):
+ with self.tracker.await_delete(fixtures.DOCUMENTS_GRAPH, victim_id, timeout=cfg.AWAIT_TIMEOUT):
os.remove(victim)
result = self.__get_text_documents()
@@ -328,7 +328,7 @@ class MinerCrawlTest(fixtures.TrackerMinerTest):
file_inside_victim_url = self.uri(os.path.join(victim, "file2.txt"))
file_inside_victim_id = self.tracker.get_content_resource_id(file_inside_victim_url)
- with self.tracker.await_delete(fixtures.DOCUMENTS_GRAPH, file_inside_victim_id):
+ with self.tracker.await_delete(fixtures.DOCUMENTS_GRAPH, file_inside_victim_id,
timeout=cfg.AWAIT_TIMEOUT):
shutil.rmtree(victim)
result = self.__get_text_documents()
diff --git a/tests/functional-tests/miner-resource-removal.py
b/tests/functional-tests/miner-resource-removal.py
index 390727616..cf0fd1fd0 100755
--- a/tests/functional-tests/miner-resource-removal.py
+++ b/tests/functional-tests/miner-resource-removal.py
@@ -25,6 +25,7 @@ import os
import pathlib
import unittest as ut
+import configuration as cfg
import fixtures
@@ -41,7 +42,9 @@ class MinerResourceRemovalTest(fixtures.TrackerMinerTest):
nie:isStoredAs <%s> . \
} " % (fixtures.AUDIO_GRAPH, file_urn, title, url)
- with self.tracker.await_insert(fixtures.AUDIO_GRAPH, f'a nmm:MusicPiece; nie:title "{title}"') as
resource:
+ with self.tracker.await_insert(fixtures.AUDIO_GRAPH,
+ f'a nmm:MusicPiece; nie:title "{title}"',
+ timeout=cfg.AWAIT_TIMEOUT) as resource:
self.tracker.update(sparql)
return resource
@@ -70,7 +73,7 @@ class MinerResourceRemovalTest(fixtures.TrackerMinerTest):
ie_1 = self.create_extra_audio_content(file_1.urn, self.uri(file_1_name), "Test resource 1")
ie_2 = self.create_extra_audio_content(file_2.urn, self.uri(file_2_name), "Test resource 2")
- with self.tracker.await_delete(fixtures.DOCUMENTS_GRAPH, file_1.id):
+ with self.tracker.await_delete(fixtures.DOCUMENTS_GRAPH, file_1.id, timeout=cfg.AWAIT_TIMEOUT):
os.unlink(self.path("test-monitored/test_1.txt"))
self.assertResourceMissing(self.uri(file_1_name))
diff --git a/tests/functional-tests/minerhelper.py b/tests/functional-tests/minerhelper.py
index 4aadd97da..0df14a3d6 100644
--- a/tests/functional-tests/minerhelper.py
+++ b/tests/functional-tests/minerhelper.py
@@ -37,6 +37,9 @@ class WakeupCycleTimeoutException(RuntimeError):
pass
+DEFAULT_TIMEOUT = 10
+
+
class MinerFsHelper ():
MINERFS_BUSNAME = "org.freedesktop.Tracker3.Miner.Files"
@@ -98,7 +101,7 @@ class MinerFsHelper ():
"""Return the number of wakeup-to-idle cycles the miner-fs completed."""
return self._wakeup_count
- def await_wakeup_count(self, target_wakeup_count, timeout=configuration.DEFAULT_TIMEOUT):
+ def await_wakeup_count(self, target_wakeup_count, timeout=DEFAULT_TIMEOUT):
"""Block until the miner has completed N wakeup-and-idle cycles.
This function is for use by miner-fs tests that should trigger an
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]