[folks] Simplify tests that can time out



commit 6b42717eb7982478b1f94875ad585305eaa07cc0
Author: Simon McVittie <simon mcvittie collabora co uk>
Date:   Wed Mar 20 16:03:14 2013 +0000

    Simplify tests that can time out
    
    There are basically two patterns:
    
    * something should stop the main loop within n seconds; if not, that's
      failure (this is now loop_run_with_timeout)
    * run the main loop for n seconds, then check whether things we wanted
      to happen happened (this is now loop_run_with_non_fatal_timeout)
    
    The latter is basically a bug in itself; I'm not going to fix that
    right now, but I did mark it as deprecated.
    
    In both cases, we want to adjust the timeout for running under Valgrind
    or Callgrind, which makes everything slow.

 tests/eds/add-persona.vala                         |    8 +--
 tests/eds/anti-linking.vala                        |   18 +----
 tests/eds/avatar-details.vala                      |    8 +--
 tests/eds/create-remove-stores.vala                |   11 +--
 tests/eds/email-details.vala                       |    8 +--
 tests/eds/enable-disable-stores.vala               |   11 +--
 tests/eds/im-details.vala                          |    8 +--
 tests/eds/individual-retrieval.vala                |    8 +--
 tests/eds/link-personas-diff-stores.vala           |    9 +--
 tests/eds/link-personas.vala                       |   15 +---
 tests/eds/linkable-properties.vala                 |   10 +--
 tests/eds/name-details.vala                        |    8 +--
 tests/eds/persona-store-tests.vala                 |    8 +--
 tests/eds/phone-details.vala                       |    8 +--
 tests/eds/postal-address-details.vala              |    8 +--
 tests/eds/remove-persona.vala                      |    8 +--
 tests/eds/removing-contacts.vala                   |    7 +--
 tests/eds/set-avatar.vala                          |   17 +---
 tests/eds/set-birthday.vala                        |    7 +--
 tests/eds/set-emails.vala                          |    7 +--
 tests/eds/set-gender.vala                          |    8 +--
 tests/eds/set-im-addresses.vala                    |    7 +--
 tests/eds/set-is-favourite.vala                    |    8 +--
 tests/eds/set-names.vala                           |    7 +--
 tests/eds/set-notes.vala                           |    7 +--
 tests/eds/set-phones.vala                          |    7 +--
 tests/eds/set-postal-addresses.vala                |    7 +--
 tests/eds/set-properties-race.vala                 |    7 +--
 tests/eds/set-roles.vala                           |    7 +--
 tests/eds/set-structured-name.vala                 |    7 +--
 tests/eds/set-urls.vala                            |    7 +--
 tests/eds/store-removed.vala                       |   20 +----
 tests/eds/updating-contacts.vala                   |    7 +--
 tests/folks/aggregation.vala                       |   96 +++-----------------
 tests/folks/init.vala                              |   11 +--
 tests/key-file/individual-retrieval.vala           |   21 +----
 tests/lib/libsocialweb/test-case.vala              |    7 +--
 tests/lib/test-utils.vala                          |   77 ++++++++++++++++
 tests/libsocialweb/aggregation.vala                |   14 +---
 tests/libsocialweb/dummy-lsw.vala                  |   28 +-----
 tests/telepathy/individual-properties.vala         |   36 +-------
 tests/telepathy/individual-retrieval.vala          |   18 +----
 tests/telepathy/init.vala                          |   10 +--
 tests/telepathy/persona-store-capabilities.vala    |   12 +---
 tests/tracker/add-contact.vala                     |    8 +--
 tests/tracker/add-persona.vala                     |    8 +--
 tests/tracker/additional-names-updates.vala        |    8 +--
 tests/tracker/avatar-details-interface.vala        |    8 +--
 tests/tracker/avatar-updates.vala                  |    8 +--
 tests/tracker/birthday-details-interface.vala      |    8 +--
 tests/tracker/birthday-updates.vala                |    8 +--
 tests/tracker/default-contact.vala                 |    8 +--
 tests/tracker/duplicated-emails.vala               |    8 +--
 tests/tracker/duplicated-phones.vala               |    8 +--
 tests/tracker/email-details-interface.vala         |    8 +--
 tests/tracker/emails-updates.vala                  |    8 +--
 tests/tracker/family-name-updates.vala             |    8 +--
 tests/tracker/favourite-details-interface.vala     |    8 +--
 tests/tracker/favourite-updates.vala               |    8 +--
 tests/tracker/fullname-updates.vala                |    8 +--
 tests/tracker/gender-details-interface.vala        |    8 +--
 tests/tracker/given-name-updates.vala              |    8 +--
 tests/tracker/im-details-interface.vala            |    8 +--
 tests/tracker/imaddresses-updates.vala             |    8 +--
 tests/tracker/individual-retrieval.vala            |    8 +--
 tests/tracker/link-personas-via-local-ids.vala     |    8 +--
 tests/tracker/link-personas.vala                   |    8 +--
 tests/tracker/match-all.vala                       |    8 +--
 tests/tracker/match-email-addresses.vala           |    8 +--
 tests/tracker/match-im-addresses.vala              |    8 +--
 tests/tracker/match-known-emails.vala              |    8 +--
 tests/tracker/match-name.vala                      |    8 +--
 tests/tracker/match-phone-number.vala              |    8 +--
 tests/tracker/name-details-interface.vala          |    8 +--
 tests/tracker/nickname-updates.vala                |    8 +--
 tests/tracker/note-details-interface.vala          |    8 +--
 tests/tracker/phone-details-interface.vala         |    8 +--
 tests/tracker/phones-updates.vala                  |    8 +--
 .../tracker/postal-address-details-interface.vala  |    8 +--
 tests/tracker/prefix-name-updates.vala             |    8 +--
 tests/tracker/remove-contact.vala                  |    8 +--
 tests/tracker/remove-persona.vala                  |    8 +--
 tests/tracker/role-details-interface.vala          |    8 +--
 tests/tracker/set-avatar.vala                      |    8 +--
 tests/tracker/set-birthday.vala                    |    8 +--
 tests/tracker/set-duplicate-email.vala             |    8 +--
 tests/tracker/set-emails.vala                      |    8 +--
 tests/tracker/set-favourite.vala                   |    8 +--
 tests/tracker/set-full-name.vala                   |    8 +--
 tests/tracker/set-gender.vala                      |    8 +--
 tests/tracker/set-im-addresses.vala                |    8 +--
 tests/tracker/set-nickname.vala                    |    8 +--
 tests/tracker/set-notes.vala                       |    8 +--
 tests/tracker/set-null-avatar.vala                 |    8 +--
 tests/tracker/set-phones.vala                      |    8 +--
 tests/tracker/set-postal-addresses.vala            |    8 +--
 tests/tracker/set-roles.vala                       |    8 +--
 tests/tracker/set-structured-name.vala             |    8 +--
 tests/tracker/set-urls.vala                        |    8 +--
 tests/tracker/suffix-name-updates.vala             |    8 +--
 tests/tracker/url-details-interface.vala           |    8 +--
 tests/tracker/website-updates.vala                 |    8 +--
 102 files changed, 205 insertions(+), 887 deletions(-)
---
diff --git a/tests/eds/add-persona.vala b/tests/eds/add-persona.vala
index 60ca1b8..178fcb3 100644
--- a/tests/eds/add-persona.vala
+++ b/tests/eds/add-persona.vala
@@ -101,13 +101,7 @@ public class AddPersonaTests : EdsTest.TestCase
 
       this._test_add_persona_async.begin ();
 
-      Timeout.add_seconds (5, () =>
-        {
-          this._main_loop.quit ();
-          assert_not_reached ();
-        });
-
-      this._main_loop.run ();
+      TestUtils.loop_run_with_timeout (this._main_loop);
 
       foreach (var k in this._properties_found.get_values ())
         {
diff --git a/tests/eds/anti-linking.vala b/tests/eds/anti-linking.vala
index ed129a7..dd51914 100644
--- a/tests/eds/anti-linking.vala
+++ b/tests/eds/anti-linking.vala
@@ -107,14 +107,7 @@ public class AntiLinkingTests : EdsTest.TestCase
 
       this._test_anti_linking_basic_async.begin ();
 
-      Timeout.add_seconds (5, () =>
-        {
-          this._main_loop.quit ();
-          stderr.printf ("Personas failed to be anti-linked\n");
-          assert_not_reached ();
-        });
-
-      this._main_loop.run ();
+      TestUtils.loop_run_with_timeout (this._main_loop);
 
       assert (this._found_before_update);
       assert (this._found_after_update);
@@ -234,14 +227,7 @@ public class AntiLinkingTests : EdsTest.TestCase
 
       this._test_anti_linking_removal_async.begin ();
 
-      Timeout.add_seconds (5, () =>
-        {
-          this._main_loop.quit ();
-          stderr.printf ("Personas failed to be anti-linked\n");
-          assert_not_reached ();
-        });
-
-      this._main_loop.run ();
+      TestUtils.loop_run_with_timeout (this._main_loop);
 
       assert (this._found_before_update);
       assert (this._found_after_update);
diff --git a/tests/eds/avatar-details.vala b/tests/eds/avatar-details.vala
index 7c90476..21802f3 100644
--- a/tests/eds/avatar-details.vala
+++ b/tests/eds/avatar-details.vala
@@ -58,13 +58,7 @@ public class AvatarDetailsTests : EdsTest.TestCase
 
       this._test_avatar_async.begin ();
 
-      Timeout.add_seconds (5, () =>
-        {
-          this._main_loop.quit ();
-          return false;
-        });
-
-      this._main_loop.run ();
+      TestUtils.loop_run_with_non_fatal_timeout (this._main_loop);
 
       assert (this._avatars_are_equal);
    }
diff --git a/tests/eds/create-remove-stores.vala b/tests/eds/create-remove-stores.vala
index 271570f..d189005 100644
--- a/tests/eds/create-remove-stores.vala
+++ b/tests/eds/create-remove-stores.vala
@@ -64,21 +64,14 @@ public class CreateRemoveStoresTests : EdsTest.TestCase
 
       this._test_creating_removing_stores_async.begin ();
 
-      var timer_id = Timeout.add_seconds (20, () =>
-        {
-          this._main_loop.quit ();
-          assert_not_reached ();
-        });
-
-      this._main_loop.run ();
+      TestUtils.loop_run_with_timeout (this._main_loop, 20);
 
       assert (this._store_removed.size > 0);
       foreach (bool removed in this._store_removed.values)
         {
           assert (removed == true);
         }
-        
-      GLib.Source.remove (timer_id);
+
       this._aggregator = null;
       this._main_loop = null;
     }
diff --git a/tests/eds/email-details.vala b/tests/eds/email-details.vala
index 30646e3..f077c9c 100644
--- a/tests/eds/email-details.vala
+++ b/tests/eds/email-details.vala
@@ -86,13 +86,7 @@ public class EmailDetailsTests : EdsTest.TestCase
 
       this._test_email_details_async.begin ();
 
-      Timeout.add_seconds (5, () =>
-          {
-            this._main_loop.quit ();
-            return false;
-          });
-
-      this._main_loop.run ();
+      TestUtils.loop_run_with_non_fatal_timeout (this._main_loop, 5);
 
       assert (this._email_count == 6);
       assert (this._email_types.size == 1);
diff --git a/tests/eds/enable-disable-stores.vala b/tests/eds/enable-disable-stores.vala
index 5b08c09..5ba1fce 100644
--- a/tests/eds/enable-disable-stores.vala
+++ b/tests/eds/enable-disable-stores.vala
@@ -70,21 +70,14 @@ public class EnableDisableStoresTests : EdsTest.TestCase
 
       this._test_disabling_stores_async.begin ();
 
-      var timer_id = Timeout.add_seconds (8, () =>
-        {
-          this._main_loop.quit ();
-          assert_not_reached ();
-        });
-
-      this._main_loop.run ();
+      TestUtils.loop_run_with_timeout (this._main_loop);
 
       assert (this._store_removed.size > 0);
       foreach (bool removed in this._store_removed.values)
         {
           assert (removed == true);
         }
-        
-      GLib.Source.remove (timer_id);
+
       this._aggregator = null;
       this._main_loop = null;
     }
diff --git a/tests/eds/im-details.vala b/tests/eds/im-details.vala
index f9e5dac..e0a8986 100644
--- a/tests/eds/im-details.vala
+++ b/tests/eds/im-details.vala
@@ -65,13 +65,7 @@ public class ImDetailsTests : EdsTest.TestCase
 
       this._test_im_details_interface_async.begin ();
 
-      Timeout.add_seconds (5, () =>
-        {
-          this._main_loop.quit ();
-          assert_not_reached ();
-        });
-
-      this._main_loop.run ();
+      TestUtils.loop_run_with_timeout (this._main_loop);
 
       assert (this._num_addrs == 2);
       assert (this._found_addr_1 == true);
