[tracker-miners/wip/carlosg/test-error-fixes: 1/5] tests: Add timer after consecutive file operations
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker-miners/wip/carlosg/test-error-fixes: 1/5] tests: Add timer after consecutive file operations
- Date: Tue, 13 Jul 2021 12:06:02 +0000 (UTC)
commit 6790ee48e86f6e42956b03b833f03cb156516b70
Author: Carlos Garnacho <carlosg gnome org>
Date: Wed Jul 7 23:30:22 2021 +0200
tests: Add timer after consecutive file operations
In tracker-miner-fs-test we are testing the simultaneous handling
of several consecutive file operations. We however don't get any
guarantees that these all will be handled atomically by the time
we iterate the main context to process the events.
This may result in split operations, that stop the miner in between,
thus ends our testcases without the expected results.
In these situations, wait for all events with a timeout, instead
of looking for TrackerMiner being finished. We ensure slightly
better that inotify/glib and our own TrackerMonitor thread did
all catch up to all the changes within the fixture_run_timed()
calls.
Fixes: https://gitlab.gnome.org/GNOME/tracker-miners/-/issues/177
tests/libtracker-miner/tracker-miner-fs-test.c | 42 +++++++++++++++++++-------
1 file changed, 31 insertions(+), 11 deletions(-)
---
diff --git a/tests/libtracker-miner/tracker-miner-fs-test.c b/tests/libtracker-miner/tracker-miner-fs-test.c
index eae9c23ff..db164172c 100644
--- a/tests/libtracker-miner/tracker-miner-fs-test.c
+++ b/tests/libtracker-miner/tracker-miner-fs-test.c
@@ -400,6 +400,26 @@ fixture_iterate (TrackerMinerFSTestFixture *fixture)
g_main_context_iteration (NULL, TRUE);
}
+static gboolean
+loop_timeout (GMainLoop *main_loop)
+{
+ g_main_loop_quit (main_loop);
+ return G_SOURCE_REMOVE;
+}
+
+static void
+fixture_iterate_timed (TrackerMinerFSTestFixture *fixture,
+ int seconds)
+{
+ GMainLoop *main_loop;
+
+ main_loop = g_main_loop_new (NULL, FALSE);
+ g_timeout_add_seconds (seconds, (GSourceFunc) loop_timeout, main_loop);
+ g_main_loop_run (main_loop);
+
+ g_main_loop_unref (main_loop);
+}
+
static void
test_recursive_indexing (TrackerMinerFSTestFixture *fixture,
gconstpointer data)
@@ -1486,7 +1506,7 @@ test_event_queue_create_and_update (TrackerMinerFSTestFixture *fixture,
g_free (content);
g_assert_cmpint (((TestMiner *) fixture->miner)->n_process_file, ==, 1);
- fixture_iterate (fixture);
+ fixture_iterate_timed (fixture, 1);
content = fixture_get_content (fixture);
g_assert_cmpstr (content, ==,
@@ -1551,7 +1571,7 @@ test_event_queue_create_and_move (TrackerMinerFSTestFixture *fixture,
g_assert_cmpstr (content, ==, "recursive");
g_free (content);
- fixture_iterate (fixture);
+ fixture_iterate_timed (fixture, 1);
content = fixture_get_content (fixture);
g_assert_cmpstr (content, ==,
@@ -1596,7 +1616,7 @@ test_event_queue_update_and_update (TrackerMinerFSTestFixture *fixture,
"recursive/a");
g_free (content);
- fixture_iterate (fixture);
+ fixture_iterate_timed (fixture, 1);
/* Coalescing desirable, but not mandatory */
g_assert_cmpint (((TestMiner *) fixture->miner)->n_process_file, >=, 1);
@@ -1640,7 +1660,7 @@ test_event_queue_update_and_delete (TrackerMinerFSTestFixture *fixture,
"recursive/a");
g_free (content);
- fixture_iterate (fixture);
+ fixture_iterate_timed (fixture, 1);
content = fixture_get_content (fixture);
g_assert_cmpstr (content, ==, "recursive");
@@ -1681,7 +1701,7 @@ test_event_queue_update_and_move (TrackerMinerFSTestFixture *fixture,
"recursive/a");
g_free (content);
- fixture_iterate (fixture);
+ fixture_iterate_timed (fixture, 1);
content = fixture_get_content (fixture);
g_assert_cmpstr (content, ==,
@@ -1723,7 +1743,7 @@ test_event_queue_delete_and_create (TrackerMinerFSTestFixture *fixture,
"recursive/a");
g_free (content);
- fixture_iterate (fixture);
+ fixture_iterate_timed (fixture, 1);
content = fixture_get_content (fixture);
g_assert_cmpstr (content, ==,
@@ -1767,7 +1787,7 @@ test_event_queue_move_and_update (TrackerMinerFSTestFixture *fixture,
"recursive/a");
g_free (content);
- fixture_iterate (fixture);
+ fixture_iterate_timed (fixture, 1);
g_assert_cmpint (((TestMiner *) fixture->miner)->n_process_file, ==, 2);
content = fixture_get_content (fixture);
@@ -1810,7 +1830,7 @@ test_event_queue_move_and_create_origin (TrackerMinerFSTestFixture *fixture,
"recursive/a");
g_free (content);
- fixture_iterate (fixture);
+ fixture_iterate_timed (fixture, 1);
content = fixture_get_content (fixture);
g_assert_cmpstr (content, ==,
@@ -1853,7 +1873,7 @@ test_event_queue_move_and_delete (TrackerMinerFSTestFixture *fixture,
"recursive/a");
g_free (content);
- fixture_iterate (fixture);
+ fixture_iterate_timed (fixture, 1);
content = fixture_get_content (fixture);
g_assert_cmpstr (content, ==,
@@ -1894,7 +1914,7 @@ test_event_queue_move_and_move (TrackerMinerFSTestFixture *fixture,
"recursive/a");
g_free (content);
- fixture_iterate (fixture);
+ fixture_iterate_timed (fixture, 1);
content = fixture_get_content (fixture);
g_assert_cmpstr (content, ==,
@@ -1936,7 +1956,7 @@ test_event_queue_move_and_move_back (TrackerMinerFSTestFixture *fixture,
"recursive/a");
g_free (content);
- fixture_iterate (fixture);
+ fixture_iterate_timed (fixture, 1);
content = fixture_get_content (fixture);
g_assert_cmpstr (content, ==,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]