diff --git a/tests/eds/individual-retrieval.vala b/tests/eds/individual-retrieval.vala
index b69cce0..a02c674 100644
--- a/tests/eds/individual-retrieval.vala
+++ b/tests/eds/individual-retrieval.vala
@@ -63,13 +63,7 @@ public class IndividualRetrievalTests : EdsTest.TestCase
 
       this._test_singleton_individuals_async.begin ();
 
-      Timeout.add_seconds (5, () =>
-        {
-          this._main_loop.quit ();
-          return false;
-        });
-
-      this._main_loop.run ();
+      TestUtils.loop_run_with_non_fatal_timeout (this._main_loop, 5);
 
       assert (this._found_individuals.size == 2);
     }
diff --git a/tests/eds/link-personas-diff-stores.vala b/tests/eds/link-personas-diff-stores.vala
index fced5c9..8701bcf 100644
--- a/tests/eds/link-personas-diff-stores.vala
+++ b/tests/eds/link-personas-diff-stores.vala
@@ -74,17 +74,10 @@ public class LinkPersonasDiffStoresTests : EdsTest.TestCase
 
       this._test_linking_personas_async.begin ();
 
-      var timer_id = Timeout.add_seconds (8, () =>
-        {
-          this._main_loop.quit ();
-          assert_not_reached ();
-        });
-
-      this._main_loop.run ();
+      TestUtils.loop_run_with_timeout (this._main_loop, 8);
 
       assert (this._linked_individual_found == true);
 
-      GLib.Source.remove (timer_id);
       this._aggregator = null;
       this._main_loop = null;
     }
diff --git a/tests/eds/link-personas.vala b/tests/eds/link-personas.vala
index ec88be9..74f72dd 100644
--- a/tests/eds/link-personas.vala
+++ b/tests/eds/link-personas.vala
@@ -124,20 +124,8 @@ public class LinkPersonasTests : EdsTest.TestCase
 
       this._test_linking_personas_async.begin ();
 
-      var timer_id = Timeout.add_seconds (8, () =>
-        {
-          // Let the main loop run out of events before we quit (yes, this is a HACK)
-          Timeout.add_seconds (5, () =>
-            {
-              this._main_loop.quit ();
-              return false;
-            });
-          assert_not_reached ();
-        });
-
-      this._main_loop.run ();
+      TestUtils.loop_run_with_timeout (this._main_loop, 8);
 
-      GLib.Source.remove (timer_id);
       this._aggregator = null;
       this._main_loop = null;
     }
@@ -424,6 +412,7 @@ public class LinkPersonasTests : EdsTest.TestCase
 
           if (this._linking_props.size == 0)
             {
+              /* FIXME: if the timeout is reached, should this just fail? */
               Timeout.add_seconds (5, () =>
                 {
                   this._main_loop.quit ();
diff --git a/tests/eds/linkable-properties.vala b/tests/eds/linkable-properties.vala
index 3903e10..44512b7 100644
--- a/tests/eds/linkable-properties.vala
+++ b/tests/eds/linkable-properties.vala
@@ -102,15 +102,7 @@ public class LinkablePropertiesTests : EdsTest.TestCase
 
       this._test_linkable_properties_aggregate_after_change_async.begin ();
 
-      Timeout.add_seconds (5, () =>
-        {
-          this._main_loop.quit ();
-          stderr.printf ("Personas failed to be aggregated after being given " +
-            "the same linkable properties\n");
-          assert_not_reached ();
-        });
-
-      this._main_loop.run ();
+      TestUtils.loop_run_with_timeout (this._main_loop);
 
       assert (this._found_before_update);
       assert (this._found_after_update);
diff --git a/tests/eds/name-details.vala b/tests/eds/name-details.vala
index fb46c48..bb292be 100644
--- a/tests/eds/name-details.vala
+++ b/tests/eds/name-details.vala
@@ -84,13 +84,7 @@ public class NameDetailsTests : EdsTest.TestCase
 
       this._test_names_async.begin ();
 
-      Timeout.add_seconds (5, () =>
-          {
-            this._main_loop.quit ();
-            return false;
-          });
-
-      this._main_loop.run ();
+      TestUtils.loop_run_with_non_fatal_timeout (this._main_loop, 5);
 
       assert (this._names_count == 2);
       assert (this._c1.size == 0);
diff --git a/tests/eds/persona-store-tests.vala b/tests/eds/persona-store-tests.vala
index b9ec43c..2714ea5 100644
--- a/tests/eds/persona-store-tests.vala
+++ b/tests/eds/persona-store-tests.vala
@@ -93,13 +93,7 @@ public class PersonaStoreTests : EdsTest.TestCase
 
       backend_store.load_backends.begin ();
 
-      Timeout.add_seconds (3, () =>
-        {
-          main_loop.quit ();
-          return false;
-        });
-
-      main_loop.run ();
+      TestUtils.loop_run_with_non_fatal_timeout (main_loop);
 
       assert (this._capabilities_received.contains ("can-add-personas"));
       assert (this._capabilities_received.contains ("can-remove-personas"));
diff --git a/tests/eds/phone-details.vala b/tests/eds/phone-details.vala
index 316c8f6..b62e444 100644
--- a/tests/eds/phone-details.vala
+++ b/tests/eds/phone-details.vala
@@ -79,13 +79,7 @@ public class PhoneDetailsTests : EdsTest.TestCase
 
       this._test_phone_numbers_async.begin ();
 
-      Timeout.add_seconds (5, () =>
-        {
-          this._main_loop.quit ();
-          return false;
-        });
-
-      this._main_loop.run ();
+      TestUtils.loop_run_with_non_fatal_timeout (this._main_loop, 5);
 
       assert (this._phones_count == 6);
       assert (this._phone_types.size == 3);
diff --git a/tests/eds/postal-address-details.vala b/tests/eds/postal-address-details.vala
index 8c068d2..22abe62 100644
--- a/tests/eds/postal-address-details.vala
+++ b/tests/eds/postal-address-details.vala
@@ -90,13 +90,7 @@ public class PostalAddressDetailsTests : EdsTest.TestCase
 
       this._test_postal_address_details_interface_async.begin ();
 
-      Timeout.add_seconds (5, () =>
-        {
-          this._main_loop.quit ();
-          assert_not_reached ();
-        });
-
-      this._main_loop.run ();
+      TestUtils.loop_run_with_timeout (this._main_loop);
 
       assert (this._found_postal_address == true);
     }
diff --git a/tests/eds/remove-persona.vala b/tests/eds/remove-persona.vala
index 61881f4..297953c 100644
--- a/tests/eds/remove-persona.vala
+++ b/tests/eds/remove-persona.vala
@@ -52,13 +52,7 @@ public class RemovePersonaTests : EdsTest.TestCase
 
       this._test_remove_persona_async.begin ();
 
-      Timeout.add_seconds (5, () =>
-        {
-          this._main_loop.quit ();
-          assert_not_reached ();
-        });
-
-      this._main_loop.run ();
+      TestUtils.loop_run_with_timeout (this._main_loop);
 
       assert (this._persona_removed == true);
       assert (this._individual_removed == true);
diff --git a/tests/eds/removing-contacts.vala b/tests/eds/removing-contacts.vala
index fc895ec..cb640ac 100644
--- a/tests/eds/removing-contacts.vala
+++ b/tests/eds/removing-contacts.vala
@@ -54,12 +54,7 @@ public class RemovingContactsTests : EdsTest.TestCase
 
       this._test_removal_async.begin ();
 
-      Timeout.add_seconds (5, () => {
-            this._main_loop.quit ();
-            return false;
-          });
-
-      this._main_loop.run ();
+      TestUtils.loop_run_with_non_fatal_timeout (this._main_loop, 5);
 
       assert (this._added == true);
       assert (this._removed == true);
diff --git a/tests/eds/set-avatar.vala b/tests/eds/set-avatar.vala
index d70cbeb..318954f 100644
--- a/tests/eds/set-avatar.vala
+++ b/tests/eds/set-avatar.vala
@@ -60,17 +60,11 @@ public class SetAvatarTests : EdsTest.TestCase
 
       this._test_set_avatar_async.begin ();
 
-      var timeout_id = Timeout.add_seconds (5, () => {
-            this._main_loop.quit ();
-            assert_not_reached ();
-          });
-
-      this._main_loop.run ();
+      TestUtils.loop_run_with_timeout (this._main_loop);
 
       assert (this._found_before_update);
       assert (this._found_after_update);
 
-      Source.remove (timeout_id);
       this._aggregator = null;
       this._main_loop = null;
     }
@@ -170,18 +164,11 @@ public class SetAvatarTests : EdsTest.TestCase
 
       this._test_set_individual_avatar_async.begin ();
 
-      var timeout_id = Timeout.add_seconds (5, () =>
-        {
-          this._main_loop.quit ();
-          assert_not_reached ();
-        });
-
-      this._main_loop.run ();
+      TestUtils.loop_run_with_timeout (this._main_loop);
 
       assert (this._found_before_update);
       assert (this._found_after_update);
 
-      Source.remove (timeout_id);
       this._aggregator = null;
       this._main_loop = null;
     }
diff --git a/tests/eds/set-birthday.vala b/tests/eds/set-birthday.vala
index 0c4df83..d5fb7c3 100644
--- a/tests/eds/set-birthday.vala
+++ b/tests/eds/set-birthday.vala
@@ -55,12 +55,7 @@ public class SetBirthdayTests : EdsTest.TestCase
 
       this._test_set_birthday_async.begin ();
 
-      Timeout.add_seconds (5, () => {
-            this._main_loop.quit ();
-            assert_not_reached ();
-          });
-
-      this._main_loop.run ();
+      TestUtils.loop_run_with_timeout (this._main_loop);
 
       assert (this._found_before_update);
       assert (this._found_after_update);
diff --git a/tests/eds/set-emails.vala b/tests/eds/set-emails.vala
index 52ca688..2d575d9 100644
--- a/tests/eds/set-emails.vala
+++ b/tests/eds/set-emails.vala
@@ -54,12 +54,7 @@ public class SetEmailsTests : EdsTest.TestCase
 
       this._test_set_emails_async.begin ();
 
-      Timeout.add_seconds (5, () => {
-            this._main_loop.quit ();
-            assert_not_reached ();
-          });
-
-      this._main_loop.run ();
+      TestUtils.loop_run_with_timeout (this._main_loop);
 
       assert (this._found_before_update);
       assert (this._found_after_update);
diff --git a/tests/eds/set-gender.vala b/tests/eds/set-gender.vala
index 8d5a6b7..6cab286 100644
--- a/tests/eds/set-gender.vala
+++ b/tests/eds/set-gender.vala
@@ -55,13 +55,7 @@ public class SetGenderTests : EdsTest.TestCase
 
       this._test_set_gender_async.begin ();
 
-      Timeout.add_seconds (5, () =>
-        {
-          this._main_loop.quit ();
-          assert_not_reached ();
-        });
-
-      this._main_loop.run ();
+      TestUtils.loop_run_with_timeout (this._main_loop);
 
       assert (this._gender_before_update);
       assert (this._gender_after_update);
diff --git a/tests/eds/set-im-addresses.vala b/tests/eds/set-im-addresses.vala
index 7e7a3dc..8dd1c61 100644
--- a/tests/eds/set-im-addresses.vala
+++ b/tests/eds/set-im-addresses.vala
@@ -55,12 +55,7 @@ public class SetIMAddressesTests : EdsTest.TestCase
 
       this._test_set_im_addresses_async.begin ();
 
-      Timeout.add_seconds (5, () => {
-            this._main_loop.quit ();
-            assert_not_reached ();
-          });
-
-      this._main_loop.run ();
+      TestUtils.loop_run_with_timeout (this._main_loop);
 
       assert (this._found_before_update);
       assert (this._found_after_update);
diff --git a/tests/eds/set-is-favourite.vala b/tests/eds/set-is-favourite.vala
index df29a85..5ff7b23 100644
--- a/tests/eds/set-is-favourite.vala
+++ b/tests/eds/set-is-favourite.vala
@@ -55,13 +55,7 @@ public class SetIsFavouriteTests : EdsTest.TestCase
 
       this._test_set_is_favourite_async.begin ();
 
-      Timeout.add_seconds (5, () =>
-        {
-          this._main_loop.quit ();
-          assert_not_reached ();
-        });
-
-      this._main_loop.run ();
+      TestUtils.loop_run_with_timeout (this._main_loop);
 
       assert (!this._is_favourite_before_update);
       assert (this._is_favourite_after_update);
diff --git a/tests/eds/set-names.vala b/tests/eds/set-names.vala
index a24ec9b..f1fee50 100644
--- a/tests/eds/set-names.vala
+++ b/tests/eds/set-names.vala
@@ -62,12 +62,7 @@ public class SetNamesTests : EdsTest.TestCase
 
       this._test_set_names_async.begin ();
 
-      Timeout.add_seconds (5, () => {
-            this._main_loop.quit ();
-            assert_not_reached ();
-          });
-
-      this._main_loop.run ();
+      TestUtils.loop_run_with_timeout (this._main_loop);
 
       assert (this._full_name_found_before_update);
       assert (this._full_name_found_after_update);
diff --git a/tests/eds/set-notes.vala b/tests/eds/set-notes.vala
index d56545a..1264cd2 100644
--- a/tests/eds/set-notes.vala
+++ b/tests/eds/set-notes.vala
@@ -56,12 +56,7 @@ public class SetNotesTests : EdsTest.TestCase
 
       this._test_set_full_name_async.begin ();
 
-      Timeout.add_seconds (5, () => {
-            this._main_loop.quit ();
-            assert_not_reached ();
-          });
-
-      this._main_loop.run ();
+      TestUtils.loop_run_with_timeout (this._main_loop);
 
       assert (this._found_before_update);
       assert (this._found_after_update);
diff --git a/tests/eds/set-phones.vala b/tests/eds/set-phones.vala
index e00e328..cb54411 100644
--- a/tests/eds/set-phones.vala
+++ b/tests/eds/set-phones.vala
@@ -54,12 +54,7 @@ public class SetPhonesTests : EdsTest.TestCase
 
       this._test_set_phones_async.begin ();
 
-      Timeout.add_seconds (5, () => {
-            this._main_loop.quit ();
-            assert_not_reached ();
-          });
-
-      this._main_loop.run ();
+      TestUtils.loop_run_with_timeout (this._main_loop);
 
       assert (this._found_before_update);
       assert (this._found_after_update);
diff --git a/tests/eds/set-postal-addresses.vala b/tests/eds/set-postal-addresses.vala
index 9d3ef30..54a923d 100644
--- a/tests/eds/set-postal-addresses.vala
+++ b/tests/eds/set-postal-addresses.vala
@@ -62,12 +62,7 @@ public class SetPostalAddressesTests : EdsTest.TestCase
 
       this._test_set_postal_addresses_async.begin ();
 
-      Timeout.add_seconds (5, () => {
-            this._main_loop.quit ();
-            assert_not_reached ();
-          });
-
-      this._main_loop.run ();
+      TestUtils.loop_run_with_timeout (this._main_loop);
 
       assert (this._found_before_update);
       assert (this._found_after_update);
diff --git a/tests/eds/set-properties-race.vala b/tests/eds/set-properties-race.vala
index ee207c2..bfdf8d8 100644
--- a/tests/eds/set-properties-race.vala
+++ b/tests/eds/set-properties-race.vala
@@ -62,12 +62,7 @@ public class SetPropertiesRaceTests : EdsTest.TestCase
 
       this._test_set_postal_addresses_async.begin ();
 
-      Timeout.add_seconds (5, () => {
-            this._main_loop.quit ();
-            assert_not_reached ();
-          });
-
-      this._main_loop.run ();
+      TestUtils.loop_run_with_timeout (this._main_loop);
 
       assert (this._found_before_update);
       assert (this._found_after_update);
diff --git a/tests/eds/set-roles.vala b/tests/eds/set-roles.vala
index b0b0edb..188ee17 100644
--- a/tests/eds/set-roles.vala
+++ b/tests/eds/set-roles.vala
@@ -56,12 +56,7 @@ public class SetRolesTests : EdsTest.TestCase
 
       this._test_set_roles_async.begin ();
 
-      Timeout.add_seconds (5, () => {
-            this._main_loop.quit ();
-            assert_not_reached ();
-          });
-
-      this._main_loop.run ();
+      TestUtils.loop_run_with_timeout (this._main_loop, 5);
 
       assert (this._found_before_update);
       assert (this._found_after_update);
diff --git a/tests/eds/set-structured-name.vala b/tests/eds/set-structured-name.vala
index 8cf33f0..7adc388 100644
--- a/tests/eds/set-structured-name.vala
+++ b/tests/eds/set-structured-name.vala
@@ -57,12 +57,7 @@ public class SetStructuredNameTests : EdsTest.TestCase
 
       this._test_set_structured_name_async.begin ();
 
-      Timeout.add_seconds (5, () => {
-            this._main_loop.quit ();
-            assert_not_reached ();
-          });
-
-      this._main_loop.run ();
+      TestUtils.loop_run_with_timeout (this._main_loop, 5);
 
       assert (this._found_before_update);
       assert (this._found_after_update);
diff --git a/tests/eds/set-urls.vala b/tests/eds/set-urls.vala
index 29ed296..5fa06f3 100644
--- a/tests/eds/set-urls.vala
+++ b/tests/eds/set-urls.vala
@@ -66,12 +66,7 @@ public class SetUrlsTests : EdsTest.TestCase
 
       this._test_set_urls_async.begin ();
 
-      Timeout.add_seconds (5, () => {
-            this._main_loop.quit ();
-            assert_not_reached ();
-          });
-
-      this._main_loop.run ();
+      TestUtils.loop_run_with_timeout (this._main_loop, 5);
 
       assert (this._found_before_update);
       assert (this._found_url_extra_1);
diff --git a/tests/eds/store-removed.vala b/tests/eds/store-removed.vala
index 784bf3f..4d6e282 100644
--- a/tests/eds/store-removed.vala
+++ b/tests/eds/store-removed.vala
@@ -57,34 +57,18 @@ public class StoreRemovedTests : EdsTest.TestCase
       /* Schedule the test to start with the main loop. */
       this._test_single_store_part1_async.begin ();
 
-      var timeout_id = Timeout.add_seconds (5, () =>
-        {
-          critical ("Timeout reached.");
-          return false;
-        });
-
-      this._main_loop.run ();
+      TestUtils.loop_run_with_timeout (this._main_loop, 5);
 
       /* We should have a single individual by now. */
       assert (this._aggregator.individuals.size == 1);
 
-      GLib.Source.remove (timeout_id);
-
       /* Part 2, where we remove the address book. */
       this._test_single_store_part2_async.begin ();
 
-      timeout_id = Timeout.add_seconds (5, () =>
-        {
-          critical ("Timeout reached.");
-          return false;
-        });
-
-      this._main_loop.run ();
+      TestUtils.loop_run_with_timeout (this._main_loop, 5);
 
       /* The individual should be gone. */
       assert (this._aggregator.individuals.size == 0);
-
-      GLib.Source.remove (timeout_id);
     }
 
   private async void _test_single_store_part1_async ()
diff --git a/tests/eds/updating-contacts.vala b/tests/eds/updating-contacts.vala
index 5d66d66..35648ab 100644
--- a/tests/eds/updating-contacts.vala
+++ b/tests/eds/updating-contacts.vala
@@ -54,12 +54,7 @@ public class UpdatingContactsTests : EdsTest.TestCase
 
       this._test_updates_async.begin ();
 
-      Timeout.add_seconds (5, () => {
-            this._main_loop.quit ();
-            assert_not_reached ();
-          });
-
-      this._main_loop.run ();
+      TestUtils.loop_run_with_timeout (this._main_loop, 5);
 
       assert (this._found_before_update);
       assert (this._found_after_update);
diff --git a/tests/folks/aggregation.vala b/tests/folks/aggregation.vala
index 8b19b56..024e296 100644
--- a/tests/folks/aggregation.vala
+++ b/tests/folks/aggregation.vala
@@ -24,7 +24,6 @@ using TpTests;
 public class AggregationTests : TpfTest.MixedTestCase
 {
   private HashSet<string> _default_personas;
-  private int _test_timeout = 3;
 
   public AggregationTests ()
     {
@@ -57,9 +56,6 @@ public class AggregationTests : TpfTest.MixedTestCase
           this.test_ensure_individual_property_writeable_add_persona);
       this.add_test ("ensure individual property writeable:failure",
           this.test_ensure_individual_property_writeable_failure);
-
-      if (Environment.get_variable ("FOLKS_TEST_VALGRIND") != null)
-          this._test_timeout = 10;
     }
 
   public override void set_up_tp ()
@@ -151,11 +147,6 @@ public class AggregationTests : TpfTest.MixedTestCase
       /* Kill the main loop after a few seconds. If there are still individuals
        * in the set of expected individuals, the aggregator has either failed or
        * been too slow (which we can consider to be failure). */
-      Timeout.add_seconds (this._test_timeout, () =>
-        {
-          main_loop.quit ();
-          return false;
-        });
 
       Idle.add (() =>
         {
@@ -176,7 +167,7 @@ public class AggregationTests : TpfTest.MixedTestCase
           return false;
         });
 
-      main_loop.run ();
+      TestUtils.loop_run_with_non_fatal_timeout (main_loop, 3);
 
       /* We should have enumerated exactly the individuals in the set */
       assert (expected_individuals.size == 0);
@@ -289,11 +280,6 @@ public class AggregationTests : TpfTest.MixedTestCase
       /* Kill the main loop after a few seconds. If there are still individuals
        * in the set of expected individuals, the aggregator has either failed or
        * been too slow (which we can consider to be failure). */
-      Timeout.add_seconds (this._test_timeout, () =>
-        {
-          main_loop.quit ();
-          return false;
-        });
 
       Idle.add (() =>
         {
@@ -314,7 +300,7 @@ public class AggregationTests : TpfTest.MixedTestCase
           return false;
         });
 
-      main_loop.run ();
+      TestUtils.loop_run_with_non_fatal_timeout (main_loop, 3);
 
       /* Verify the two individuals we should have */
       assert (individual1 != null);
@@ -470,11 +456,6 @@ public class AggregationTests : TpfTest.MixedTestCase
       /* Kill the main loop after a few seconds. If there are still individuals
        * in the set of expected individuals, the aggregator has either failed or
        * been too slow (which we can consider to be failure). */
-      Timeout.add_seconds (this._test_timeout, () =>
-        {
-          main_loop.quit ();
-          return false;
-        });
 
       Idle.add (() =>
         {
@@ -495,7 +476,7 @@ public class AggregationTests : TpfTest.MixedTestCase
           return false;
         });
 
-      main_loop.run ();
+      TestUtils.loop_run_with_non_fatal_timeout (main_loop, 3);
 
       /* Verify the two individuals we should have */
       assert (individual1 != null);
@@ -655,11 +636,6 @@ public class AggregationTests : TpfTest.MixedTestCase
       /* Kill the main loop after a few seconds. If there are still individuals
        * in the set of expected individuals, the aggregator has either failed or
        * been too slow (which we can consider to be failure). */
-      Timeout.add_seconds (this._test_timeout, () =>
-        {
-          main_loop.quit ();
-          return false;
-        });
 
       Idle.add (() =>
         {
@@ -680,7 +656,7 @@ public class AggregationTests : TpfTest.MixedTestCase
           return false;
         });
 
-      main_loop.run ();
+      TestUtils.loop_run_with_non_fatal_timeout (main_loop, 3);
 
       /* The user exported by the aggregator should be the same as the one
        * we've kept track of */
@@ -789,11 +765,6 @@ public class AggregationTests : TpfTest.MixedTestCase
       /* Kill the main loop after a few seconds. If there are still individuals
        * in the set of expected individuals, the aggregator has either failed or
        * been too slow (which we can consider to be failure). */
-      Timeout.add_seconds (this._test_timeout, () =>
-        {
-          main_loop.quit ();
-          return false;
-        });
 
       Idle.add (() =>
         {
@@ -814,7 +785,7 @@ public class AggregationTests : TpfTest.MixedTestCase
           return false;
         });
 
-      main_loop.run ();
+      TestUtils.loop_run_with_non_fatal_timeout (main_loop, 3);
 
       aggregator.disconnect (individuals_changed_id);
       aggregator.disconnect (individuals_changed_detailed_id);
@@ -942,11 +913,6 @@ public class AggregationTests : TpfTest.MixedTestCase
 
       /* Kill the main loop after a few seconds. We can assume that we've
        * reached a quiescent state by this point. */
-      Timeout.add_seconds (this._test_timeout, () =>
-        {
-          main_loop.quit ();
-          return false;
-        });
 
       Idle.add (() =>
         {
@@ -967,7 +933,7 @@ public class AggregationTests : TpfTest.MixedTestCase
           return false;
         });
 
-      main_loop.run ();
+      TestUtils.loop_run_with_non_fatal_timeout (main_loop, 3);
 
       /* Check that all Individuals are either ADDED or FINALISED. There should
        * be no Individuals which are REMOVED (but not yet finalised). */
@@ -987,13 +953,8 @@ public class AggregationTests : TpfTest.MixedTestCase
 
       /* Kill the main loop after a few seconds. We can assume that we've
        * reached another quiescent state by this point. */
-      Timeout.add_seconds (this._test_timeout, () =>
-        {
-          main_loop.quit ();
-          return false;
-        });
 
-      main_loop.run ();
+      TestUtils.loop_run_with_non_fatal_timeout (main_loop, 3);
 
       /* Now that the backends have been finalised, all the Individuals should
        * have been finalised too. */
@@ -1041,11 +1002,6 @@ public class AggregationTests : TpfTest.MixedTestCase
         });
 
       /* Kill the main loop after a few seconds. */
-      Timeout.add_seconds (this._test_timeout, () =>
-        {
-          main_loop.quit ();
-          return false;
-        });
 
       Idle.add (() =>
         {
@@ -1066,7 +1022,7 @@ public class AggregationTests : TpfTest.MixedTestCase
           return false;
         });
 
-      main_loop.run ();
+      TestUtils.loop_run_with_non_fatal_timeout (main_loop, 3);
 
       /* Check we've got the individual we want */
       assert (individual != null);
@@ -1085,11 +1041,6 @@ public class AggregationTests : TpfTest.MixedTestCase
       Persona? writeable_persona = null;
 
       /* Kill the main loop after a few seconds. */
-      Timeout.add_seconds (this._test_timeout, () =>
-        {
-          main_loop.quit ();
-          return false;
-        });
 
       Idle.add (() =>
         {
@@ -1114,7 +1065,7 @@ public class AggregationTests : TpfTest.MixedTestCase
           return false;
         });
 
-      main_loop.run ();
+      TestUtils.loop_run_with_non_fatal_timeout (main_loop, 3);
 
       assert (writeable_persona != null);
       assert (writeable_persona == persona);
@@ -1173,11 +1124,6 @@ public class AggregationTests : TpfTest.MixedTestCase
         });
 
       /* Kill the main loop after a few seconds. */
-      var timeout_id = Timeout.add_seconds (this._test_timeout, () =>
-        {
-          main_loop.quit ();
-          return false;
-        });
 
       Idle.add (() =>
         {
@@ -1198,7 +1144,7 @@ public class AggregationTests : TpfTest.MixedTestCase
           return false;
         });
 
-      main_loop.run ();
+      TestUtils.loop_run_with_non_fatal_timeout (main_loop, 3);
 
       /* Check we've got the individual we want */
       assert (individual != null);
@@ -1218,7 +1164,6 @@ public class AggregationTests : TpfTest.MixedTestCase
 
       /* Remove the signal handler */
       aggregator.disconnect (individuals_changed_id);
-      Source.remove (timeout_id);
       aggregator.individuals_changed_detailed.connect ((changes) =>
         {
           var added = changes.get_values ();
@@ -1270,11 +1215,6 @@ public class AggregationTests : TpfTest.MixedTestCase
         });
 
       /* Kill the main loop after a few seconds. */
-      Timeout.add_seconds (this._test_timeout, () =>
-        {
-          main_loop.quit ();
-          return false;
-        });
 
       Idle.add (() =>
         {
@@ -1299,7 +1239,7 @@ public class AggregationTests : TpfTest.MixedTestCase
           return false;
         });
 
-      main_loop.run ();
+      TestUtils.loop_run_with_non_fatal_timeout (main_loop, 3);
 
       assert (writeable_persona != null);
       assert (writeable_persona != persona);
@@ -1351,11 +1291,6 @@ public class AggregationTests : TpfTest.MixedTestCase
         });
 
       /* Kill the main loop after a few seconds. */
-      Timeout.add_seconds (this._test_timeout, () =>
-        {
-          main_loop.quit ();
-          return false;
-        });
 
       Idle.add (() =>
         {
@@ -1376,7 +1311,7 @@ public class AggregationTests : TpfTest.MixedTestCase
           return false;
         });
 
-      main_loop.run ();
+      TestUtils.loop_run_with_non_fatal_timeout (main_loop, 3);
 
       /* Check we've got the individual we want */
       assert (individual != null);
@@ -1395,11 +1330,6 @@ public class AggregationTests : TpfTest.MixedTestCase
       Persona? writeable_persona = null;
 
       /* Kill the main loop after a few seconds. */
-      Timeout.add_seconds (this._test_timeout, () =>
-        {
-          main_loop.quit ();
-          return false;
-        });
 
       Idle.add (() =>
         {
@@ -1428,7 +1358,7 @@ public class AggregationTests : TpfTest.MixedTestCase
           return false;
         });
 
-      main_loop.run ();
+      TestUtils.loop_run_with_non_fatal_timeout (main_loop, 3);
 
       assert (writeable_persona == null);
 
diff --git a/tests/folks/init.vala b/tests/folks/init.vala
index 3dd44e6..b7318e9 100644
--- a/tests/folks/init.vala
+++ b/tests/folks/init.vala
@@ -23,8 +23,6 @@ using Folks;
 
 public class InitTests : TpfTest.MixedTestCase
 {
-  private int _test_timeout = 5;
-
   public InitTests ()
     {
       base ("Init");
@@ -69,14 +67,7 @@ public class InitTests : TpfTest.MixedTestCase
           aggregator = null;
         }
 
-      /* Kill the main loop after a few seconds. */
-      Timeout.add_seconds (this._test_timeout, () =>
-        {
-          main_loop.quit ();
-          return false;
-        });
-
-      main_loop.run ();
+      TestUtils.loop_run_with_non_fatal_timeout (main_loop, 5);
 
       /* Clean up for the next test */
       tp_backend.remove_account (account2_handle);
diff --git a/tests/key-file/individual-retrieval.vala b/tests/key-file/individual-retrieval.vala
index ce33e7f..e6657f4 100644
--- a/tests/key-file/individual-retrieval.vala
+++ b/tests/key-file/individual-retrieval.vala
@@ -23,17 +23,12 @@ using KfTest;
 
 public class IndividualRetrievalTests : KfTest.TestCase
 {
-  private int _test_timeout = 3;
-
   public IndividualRetrievalTests ()
     {
       base ("IndividualRetrieval");
 
       this.add_test ("singleton individuals", this.test_singleton_individuals);
       this.add_test ("aliases", this.test_aliases);
-
-      if (Environment.get_variable ("FOLKS_TEST_VALGRIND") != null)
-          this._test_timeout = 10;
     }
 
   public void test_singleton_individuals ()
@@ -85,13 +80,7 @@ public class IndividualRetrievalTests : KfTest.TestCase
       /* Kill the main loop after a few seconds. If there are still individuals
        * in the set of expected individuals, the aggregator has either failed
        * or been too slow (which we can consider to be failure). */
-      Timeout.add_seconds (this._test_timeout, () =>
-        {
-          main_loop.quit ();
-          return false;
-        });
-
-      main_loop.run ();
+      TestUtils.loop_run_with_non_fatal_timeout (main_loop, 3);
 
       /* We should have enumerated exactly the individuals in the set */
       assert (expected_individuals.size == 0);
@@ -136,13 +125,7 @@ public class IndividualRetrievalTests : KfTest.TestCase
       /* Kill the main loop after a few seconds. If there are still individuals
        * in the set of expected individuals, the aggregator has either failed
        * or been too slow (which we can consider to be failure). */
-      Timeout.add_seconds (this._test_timeout, () =>
-        {
-          main_loop.quit ();
-          return false;
-        });
-
-      main_loop.run ();
+      TestUtils.loop_run_with_non_fatal_timeout (main_loop, 3);
 
       /* We should have enumerated exactly one individual */
       assert (individuals_changed_count == 1);
diff --git a/tests/lib/libsocialweb/test-case.vala b/tests/lib/libsocialweb/test-case.vala
index 90b6ceb..2617588 100644
--- a/tests/lib/libsocialweb/test-case.vala
+++ b/tests/lib/libsocialweb/test-case.vala
@@ -73,14 +73,9 @@ public class LibsocialwebTest.TestCase : Folks.TestCase
         {
           main_loop.quit ();
         });
-      uint timer_id = Timeout.add_seconds (5, () =>
-        {
-          assert_not_reached ();
-        });
 
       lsw_backend.set_up ();
-      main_loop.run ();
-      Source.remove (timer_id);
+      Folks.TestUtils.loop_run_with_timeout (main_loop, 5);
     }
 
   public override void tear_down ()
diff --git a/tests/lib/test-utils.vala b/tests/lib/test-utils.vala
index 8878bd5..dbb1ecf 100644
--- a/tests/lib/test-utils.vala
+++ b/tests/lib/test-utils.vala
@@ -31,6 +31,83 @@ public class Folks.TestUtils
   public extern static bool remove_directory_recursively (string path);
 
   /**
+   * Apply an arbitrary fudge factor to the timeout, which might be
+   * appropriate for any debuggers or other slow wrappers we're using.
+   *
+   * @param timeout A timeout in any units
+   * @return A revised timeout in the same units
+   */
+  public static int multiply_timeout (int timeout)
+    {
+      int result = timeout;
+
+      if (Environment.get_variable ("FOLKS_TEST_VALGRIND") != null)
+        {
+          result *= 10;
+        }
+
+      if (Environment.get_variable ("FOLKS_TEST_CALLGRIND") != null)
+        {
+          result *= 10;
+        }
+
+      return result;
+    }
+
+  /**
+   * Run //loop// with a timeout. Something should call ``loop.quit()``
+   * before the timeout is reached. If not, a fatal error occurs.
+   *
+   * @param loop A main loop.
+   * @param timeout A timeout, initially in seconds, defaulting to long
+   *    enough to do something "reasonably fast". It will be adjusted with
+   *    multiply_timeout() before use.
+   */
+  public static void loop_run_with_timeout (MainLoop loop, int timeout = 5)
+    {
+      var source = new TimeoutSource.seconds (
+          TestUtils.multiply_timeout (timeout));
+      source.set_callback (() => { error ("Timed out"); });
+      source.attach (loop.get_context ());
+
+      loop.run ();
+
+      source.destroy ();
+    }
+
+  /**
+   * Run //loop// with a timeout. Something should call ``loop.quit()``
+   * before the timeout is reached. If not, the timeout callback will do so.
+   *
+   * This function is a bad idea: we don't want things to run for an arbitrary
+   * time. Use loop_run_with_timeout() instead.
+   *
+   * FIXME: Remove this when it has no more callers.
+   *
+   * @param loop A main loop.
+   * @param timeout A timeout, initially in seconds, defaulting to long
+   *    enough to do something "reasonably fast". It will be adjusted with
+   *    multiply_timeout() before use.
+   */
+  [Deprecated (replacement = "loop_run_with_timeout")]
+  public static void loop_run_with_non_fatal_timeout (MainLoop loop,
+      int timeout = 3)
+    {
+      var source = new TimeoutSource.seconds (
+          TestUtils.multiply_timeout (timeout));
+      source.set_callback (() =>
+        {
+          loop.quit ();
+          return false;
+        });
+      source.attach (loop.get_context ());
+
+      loop.run ();
+
+      source.destroy ();
+    }
+
+  /**
    * Compare the content of two { link LoadableIcon}s for equality.
    *
    * This is in contrast to { link Icon.equal}, which returns ``false`` for
diff --git a/tests/libsocialweb/aggregation.vala b/tests/libsocialweb/aggregation.vala
index 9e197e4..6d47bec 100644
--- a/tests/libsocialweb/aggregation.vala
+++ b/tests/libsocialweb/aggregation.vala
@@ -183,12 +183,7 @@ public class AggregationTests : LibsocialwebTest.TestCase
         });
       aggregator.prepare.begin ();
 
-      uint timer_id = Timeout.add_seconds (5, () =>
-        {
-          assert_not_reached ();
-        });
-      main_loop.run ();
-      Source.remove (timer_id);
+      TestUtils.loop_run_with_timeout (main_loop, 5);
       aggregator.disconnect (handler_id);
 
       /* Check the aggregator got the correct data */
@@ -258,12 +253,7 @@ public class AggregationTests : LibsocialwebTest.TestCase
           return false;
         });
 
-      timer_id = Timeout.add_seconds (5, () =>
-        {
-          assert_not_reached ();
-        });
-      main_loop.run ();
-      Source.remove (timer_id);
+      TestUtils.loop_run_with_timeout (main_loop, 5);
     }
 }
 
diff --git a/tests/libsocialweb/dummy-lsw.vala b/tests/libsocialweb/dummy-lsw.vala
index e34c131..4cccffd 100644
--- a/tests/libsocialweb/dummy-lsw.vala
+++ b/tests/libsocialweb/dummy-lsw.vala
@@ -66,12 +66,7 @@ public class DummyLswTests : LibsocialwebTest.TestCase
           assert_not_reached ();
         }
 
-      uint timer_id = Timeout.add_seconds (5, () =>
-        {
-          assert_not_reached ();
-        });
-      main_loop.run ();
-      Source.remove (timer_id);
+      TestUtils.loop_run_with_timeout (main_loop, 5);
 
       /* Test adding two contacts */
 
@@ -141,12 +136,7 @@ public class DummyLswTests : LibsocialwebTest.TestCase
         });
       aggregator.prepare.begin ();
 
-      timer_id = Timeout.add_seconds (5, () =>
-        {
-          assert_not_reached ();
-        });
-      main_loop.run ();
-      Source.remove (timer_id);
+      TestUtils.loop_run_with_timeout (main_loop, 5);
       aggregator.disconnect (handler_id);
       assert (i1 != null);
       assert (i2 != null);
@@ -211,12 +201,7 @@ public class DummyLswTests : LibsocialwebTest.TestCase
           main_loop.quit ();
         });
 
-      timer_id = Timeout.add_seconds (5, () =>
-        {
-          assert_not_reached ();
-        });
-      main_loop.run ();
-      Source.remove (timer_id);
+      TestUtils.loop_run_with_timeout (main_loop, 5);
       i1.disconnect (handler_id);
 
       /* Test deleting two contacts */
@@ -268,12 +253,7 @@ public class DummyLswTests : LibsocialwebTest.TestCase
           main_loop.quit ();
         });
 
-      timer_id = Timeout.add_seconds (5, () =>
-        {
-          assert_not_reached ();
-        });
-      main_loop.run ();
-      Source.remove (timer_id);
+      TestUtils.loop_run_with_timeout (main_loop, 5);
       aggregator.disconnect (handler_id);
     }
 }
diff --git a/tests/telepathy/individual-properties.vala b/tests/telepathy/individual-properties.vala
index 931098f..e355661 100644
--- a/tests/telepathy/individual-properties.vala
+++ b/tests/telepathy/individual-properties.vala
@@ -26,7 +26,6 @@ using Gee;
 
 public class IndividualPropertiesTests : TpfTest.TestCase
 {
-  private int _test_timeout = 3;
   private HashSet<string>? _changes_pending = null;
 
   public IndividualPropertiesTests ()
@@ -41,9 +40,6 @@ public class IndividualPropertiesTests : TpfTest.TestCase
           this.test_individual_properties_change_alias_through_test_cm);
       this.add_test ("individual properties:change contact info",
           this.test_individual_properties_change_contact_info);
-
-      if (Environment.get_variable ("FOLKS_TEST_VALGRIND") != null)
-          this._test_timeout = 10;
     }
 
   public override void set_up ()
@@ -183,13 +179,7 @@ public class IndividualPropertiesTests : TpfTest.TestCase
       /* Kill the main loop after a few seconds. If there are still individuals
        * in the set of expected individuals, the aggregator has either failed
        * or been too slow (which we can consider to be failure). */
-      Timeout.add_seconds (this._test_timeout, () =>
-        {
-          main_loop.quit ();
-          return false;
-        });
-
-      main_loop.run ();
+      TestUtils.loop_run_with_non_fatal_timeout (main_loop);
 
       /* necessary to reset the aggregator for the next test */
       aggregator = null;
@@ -260,13 +250,7 @@ public class IndividualPropertiesTests : TpfTest.TestCase
       /* Kill the main loop after a few seconds. If the alias hasn't been
        * notified, something along the way failed or been too slow (which we can
        * consider to be failure). */
-      Timeout.add_seconds (this._test_timeout, () =>
-        {
-          main_loop.quit ();
-          return false;
-        });
-
-      main_loop.run ();
+      TestUtils.loop_run_with_non_fatal_timeout (main_loop);
 
       assert (alias_notified);
 
@@ -340,13 +324,7 @@ public class IndividualPropertiesTests : TpfTest.TestCase
       /* Kill the main loop after a few seconds. If the alias hasn't been
        * notified, something along the way failed or been too slow (which we can
        * consider to be failure). */
-      Timeout.add_seconds (this._test_timeout, () =>
-        {
-          main_loop.quit ();
-          return false;
-        });
-
-      main_loop.run ();
+      TestUtils.loop_run_with_non_fatal_timeout (main_loop);
 
       assert (alias_notified);
 
@@ -375,13 +353,7 @@ public class IndividualPropertiesTests : TpfTest.TestCase
       /* Kill the main loop after a few seconds. If the alias hasn't been
        * notified, something along the way failed or been too slow (which we can
        * consider to be failure). */
-      Timeout.add_seconds (this._test_timeout, () =>
-        {
-          main_loop.quit ();
-          return false;
-        });
-
-      main_loop.run ();
+      TestUtils.loop_run_with_non_fatal_timeout (main_loop);
 
       assert (this._changes_pending.size == 0);
 
diff --git a/tests/telepathy/individual-retrieval.vala b/tests/telepathy/individual-retrieval.vala
index 490a8a8..5919e3d 100644
--- a/tests/telepathy/individual-retrieval.vala
+++ b/tests/telepathy/individual-retrieval.vala
@@ -27,7 +27,6 @@ using Gee;
 public class IndividualRetrievalTests : TpfTest.TestCase
 {
   private HashSet<string> default_individuals;
-  private int _test_timeout = 3;
 
   public IndividualRetrievalTests ()
     {
@@ -63,9 +62,6 @@ public class IndividualRetrievalTests : TpfTest.TestCase
 
       this.add_test ("aggregator", this.test_aggregator);
       this.add_test ("aggregator:add", this.test_aggregator_add);
-
-      if (Environment.get_variable ("FOLKS_TEST_VALGRIND") != null)
-          this._test_timeout = 10;
     }
 
   public void test_aggregator ()
@@ -101,11 +97,6 @@ public class IndividualRetrievalTests : TpfTest.TestCase
       /* Kill the main loop after a few seconds. If there are still individuals
        * in the set of expected individuals, the aggregator has either failed or
        * been too slow (which we can consider to be failure). */
-      Timeout.add_seconds (this._test_timeout, () =>
-        {
-          main_loop.quit ();
-          return false;
-        });
 
       Idle.add (() =>
         {
@@ -126,7 +117,7 @@ public class IndividualRetrievalTests : TpfTest.TestCase
           return false;
         });
 
-      main_loop.run ();
+      TestUtils.loop_run_with_non_fatal_timeout (main_loop);
 
       /* We should have enumerated exactly the individuals in the set */
       assert (expected_individuals.size == 0);
@@ -181,11 +172,6 @@ public class IndividualRetrievalTests : TpfTest.TestCase
       /* Kill the main loop after a few seconds. If there are still individuals
        * in the set of expected individuals, the aggregator has either failed or
        * been too slow (which we can consider to be failure). */
-      Timeout.add_seconds (this._test_timeout, () =>
-        {
-          main_loop.quit ();
-          return false;
-        });
 
       Idle.add (() =>
         {
@@ -239,7 +225,7 @@ public class IndividualRetrievalTests : TpfTest.TestCase
           return false;
         });
 
-      main_loop.run ();
+      TestUtils.loop_run_with_non_fatal_timeout (main_loop);
 
       /* We should have received (and removed) the individuals in the set */
       assert (added_individuals.size == 0);
diff --git a/tests/telepathy/init.vala b/tests/telepathy/init.vala
index df057e4..92cb1ff 100644
--- a/tests/telepathy/init.vala
+++ b/tests/telepathy/init.vala
@@ -22,8 +22,6 @@ using Folks;
 
 public class InitTests : TpfTest.TestCase
 {
-  private int _test_timeout = 5;
-
   public InitTests ()
     {
       base ("Init");
@@ -63,13 +61,7 @@ public class InitTests : TpfTest.TestCase
         });
 
       /* Add a timeout for failure. */
-      Timeout.add_seconds (this._test_timeout, () =>
-        {
-          main_loop.quit ();
-          return false;
-        });
-
-      main_loop.run ();
+      TestUtils.loop_run_with_non_fatal_timeout (this._main_loop, 5);
 
       /* Check results. */
       assert (aggregator.is_quiescent == true);
diff --git a/tests/telepathy/persona-store-capabilities.vala b/tests/telepathy/persona-store-capabilities.vala
index e3d9acd..303ec25 100644
--- a/tests/telepathy/persona-store-capabilities.vala
+++ b/tests/telepathy/persona-store-capabilities.vala
@@ -27,7 +27,6 @@ using Gee;
 public class PersonaStoreCapabilitiesTests : TpfTest.TestCase
 {
   private HashSet<string>? _capabilities_received = null;
-  private int _test_timeout = 3;
 
   public PersonaStoreCapabilitiesTests ()
     {
@@ -35,9 +34,6 @@ public class PersonaStoreCapabilitiesTests : TpfTest.TestCase
 
       this.add_test ("persona store capabilities",
           this.test_persona_store_capabilities);
-
-      if (Environment.get_variable ("FOLKS_TEST_VALGRIND") != null)
-          this._test_timeout = 10;
     }
 
   public override void set_up ()
@@ -79,13 +75,7 @@ public class PersonaStoreCapabilitiesTests : TpfTest.TestCase
 
       backend_store.load_backends.begin ();
 
-      Timeout.add_seconds (this._test_timeout, () =>
-        {
-          main_loop.quit ();
-          return false;
-        });
-
-      main_loop.run ();
+      TestUtils.loop_run_with_non_fatal_timeout (main_loop);
 
       assert (this._capabilities_received.contains ("can-add-personas"));
       assert (this._capabilities_received.contains ("can-remove-personas"));
diff --git a/tests/tracker/add-contact.vala b/tests/tracker/add-contact.vala
index 27678d6..e921fe8 100644
--- a/tests/tracker/add-contact.vala
+++ b/tests/tracker/add-contact.vala
@@ -51,13 +51,7 @@ public class AddContactTests : TrackerTest.TestCase
 
       this._test_add_contact_async.begin ();
 
-      Timeout.add_seconds (5, () =>
-          {
-            this._main_loop.quit ();
-            assert_not_reached ();
-          });
-
-      this._main_loop.run ();
+      TestUtils.loop_run_with_timeout (this._main_loop);
       assert (this._contact_added == true);
     }
 
diff --git a/tests/tracker/add-persona.vala b/tests/tracker/add-persona.vala
index 4e81260..109c3c6 100644
--- a/tests/tracker/add-persona.vala
+++ b/tests/tracker/add-persona.vala
@@ -121,13 +121,7 @@ public class AddPersonaTests : TrackerTest.TestCase
 
       this._test_add_persona_async.begin ();
 
-      Timeout.add_seconds (5, () =>
-        {
-          this._main_loop.quit ();
-          assert_not_reached ();
-        });
-
-      this._main_loop.run ();
+      TestUtils.loop_run_with_timeout (this._main_loop);
 
       foreach (var k in this._properties_found.get_values ())
         {
diff --git a/tests/tracker/additional-names-updates.vala b/tests/tracker/additional-names-updates.vala
index 6d60dfa..de3ad71 100644
--- a/tests/tracker/additional-names-updates.vala
+++ b/tests/tracker/additional-names-updates.vala
@@ -69,13 +69,7 @@ public class AdditionalNamesUpdatesTests : TrackerTest.TestCase
       var store = BackendStore.dup ();
       _test_additional_names_updates_async.begin (store);
 
-      Timeout.add_seconds (5, () =>
-        {
-          this._main_loop.quit ();
-          assert_not_reached ();
-        });
-
-      this._main_loop.run ();
+      TestUtils.loop_run_with_timeout (this._main_loop);
 
       assert (this._initial_additional_names_found == true);
       assert (this._updated_additional_names_found == true);
diff --git a/tests/tracker/avatar-details-interface.vala b/tests/tracker/avatar-details-interface.vala
index 3d0ba69..782d338 100644
--- a/tests/tracker/avatar-details-interface.vala
+++ b/tests/tracker/avatar-details-interface.vala
@@ -56,13 +56,7 @@ public class AvatarDetailsInterfaceTests : TrackerTest.TestCase
 
       test_avatar_details_interface_async.begin ();
 
-      Timeout.add_seconds (5, () =>
-        {
-          this._main_loop.quit ();
-          assert_not_reached ();
-        });
-
-      this._main_loop.run ();
+      TestUtils.loop_run_with_timeout (this._main_loop);
       assert (this._avatars_are_equal);
     }
 
diff --git a/tests/tracker/avatar-updates.vala b/tests/tracker/avatar-updates.vala
index 4eda6c1..0c8ad7b 100644
--- a/tests/tracker/avatar-updates.vala
+++ b/tests/tracker/avatar-updates.vala
@@ -71,13 +71,7 @@ public class AvatarUpdatesTests : TrackerTest.TestCase
 
       test_avatar_updates_async.begin ();
 
-      Timeout.add_seconds (5, () =>
-        {
-          this._main_loop.quit ();
-          assert_not_reached ();
-        });
-
-      this._main_loop.run ();
+      TestUtils.loop_run_with_timeout (this._main_loop);
 
       assert (this._initial_avatar_found == true);
       assert (this._updated_avatar_found == true);
diff --git a/tests/tracker/birthday-details-interface.vala b/tests/tracker/birthday-details-interface.vala
index 73c4988..c349b8e 100644
--- a/tests/tracker/birthday-details-interface.vala
+++ b/tests/tracker/birthday-details-interface.vala
@@ -60,13 +60,7 @@ public class BirthdayDetailsInterfaceTests : TrackerTest.TestCase
 
       this._test_birthay_details_interface.begin ();
 
-      Timeout.add_seconds (5, () =>
-        {
-          this._main_loop.quit ();
-          assert_not_reached ();
-        });
-
-      this._main_loop.run ();
+      TestUtils.loop_run_with_timeout (this._main_loop);
 
       assert (this._found_birthday == true);
     }
diff --git a/tests/tracker/birthday-updates.vala b/tests/tracker/birthday-updates.vala
index 2f7e241..f35fef5 100644
--- a/tests/tracker/birthday-updates.vala
+++ b/tests/tracker/birthday-updates.vala
@@ -77,13 +77,7 @@ public class BirthdayUpdatesTests : TrackerTest.TestCase
       test_birthday_updates_async.begin ();
 
 
-      Timeout.add_seconds (5, () =>
-        {
-          this._main_loop.quit ();
-          assert_not_reached ();
-        });
-
-      this._main_loop.run ();
+      TestUtils.loop_run_with_timeout (this._main_loop);
 
       assert (this._initial_birthday_found == true);
       assert (this._updated_birthday_found == true);
diff --git a/tests/tracker/default-contact.vala b/tests/tracker/default-contact.vala
index c83c4d1..14f01b0 100644
--- a/tests/tracker/default-contact.vala
+++ b/tests/tracker/default-contact.vala
@@ -55,13 +55,7 @@ public class DefaultContactTests : TrackerTest.TestCase
 
       _test_default_contact_async.begin ();
 
-      Timeout.add_seconds (5, () =>
-        {
-          this._main_loop.quit ();
-          assert_not_reached ();
-        });
-
-      this._main_loop.run ();
+      TestUtils.loop_run_with_timeout (this._main_loop);
 
       assert (this._found_default_user == true);
       assert (this._found_not_user == true);
diff --git a/tests/tracker/duplicated-emails.vala b/tests/tracker/duplicated-emails.vala
index 709fc59..582907b 100644
--- a/tests/tracker/duplicated-emails.vala
+++ b/tests/tracker/duplicated-emails.vala
@@ -49,13 +49,7 @@ public class DuplicatedEmailsTests : TrackerTest.TestCase
 
       this._test_duplicated_emails_async.begin ();
 
-      Timeout.add_seconds (5, () =>
-        {
-          this._main_loop.quit ();
-          assert_not_reached ();
-        });
-
-      this._main_loop.run ();
+      TestUtils.loop_run_with_timeout (this._main_loop);
       assert (this._individual_id_1 != "");
       assert (this._individual_id_2 != "");
     }
diff --git a/tests/tracker/duplicated-phones.vala b/tests/tracker/duplicated-phones.vala
index c9461a5..1d5fae4 100644
--- a/tests/tracker/duplicated-phones.vala
+++ b/tests/tracker/duplicated-phones.vala
@@ -49,13 +49,7 @@ public class DuplicatedPhonesTests : TrackerTest.TestCase
 
       this._test_duplicated_phones_async.begin ();
 
-      Timeout.add_seconds (5, () =>
-        {
-          this._main_loop.quit ();
-          assert_not_reached ();
-        });
-
-      this._main_loop.run ();
+      TestUtils.loop_run_with_timeout (this._main_loop);
       assert (this._individual_id_1 != "");
       assert (this._individual_id_2 != "");
     }
diff --git a/tests/tracker/email-details-interface.vala b/tests/tracker/email-details-interface.vala
index 74a9aad..e6a6fca 100644
--- a/tests/tracker/email-details-interface.vala
+++ b/tests/tracker/email-details-interface.vala
@@ -57,13 +57,7 @@ public class EmailDetailsInterfaceTests : TrackerTest.TestCase
 
       this._test_email_details_interface_async.begin ();
 
-      Timeout.add_seconds (5, () =>
-        {
-          this._main_loop.quit ();
-          assert_not_reached ();
-        });
-
-      this._main_loop.run ();
+      TestUtils.loop_run_with_timeout (this._main_loop);
 
       assert (this._num_emails == 2);
       assert (this._found_email_1 == true);
diff --git a/tests/tracker/emails-updates.vala b/tests/tracker/emails-updates.vala
index a5f9766..2c9c5dd 100644
--- a/tests/tracker/emails-updates.vala
+++ b/tests/tracker/emails-updates.vala
@@ -66,13 +66,7 @@ public class EmailsUpdatesTests : TrackerTest.TestCase
 
       this._test_emails_updates_async.begin ();
 
-      Timeout.add_seconds (5, () =>
-        {
-          this._main_loop.quit ();
-          assert_not_reached ();
-        });
-
-      this._main_loop.run ();
+      TestUtils.loop_run_with_timeout (this._main_loop);
 
       assert (this._initial_email_found == true);
 
diff --git a/tests/tracker/family-name-updates.vala b/tests/tracker/family-name-updates.vala
index d2b924d..da2af7b 100644
--- a/tests/tracker/family-name-updates.vala
+++ b/tests/tracker/family-name-updates.vala
@@ -67,13 +67,7 @@ public class FamilyNameUpdatesTests : TrackerTest.TestCase
 
       this._test_family_name_updates_async.begin ();
 
-      Timeout.add_seconds (5, () =>
-        {
-          this._main_loop.quit ();
-          assert_not_reached ();
-        });
-
-      this._main_loop.run ();
+      TestUtils.loop_run_with_timeout (this._main_loop);
 
       assert (this._initial_family_name_found == true);
       assert (this._updated_family_name_found == true);
diff --git a/tests/tracker/favourite-details-interface.vala b/tests/tracker/favourite-details-interface.vala
index 93e1a5b..61d7258 100644
--- a/tests/tracker/favourite-details-interface.vala
+++ b/tests/tracker/favourite-details-interface.vala
@@ -71,13 +71,7 @@ public class FavouriteDetailsInterfaceTests : TrackerTest.TestCase
 
       this._test_favourite_details_interface_async.begin ();
 
-      Timeout.add_seconds (5, () =>
-        {
-          this._main_loop.quit ();
-          return false;
-        });
-
-      this._main_loop.run ();
+      TestUtils.loop_run_with_timeout (this._main_loop);
 
       assert (this._found_p1 == true);
       assert (this._found_p2 == true);
diff --git a/tests/tracker/favourite-updates.vala b/tests/tracker/favourite-updates.vala
index 498cc1f..0b24b49 100644
--- a/tests/tracker/favourite-updates.vala
+++ b/tests/tracker/favourite-updates.vala
@@ -75,13 +75,7 @@ public class FavouriteUpdatesTests : TrackerTest.TestCase
 
       // this timer is slightly higher than usual because sleep
       // to ensure a (usually delayed) INSERT event has happened
-      Timeout.add_seconds (7, () =>
-        {
-          this._main_loop.quit ();
-          assert_not_reached ();
-        });
-
-      this._main_loop.run ();
+      TestUtils.loop_run_with_timeout (this._main_loop, 7);
 
       assert (this._is_favourite_1 == true);
       assert (this._is_favourite_2 == false);
diff --git a/tests/tracker/fullname-updates.vala b/tests/tracker/fullname-updates.vala
index a617c2b..aec16d7 100644
--- a/tests/tracker/fullname-updates.vala
+++ b/tests/tracker/fullname-updates.vala
@@ -65,13 +65,7 @@ public class FullnameUpdatesTests : TrackerTest.TestCase
 
       this._test_fullname_updates_async.begin ();
 
-      Timeout.add_seconds (5, () =>
-        {
-          this._main_loop.quit ();
-          assert_not_reached ();
-        });
-
-      this._main_loop.run ();
+      TestUtils.loop_run_with_timeout (this._main_loop);
 
       assert (this._initial_name_found == true);
       assert (this._updated_name_found == true);
diff --git a/tests/tracker/gender-details-interface.vala b/tests/tracker/gender-details-interface.vala
index 4343083..17cbf51 100644
--- a/tests/tracker/gender-details-interface.vala
+++ b/tests/tracker/gender-details-interface.vala
@@ -57,13 +57,7 @@ public class GenderDetailsInterfaceTests : TrackerTest.TestCase
 
       this._test_gender_details_interface_async.begin ();
 
-      Timeout.add_seconds (5, () =>
-        {
-          this._main_loop.quit ();
-          return false;
-        });
-
-      this._main_loop.run ();
+      TestUtils.loop_run_with_timeout (this._main_loop);
 
       assert (this._found_gender == true);
     }
diff --git a/tests/tracker/given-name-updates.vala b/tests/tracker/given-name-updates.vala
index 2c2db0b..968759a 100644
--- a/tests/tracker/given-name-updates.vala
+++ b/tests/tracker/given-name-updates.vala
@@ -66,13 +66,7 @@ public class GivenNameUpdatesTests : TrackerTest.TestCase
 
       this._test_given_name_updates_async.begin ();
 
-      Timeout.add_seconds (5, () =>
-        {
-          this._main_loop.quit ();
-          assert_not_reached ();
-        });
-
-      this._main_loop.run ();
+      TestUtils.loop_run_with_timeout (this._main_loop);
 
       assert (this._initial_given_name_found == true);
       assert (this._updated_given_name_found == true);
diff --git a/tests/tracker/im-details-interface.vala b/tests/tracker/im-details-interface.vala
index 557e01a..dc80f11 100644
--- a/tests/tracker/im-details-interface.vala
+++ b/tests/tracker/im-details-interface.vala
@@ -59,13 +59,7 @@ public class ImDetailsInterfaceTests : TrackerTest.TestCase
 
       this._test_im_details_interface_async.begin ();
 
-      Timeout.add_seconds (5, () =>
-        {
-          this._main_loop.quit ();
-          assert_not_reached ();
-        });
-
-      this._main_loop.run ();
+      TestUtils.loop_run_with_timeout (this._main_loop);
 
       assert (this._num_addrs == 2);
       assert (this._found_addr_1 == true);
diff --git a/tests/tracker/imaddresses-updates.vala b/tests/tracker/imaddresses-updates.vala
index 89c0abe..8e486db 100644
--- a/tests/tracker/imaddresses-updates.vala
+++ b/tests/tracker/imaddresses-updates.vala
@@ -69,13 +69,7 @@ public class IMAddressesUpdatesTests : TrackerTest.TestCase
 
       this._test_imaddresses_updates_async.begin ();
 
-      Timeout.add_seconds (5, () =>
-        {
-          this._main_loop.quit ();
-          assert_not_reached ();
-        });
-
-      this._main_loop.run ();
+      TestUtils.loop_run_with_timeout (this._main_loop);
 
       assert (this._initial_imaddress_found == true);
       assert (this._updated_imaddr_found == true);
diff --git a/tests/tracker/individual-retrieval.vala b/tests/tracker/individual-retrieval.vala
index 048bdd6..46a7346 100644
--- a/tests/tracker/individual-retrieval.vala
+++ b/tests/tracker/individual-retrieval.vala
@@ -51,13 +51,7 @@ public class IndividualRetrievalTests : TrackerTest.TestCase
 
       this._test_singleton_individuals_async.begin ();
 
-      Timeout.add_seconds (5, () =>
-        {
-          this._main_loop.quit ();
-          assert_not_reached ();
-        });
-
-      this._main_loop.run ();
+      TestUtils.loop_run_with_timeout (this._main_loop);
 
       assert (this._c1.size == 0);
       assert (this._c2.size == 0);
diff --git a/tests/tracker/link-personas-via-local-ids.vala b/tests/tracker/link-personas-via-local-ids.vala
index eb28392..860cd79 100644
--- a/tests/tracker/link-personas-via-local-ids.vala
+++ b/tests/tracker/link-personas-via-local-ids.vala
@@ -83,13 +83,7 @@ public class LinkPersonasViaLocalIDsTests : TrackerTest.TestCase
       /* Kill the main loop after 8 seconds: if the linked individual hasn't
        * show up at this point then we've either seen an error or we've been
        * too slow (which we can consider to be failure). */
-      Timeout.add_seconds (8, () =>
-        {
-          this._main_loop.quit ();
-          assert_not_reached ();
-        });
-
-      this._main_loop.run ();
+      TestUtils.loop_run_with_timeout (this._main_loop, 8);
 
       /* Check we get the new individual (containing the linked
        * personas) and that the previous ones were removed. */
diff --git a/tests/tracker/link-personas.vala b/tests/tracker/link-personas.vala
index 9a9c22f..ba2b300 100644
--- a/tests/tracker/link-personas.vala
+++ b/tests/tracker/link-personas.vala
@@ -86,13 +86,7 @@ public class LinkPersonasTests : TrackerTest.TestCase
       /* Kill the main loop after 5 seconds: if the linked individual hasn't
        * show up at this point then we've either seen an error or we've been
        * too slow (which we can consider to be failure). */
-      Timeout.add_seconds (5, () =>
-        {
-          this._main_loop.quit ();
-          assert_not_reached ();
-        });
-
-      this._main_loop.run ();
+      TestUtils.loop_run_with_timeout (this._main_loop);
 
       /* Check we get the new individual (containing the linked
        * personas) and that the previous ones were removed. */
diff --git a/tests/tracker/match-all.vala b/tests/tracker/match-all.vala
index 21c4bf4..c1c0966 100644
--- a/tests/tracker/match-all.vala
+++ b/tests/tracker/match-all.vala
@@ -54,13 +54,7 @@ public class MatchAllTests : TrackerTest.TestCase
 
      this._test_match_all_async.begin ();
 
-      Timeout.add_seconds (5, () =>
-        {
-          this._main_loop.quit ();
-          assert_not_reached ();
-        });
-
-      this._main_loop.run ();
+      TestUtils.loop_run_with_timeout (this._main_loop);
 
       /* Expected outcome:
        *
diff --git a/tests/tracker/match-email-addresses.vala b/tests/tracker/match-email-addresses.vala
index c55901c..bcbc79f 100644
--- a/tests/tracker/match-email-addresses.vala
+++ b/tests/tracker/match-email-addresses.vala
@@ -50,13 +50,7 @@ public class MatchEmailAddressesTests : TrackerTest.TestCase
 
       this._test_match_email_addresses_async.begin ();
 
-      Timeout.add_seconds (5, () =>
-        {
-          this._main_loop.quit ();
-          assert_not_reached ();
-        });
-
-      this._main_loop.run ();
+      TestUtils.loop_run_with_timeout (this._main_loop);
 
       assert (this._match >= Folks.MatchResult.HIGH);
     }
diff --git a/tests/tracker/match-im-addresses.vala b/tests/tracker/match-im-addresses.vala
index 4b2a267..d914637 100644
--- a/tests/tracker/match-im-addresses.vala
+++ b/tests/tracker/match-im-addresses.vala
@@ -51,13 +51,7 @@ public class MatchIMAddressesTests : TrackerTest.TestCase
 
       this._test_match_im_addresses_async.begin ();
 
-      Timeout.add_seconds (5, () =>
-        {
-          this._main_loop.quit ();
-          assert_not_reached ();
-        });
-
-      this._main_loop.run ();
+      TestUtils.loop_run_with_timeout (this._main_loop);
       assert (this._match >= Folks.MatchResult.HIGH);
     }
 
diff --git a/tests/tracker/match-known-emails.vala b/tests/tracker/match-known-emails.vala
index ea7f547..caeea0e 100644
--- a/tests/tracker/match-known-emails.vala
+++ b/tests/tracker/match-known-emails.vala
@@ -54,13 +54,7 @@ public class MatchKnownEmailsTests : TrackerTest.TestCase
 
       this._test_match_email_addresses_async.begin ();
 
-      Timeout.add_seconds (5, () =>
-        {
-          this._main_loop.quit ();
-          assert_not_reached ();
-        });
-
-      this._main_loop.run ();
+      TestUtils.loop_run_with_timeout (this._main_loop);
 
       /* Some e-mail addresses (namely admin, webmaster, etc.)
        * are considered common alias so they shouldn't
diff --git a/tests/tracker/match-name.vala b/tests/tracker/match-name.vala
index f62cebb..f247803 100644
--- a/tests/tracker/match-name.vala
+++ b/tests/tracker/match-name.vala
@@ -66,13 +66,7 @@ public class MatchNameTests : TrackerTest.TestCase
 
       this._test_match_name_async.begin ();
 
-      Timeout.add_seconds (5, () =>
-        {
-          this._main_loop.quit ();
-          assert_not_reached ();
-        });
-
-      this._main_loop.run ();
+      TestUtils.loop_run_with_timeout (this._main_loop);
     }
 
   public void test_match_name_1 ()
diff --git a/tests/tracker/match-phone-number.vala b/tests/tracker/match-phone-number.vala
index c37d2d2..24246d4 100644
--- a/tests/tracker/match-phone-number.vala
+++ b/tests/tracker/match-phone-number.vala
@@ -51,13 +51,7 @@ public class MatchPhoneNumberTests : TrackerTest.TestCase
 
       this._test_match_phone_number_async.begin ();
 
-      Timeout.add_seconds (5, () =>
-        {
-          this._main_loop.quit ();
-          assert_not_reached ();
-        });
-
-      this._main_loop.run ();
+      TestUtils.loop_run_with_timeout (this._main_loop);
 
       /* Phone number match is very decisive */
       assert (this._match == Folks.MatchResult.HIGH);
diff --git a/tests/tracker/name-details-interface.vala b/tests/tracker/name-details-interface.vala
index 4805437..97f60ba 100644
--- a/tests/tracker/name-details-interface.vala
+++ b/tests/tracker/name-details-interface.vala
@@ -59,13 +59,7 @@ public class NameDetailsInterfaceTests : TrackerTest.TestCase
 
       this._test_name_details_interface_async.begin ();
 
-      Timeout.add_seconds (5, () =>
-        {
-          this._main_loop.quit ();
-          assert_not_reached ();
-        });
-
-      this._main_loop.run ();
+      TestUtils.loop_run_with_timeout (this._main_loop);
 
       assert (this._c1.size == 0);
       assert (this._c2.size == 0);
diff --git a/tests/tracker/nickname-updates.vala b/tests/tracker/nickname-updates.vala
index f4a6f15..bdfda34 100644
--- a/tests/tracker/nickname-updates.vala
+++ b/tests/tracker/nickname-updates.vala
@@ -61,13 +61,7 @@ public class NicknameUpdatesTests : TrackerTest.TestCase
 
       this._test_nickname_updates_async.begin ();
 
-      Timeout.add_seconds (5, () =>
-        {
-          this._main_loop.quit ();
-          assert_not_reached ();
-        });
-
-      this._main_loop.run ();
+      TestUtils.loop_run_with_timeout (this._main_loop);
 
       assert (this._updated_nickname_found == true);
     }
diff --git a/tests/tracker/note-details-interface.vala b/tests/tracker/note-details-interface.vala
index 60296e6..3ed76df 100644
--- a/tests/tracker/note-details-interface.vala
+++ b/tests/tracker/note-details-interface.vala
@@ -58,13 +58,7 @@ public class NoteDetailsInterfaceTests : TrackerTest.TestCase
 
       this._test_note_details_interface_async.begin ();
 
-      Timeout.add_seconds (5, () =>
-        {
-          this._main_loop.quit ();
-          assert_not_reached ();
-        });
-
-      this._main_loop.run ();
+      TestUtils.loop_run_with_timeout (this._main_loop);
 
       assert (this._found_note == true);
     }
diff --git a/tests/tracker/phone-details-interface.vala b/tests/tracker/phone-details-interface.vala
index 346da38..7c97b7b 100644
--- a/tests/tracker/phone-details-interface.vala
+++ b/tests/tracker/phone-details-interface.vala
@@ -56,13 +56,7 @@ public class PhoneDetailsInterfaceTests : TrackerTest.TestCase
 
       this._test_phone_details_interface_async.begin ();
 
-      Timeout.add_seconds (5, () =>
-        {
-          this._main_loop.quit ();
-          assert_not_reached ();
-        });
-
-      this._main_loop.run ();
+      TestUtils.loop_run_with_timeout (this._main_loop);
 
       assert (this._num_phones == 2);
       assert (this._found_phone_1 == true);
diff --git a/tests/tracker/phones-updates.vala b/tests/tracker/phones-updates.vala
index 531d499..3ddea90 100644
--- a/tests/tracker/phones-updates.vala
+++ b/tests/tracker/phones-updates.vala
@@ -68,13 +68,7 @@ public class PhonesUpdatesTests : TrackerTest.TestCase
 
       this._test_phones_updates_async.begin ();
 
-      Timeout.add_seconds (5, () =>
-        {
-          this._main_loop.quit ();
-          assert_not_reached ();
-        });
-
-      this._main_loop.run ();
+      TestUtils.loop_run_with_timeout (this._main_loop);
 
       assert (this._initial_phone_found == true);
       assert (this._initial_phone_found_again == false);
diff --git a/tests/tracker/postal-address-details-interface.vala 
b/tests/tracker/postal-address-details-interface.vala
index 2abadd3..b450c9f 100644
--- a/tests/tracker/postal-address-details-interface.vala
+++ b/tests/tracker/postal-address-details-interface.vala
@@ -89,13 +89,7 @@ public class PostalAddressDetailsInterfaceTests : TrackerTest.TestCase
 
       this._test_postal_address_details_interface_async.begin ();
 
-      Timeout.add_seconds (5, () =>
-        {
-          this._main_loop.quit ();
-          assert_not_reached ();
-        });
-
-      this._main_loop.run ();
+      TestUtils.loop_run_with_timeout (this._main_loop);
 
       assert (this._found_postal_address == true);
     }
diff --git a/tests/tracker/prefix-name-updates.vala b/tests/tracker/prefix-name-updates.vala
index 98408f4..e74589f 100644
--- a/tests/tracker/prefix-name-updates.vala
+++ b/tests/tracker/prefix-name-updates.vala
@@ -66,13 +66,7 @@ public class PrefixNameUpdatesTests : TrackerTest.TestCase
 
       this._test_prefix_name_updates_async.begin ();
 
-      Timeout.add_seconds (5, () =>
-        {
-          this._main_loop.quit ();
-          assert_not_reached ();
-        });
-
-      this._main_loop.run ();
+      TestUtils.loop_run_with_timeout (this._main_loop);
 
       assert (this._initial_prefix_name_found == true);
       assert (this._updated_prefix_name_found == true);
diff --git a/tests/tracker/remove-contact.vala b/tests/tracker/remove-contact.vala
index ac54e12..5571c56 100644
--- a/tests/tracker/remove-contact.vala
+++ b/tests/tracker/remove-contact.vala
@@ -55,13 +55,7 @@ public class RemoveContactTests : TrackerTest.TestCase
 
       this._test_remove_contact_async.begin ();
 
-      Timeout.add_seconds (5, () =>
-        {
-          this._main_loop.quit ();
-          assert_not_reached ();
-        });
-
-      this._main_loop.run ();
+      TestUtils.loop_run_with_timeout (this._main_loop);
 
       assert (this._contact_added == true);
       assert (this._contact_removed == true);
diff --git a/tests/tracker/remove-persona.vala b/tests/tracker/remove-persona.vala
index 4f04010..6367eb9 100644
--- a/tests/tracker/remove-persona.vala
+++ b/tests/tracker/remove-persona.vala
@@ -53,13 +53,7 @@ public class RemovePersonaTests : TrackerTest.TestCase
 
       this._test_remove_persona_async.begin ();
 
-      Timeout.add_seconds (5, () =>
-        {
-          this._main_loop.quit ();
-          assert_not_reached ();
-        });
-
-      this._main_loop.run ();
+      TestUtils.loop_run_with_timeout (this._main_loop);
 
       assert (this._persona_removed == true);
       assert (this._individual_removed == true);
diff --git a/tests/tracker/role-details-interface.vala b/tests/tracker/role-details-interface.vala
index 4d3b0de..65346bc 100644
--- a/tests/tracker/role-details-interface.vala
+++ b/tests/tracker/role-details-interface.vala
@@ -58,13 +58,7 @@ public class RoleDetailsInterfaceTests : TrackerTest.TestCase
 
       this._test_role_details_interface_async.begin ();
 
-      Timeout.add_seconds (5, () =>
-        {
-          this._main_loop.quit ();
-          assert_not_reached ();
-        });
-
-      this._main_loop.run ();
+      TestUtils.loop_run_with_timeout (this._main_loop);
 
       assert (this._found_role == true);
     }
diff --git a/tests/tracker/set-avatar.vala b/tests/tracker/set-avatar.vala
index 4f6220b..794530b 100644
--- a/tests/tracker/set-avatar.vala
+++ b/tests/tracker/set-avatar.vala
@@ -56,13 +56,7 @@ public class SetAvatarTests : TrackerTest.TestCase
 
       this._test_set_avatar_async.begin ();
 
-      Timeout.add_seconds (5, () =>
-        {
-          this._main_loop.quit ();
-          assert_not_reached ();
-        });
-
-      this._main_loop.run ();
+      TestUtils.loop_run_with_timeout (this._main_loop);
 
       assert (this._avatar_found);
     }
diff --git a/tests/tracker/set-birthday.vala b/tests/tracker/set-birthday.vala
index e558c49..56b8546 100644
--- a/tests/tracker/set-birthday.vala
+++ b/tests/tracker/set-birthday.vala
@@ -60,13 +60,7 @@ public class SetBirthdayTests : TrackerTest.TestCase
 
       this._test_set_bday_async.begin ();
 
-      Timeout.add_seconds (5, () =>
-        {
-          this._main_loop.quit ();
-          assert_not_reached ();
-        });
-
-      this._main_loop.run ();
+      TestUtils.loop_run_with_timeout (this._main_loop);
 
       assert (this._bday_found);
     }
diff --git a/tests/tracker/set-duplicate-email.vala b/tests/tracker/set-duplicate-email.vala
index c5110a3..0773a08 100644
--- a/tests/tracker/set-duplicate-email.vala
+++ b/tests/tracker/set-duplicate-email.vala
@@ -48,13 +48,7 @@ public class SetDuplicateEmailTests : TrackerTest.TestCase
       this._email_found = false;
       this._test_set_duplicate_email_async.begin ();
 
-      Timeout.add_seconds (5, () =>
-        {
-          this._main_loop.quit ();
-          assert_not_reached ();
-        });
-
-      this._main_loop.run ();
+      TestUtils.loop_run_with_timeout (this._main_loop);
       /* we should see the e-mail address twice:
        * 1) when we create the Persona
        * 2) when we re-set the address */
diff --git a/tests/tracker/set-emails.vala b/tests/tracker/set-emails.vala
index 63be541..f2ebf0c 100644
--- a/tests/tracker/set-emails.vala
+++ b/tests/tracker/set-emails.vala
@@ -58,13 +58,7 @@ public class SetEmailsTests : TrackerTest.TestCase
 
       this._test_set_emails_async.begin ();
 
-      Timeout.add_seconds (5, () =>
-        {
-          this._main_loop.quit ();
-          assert_not_reached ();
-        });
-
-      this._main_loop.run ();
+      TestUtils.loop_run_with_timeout (this._main_loop);
 
       assert (this._email_1_found);
       assert (this._email_2_found);
diff --git a/tests/tracker/set-favourite.vala b/tests/tracker/set-favourite.vala
index 287c707..90bc63e 100644
--- a/tests/tracker/set-favourite.vala
+++ b/tests/tracker/set-favourite.vala
@@ -65,13 +65,7 @@ public class SetFavouriteTests : TrackerTest.TestCase
 
       this._test_set_alias_async.begin ();
 
-      Timeout.add_seconds (5, () =>
-        {
-          this._main_loop.quit ();
-          assert_not_reached ();
-        });
-
-      this._main_loop.run ();
+      TestUtils.loop_run_with_timeout (this._main_loop);
 
       /* Note:
        *  the is-favourite property is notified as a
diff --git a/tests/tracker/set-full-name.vala b/tests/tracker/set-full-name.vala
index 981e74e..7293b8e 100644
--- a/tests/tracker/set-full-name.vala
+++ b/tests/tracker/set-full-name.vala
@@ -57,13 +57,7 @@ public class SetFullNameTests : TrackerTest.TestCase
 
       this._test_set_full_name_async.begin ();
 
-      Timeout.add_seconds (5, () =>
-        {
-          this._main_loop.quit ();
-          assert_not_reached ();
-        });
-
-      this._main_loop.run ();
+      TestUtils.loop_run_with_timeout (this._main_loop);
 
       assert (this._found_changed_full_name);
     }
diff --git a/tests/tracker/set-gender.vala b/tests/tracker/set-gender.vala
index 1272850..ab96b82 100644
--- a/tests/tracker/set-gender.vala
+++ b/tests/tracker/set-gender.vala
@@ -53,13 +53,7 @@ public class SetGenderTests : TrackerTest.TestCase
 
       this._test_set_gender_async.begin ();
 
-      Timeout.add_seconds (5, () =>
-        {
-          this._main_loop.quit ();
-          assert_not_reached ();
-        });
-
-      this._main_loop.run ();
+      TestUtils.loop_run_with_timeout (this._main_loop);
 
       assert (this._gender_found);
     }
diff --git a/tests/tracker/set-im-addresses.vala b/tests/tracker/set-im-addresses.vala
index e18debd..a6e8f9f 100644
--- a/tests/tracker/set-im-addresses.vala
+++ b/tests/tracker/set-im-addresses.vala
@@ -59,13 +59,7 @@ public class SetIMAddressesTests : TrackerTest.TestCase
 
       this._test_set_im_addresses_async.begin ();
 
-      Timeout.add_seconds (5, () =>
-        {
-          this._main_loop.quit ();
-          assert_not_reached ();
-        });
-
-      this._main_loop.run ();
+      TestUtils.loop_run_with_timeout (this._main_loop);
 
       assert (this._initial_individual_found);
       assert (this._addresses.length () == 0);
diff --git a/tests/tracker/set-nickname.vala b/tests/tracker/set-nickname.vala
index 18efcb4..e171a54 100644
--- a/tests/tracker/set-nickname.vala
+++ b/tests/tracker/set-nickname.vala
@@ -59,13 +59,7 @@ public class SetNicknameTests : TrackerTest.TestCase
 
       this._test_set_nickname_async.begin ();
 
-      Timeout.add_seconds (5, () =>
-        {
-          this._main_loop.quit ();
-          assert_not_reached ();
-        });
-
-      this._main_loop.run ();
+      TestUtils.loop_run_with_timeout (this._main_loop);
 
       assert (this._initial_nickname_found == true);
       assert (this._modified_nickname_found == true);
diff --git a/tests/tracker/set-notes.vala b/tests/tracker/set-notes.vala
index acc3248..c9b197a 100644
--- a/tests/tracker/set-notes.vala
+++ b/tests/tracker/set-notes.vala
@@ -56,13 +56,7 @@ public class SetNotesTests : TrackerTest.TestCase
 
       this._test_set_notes_async.begin ();
 
-      Timeout.add_seconds (5, () =>
-        {
-          this._main_loop.quit ();
-          assert_not_reached ();
-        });
-
-      this._main_loop.run ();
+      TestUtils.loop_run_with_timeout (this._main_loop);
 
       assert (this._note_found);
     }
diff --git a/tests/tracker/set-null-avatar.vala b/tests/tracker/set-null-avatar.vala
index 5612570..1b02c4b 100644
--- a/tests/tracker/set-null-avatar.vala
+++ b/tests/tracker/set-null-avatar.vala
@@ -52,13 +52,7 @@ public class SetNullAvatarTests : TrackerTest.TestCase
 
       this._test_set_null_avatar_async.begin ();
 
-      Timeout.add_seconds (5, () =>
-        {
-          this._main_loop.quit ();
-          assert_not_reached ();
-        });
-
-      this._main_loop.run ();
+      TestUtils.loop_run_with_timeout (this._main_loop);
 
       assert (this._null_avatar_set);
     }
diff --git a/tests/tracker/set-phones.vala b/tests/tracker/set-phones.vala
index f81ab4b..82b5afe 100644
--- a/tests/tracker/set-phones.vala
+++ b/tests/tracker/set-phones.vala
@@ -58,13 +58,7 @@ public class SetPhonesTests : TrackerTest.TestCase
 
       this._test_set_phones_async.begin ();
 
-      Timeout.add_seconds (5, () =>
-        {
-          this._main_loop.quit ();
-          assert_not_reached ();
-        });
-
-      this._main_loop.run ();
+      TestUtils.loop_run_with_timeout (this._main_loop);
 
       assert (this._phone_1_found);
       assert (this._phone_2_found);
diff --git a/tests/tracker/set-postal-addresses.vala b/tests/tracker/set-postal-addresses.vala
index 6d007da..9fa2be3 100644
--- a/tests/tracker/set-postal-addresses.vala
+++ b/tests/tracker/set-postal-addresses.vala
@@ -65,13 +65,7 @@ public class SetPostalAddressesTests : TrackerTest.TestCase
 
       this._test_set_postal_addresses_async.begin ();
 
-      Timeout.add_seconds (5, () =>
-        {
-          this._main_loop.quit ();
-          assert_not_reached ();
-        });
-
-      this._main_loop.run ();
+      TestUtils.loop_run_with_timeout (this._main_loop);
 
       assert (this._postal_address_found);
     }
diff --git a/tests/tracker/set-roles.vala b/tests/tracker/set-roles.vala
index 6fe73bb..4696c5a 100644
--- a/tests/tracker/set-roles.vala
+++ b/tests/tracker/set-roles.vala
@@ -58,13 +58,7 @@ public class SetRolesTests : TrackerTest.TestCase
 
       this._test_set_roles_async.begin ();
 
-      Timeout.add_seconds (5, () =>
-        {
-          this._main_loop.quit ();
-          assert_not_reached ();
-        });
-
-      this._main_loop.run ();
+      TestUtils.loop_run_with_timeout (this._main_loop);
 
       assert (this._role_found);
     }
diff --git a/tests/tracker/set-structured-name.vala b/tests/tracker/set-structured-name.vala
index 8050270..1f44982 100644
--- a/tests/tracker/set-structured-name.vala
+++ b/tests/tracker/set-structured-name.vala
@@ -67,13 +67,7 @@ public class SetStructuredNameTests : TrackerTest.TestCase
 
       this._test_set_structured_name_async.begin ();
 
-      Timeout.add_seconds (5, () =>
-        {
-          this._main_loop.quit ();
-          assert_not_reached ();
-        });
-
-      this._main_loop.run ();
+      TestUtils.loop_run_with_timeout (this._main_loop);
 
       assert (this._sname_found);
     }
diff --git a/tests/tracker/set-urls.vala b/tests/tracker/set-urls.vala
index 05f7c85..80d7a11 100644
--- a/tests/tracker/set-urls.vala
+++ b/tests/tracker/set-urls.vala
@@ -57,13 +57,7 @@ public class SetURLsTests : TrackerTest.TestCase
 
       this._test_set_urls_async.begin ();
 
-      Timeout.add_seconds (5, () =>
-        {
-          this._main_loop.quit ();
-          assert_not_reached ();
-        });
-
-      this._main_loop.run ();
+      TestUtils.loop_run_with_timeout (this._main_loop);
 
       assert (this._urls.size == 0);
     }
diff --git a/tests/tracker/suffix-name-updates.vala b/tests/tracker/suffix-name-updates.vala
index aa973df..f136914 100644
--- a/tests/tracker/suffix-name-updates.vala
+++ b/tests/tracker/suffix-name-updates.vala
@@ -68,13 +68,7 @@ public class SuffixNameUpdatesTests : TrackerTest.TestCase
 
       this._test_suffix_name_updates_async.begin ();
 
-      Timeout.add_seconds (5, () =>
-        {
-          this._main_loop.quit ();
-          assert_not_reached ();
-        });
-
-      this._main_loop.run ();
+      TestUtils.loop_run_with_timeout (this._main_loop);
 
       assert (this._initial_suffix_name_found == true);
       assert (this._updated_suffix_name_found == true);
diff --git a/tests/tracker/url-details-interface.vala b/tests/tracker/url-details-interface.vala
index a1a2d2e..e3802bc 100644
--- a/tests/tracker/url-details-interface.vala
+++ b/tests/tracker/url-details-interface.vala
@@ -62,13 +62,7 @@ public class UrlDetailsInterfaceTests : TrackerTest.TestCase
 
       this._test_url_details_interface_async.begin ();
 
-      Timeout.add_seconds (5, () =>
-        {
-          this._main_loop.quit ();
-          assert_not_reached ();
-        });
-
-      this._main_loop.run ();
+      TestUtils.loop_run_with_timeout (this._main_loop);
 
       assert (this._found_blog == true);
       assert (this._found_website == true);
diff --git a/tests/tracker/website-updates.vala b/tests/tracker/website-updates.vala
index a053163..9095a5c 100644
--- a/tests/tracker/website-updates.vala
+++ b/tests/tracker/website-updates.vala
@@ -68,13 +68,7 @@ public class WebsiteUpdatesTests : TrackerTest.TestCase
 
       this._test_website_updates_async.begin ();
 
-      Timeout.add_seconds (5, () =>
-        {
-          this._main_loop.quit ();
-          assert_not_reached ();
-        });
-
-      this._main_loop.run ();
+      TestUtils.loop_run_with_timeout (this._main_loop);
 
       assert (this._initial_website_found == true);
       assert (this._updated_website_found == true);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]