[folks] tests: Eliminate non-fatal timeouts from the EDS tests



commit cce549de95c9faa621b39960ca741cb397cfe7c5
Author: Philip Withnall <philip withnall collabora co uk>
Date:   Tue Jun 16 17:47:42 2015 +0100

    tests: Eliminate non-fatal timeouts from the EDS tests
    
    Consistently use TestUtils.loop_run_with_timeout() instead of
    TestUtils.loop_run_with_non_fatal_timeout(). Fix a number of race
    conditions where (for example) individuals-changed can be emitted as
    part of teardown of the test, while the test’s signal handler is still
    connected to it, resulting in an assertion failure because the handler
    does not expect personas to be removed.
    
    This should also speed the tests up a bit, because they’re no longer
    waiting for a timeout before checking for success. They now quit the
    main loop on success.

 tests/eds/avatar-details.vala       |    5 +++--
 tests/eds/email-details.vala        |    9 +++++++--
 tests/eds/individual-retrieval.vala |    5 +++--
 tests/eds/name-details.vala         |   17 +++++++++--------
 tests/eds/persona-store-tests.vala  |   35 ++++++++++++++++++++++++++++-------
 tests/eds/phone-details.vala        |    6 ++++--
 tests/eds/removing-contacts.vala    |    7 +++++--
 7 files changed, 59 insertions(+), 25 deletions(-)
---
diff --git a/tests/eds/avatar-details.vala b/tests/eds/avatar-details.vala
index 6c67466..d7f341f 100644
--- a/tests/eds/avatar-details.vala
+++ b/tests/eds/avatar-details.vala
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2011 Collabora Ltd.
+ * Copyright (C) 2011, 2015 Collabora Ltd.
  *
  * This library is free software: you can redistribute it and/or modify
  * it under the terms of the GNU Lesser General Public License as published by
@@ -15,6 +15,7 @@
  * along with this library.  If not, see <http://www.gnu.org/licenses/>.
  *
  * Authors: Raul Gutierrez Segales <raul gutierrez segales collabora co uk>
+ *          Philip Withnall <philip withnall collabora co uk>
  *
  */
 
@@ -58,7 +59,7 @@ public class AvatarDetailsTests : EdsTest.TestCase
 
       this._test_avatar_async.begin ();
 
-      TestUtils.loop_run_with_non_fatal_timeout (this._main_loop);
+      TestUtils.loop_run_with_timeout (this._main_loop);
 
       assert (this._avatars_are_equal);
    }
diff --git a/tests/eds/email-details.vala b/tests/eds/email-details.vala
index 99380b2..17618b2 100644
--- a/tests/eds/email-details.vala
+++ b/tests/eds/email-details.vala
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2011 Collabora Ltd.
+ * Copyright (C) 2011, 2015 Collabora Ltd.
  *
  * This library is free software: you can redistribute it and/or modify
  * it under the terms of the GNU Lesser General Public License as published by
@@ -15,6 +15,7 @@
  * along with this library.  If not, see <http://www.gnu.org/licenses/>.
  *
  * Authors: Raul Gutierrez Segales <raul gutierrez segales collabora co uk>
+ *          Philip Withnall <philip withnall collabora co uk>
  *
  */
 
@@ -86,7 +87,7 @@ public class EmailDetailsTests : EdsTest.TestCase
 
       this._test_email_details_async.begin ();
 
-      TestUtils.loop_run_with_non_fatal_timeout (this._main_loop, 5);
+      TestUtils.loop_run_with_timeout (this._main_loop);
 
       assert (this._email_count == 6);
       assert (this._email_types.size == 1);
@@ -172,6 +173,10 @@ public class EmailDetailsTests : EdsTest.TestCase
                   this._email_types.add (v);
                 }
             }
+
+          /* Finished? */
+          if (this._email_count == 6)
+              this._main_loop.quit ();
         }
 
       assert (removed.size == 1);
diff --git a/tests/eds/individual-retrieval.vala b/tests/eds/individual-retrieval.vala
index b3ea06d..aed7385 100644
--- a/tests/eds/individual-retrieval.vala
+++ b/tests/eds/individual-retrieval.vala
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2011 Collabora Ltd.
+ * Copyright (C) 2011, 2015 Collabora Ltd.
  *
  * This library is free software: you can redistribute it and/or modify
  * it under the terms of the GNU Lesser General Public License as published by
@@ -15,6 +15,7 @@
  * along with this library.  If not, see <http://www.gnu.org/licenses/>.
  *
  * Authors: Raul Gutierrez Segales <raul gutierrez segales collabora co uk>
+ *          Philip Withnall <philip withnall collabora co uk>
  *
  */
 
@@ -63,7 +64,7 @@ public class IndividualRetrievalTests : EdsTest.TestCase
 
       this._test_singleton_individuals_async.begin ();
 
-      TestUtils.loop_run_with_non_fatal_timeout (this._main_loop, 5);
+      TestUtils.loop_run_with_timeout (this._main_loop);
 
       assert (this._found_individuals.size == 2);
     }
diff --git a/tests/eds/name-details.vala b/tests/eds/name-details.vala
index 31add08..9f5cc28 100644
--- a/tests/eds/name-details.vala
+++ b/tests/eds/name-details.vala
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2011 Collabora Ltd.
+ * Copyright (C) 2011, 2015 Collabora Ltd.
  *
  * This library is free software: you can redistribute it and/or modify
  * it under the terms of the GNU Lesser General Public License as published by
@@ -15,6 +15,7 @@
  * along with this library.  If not, see <http://www.gnu.org/licenses/>.
  *
  * Authors: Raul Gutierrez Segales <raul gutierrez segales collabora co uk>
+ *          Philip Withnall <philip withnall collabora co uk>
  *
  */
 
@@ -84,7 +85,7 @@ public class NameDetailsTests : EdsTest.TestCase
 
       this._test_names_async.begin ();
 
-      TestUtils.loop_run_with_non_fatal_timeout (this._main_loop, 5);
+      TestUtils.loop_run_with_timeout (this._main_loop);
 
       assert (this._names_count == 2);
       assert (this._c1.size == 0);
@@ -179,18 +180,18 @@ public class NameDetailsTests : EdsTest.TestCase
           this._names_count++;
         }
 
+      /* Finished? */
+      if (this._names_count == 2)
+        {
+          this._main_loop.quit ();
+        }
+
       assert (removed.size == 1);
 
       foreach (var i in removed)
         {
           assert (i == null);
         }
-
-        if (this._c1.size == 0 &&
-            this._c2.size == 0)
-          {
-            this._main_loop.quit ();
-          }
     }
 }
 
diff --git a/tests/eds/persona-store-tests.vala b/tests/eds/persona-store-tests.vala
index 2714ea5..ba2f543 100644
--- a/tests/eds/persona-store-tests.vala
+++ b/tests/eds/persona-store-tests.vala
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2011 Collabora Ltd.
+ * Copyright (C) 2011, 2015 Collabora Ltd.
  *
  * This library is free software: you can redistribute it and/or modify
  * it under the terms of the GNU Lesser General Public License as published by
@@ -15,6 +15,7 @@
  * along with this library.  If not, see <http://www.gnu.org/licenses/>.
  *
  * Authors: Raul Gutierrez Segales <raul gutierrez segales collabora co uk>
+ *          Philip Withnall <philip withnall collabora co uk>
  *
  */
 
@@ -25,6 +26,8 @@ using Gee;
 public class PersonaStoreTests : EdsTest.TestCase
 {
   private HashSet<string>? _capabilities_received = null;
+  private MainLoop? _main_loop = null;
+  private uint _callbacks_received = 0;
 
   public PersonaStoreTests ()
     {
@@ -48,7 +51,7 @@ public class PersonaStoreTests : EdsTest.TestCase
     {
       Gee.HashMap<string, Value?> c1 = new Gee.HashMap<string, Value?> ();
       Gee.HashMap<string, Value?> c2 = new Gee.HashMap<string, Value?> ();
-      var main_loop = new GLib.MainLoop (null, false);
+      this._main_loop = new GLib.MainLoop (null, false);
       Value? v;
 
       this.eds_backend.reset ();
@@ -69,6 +72,8 @@ public class PersonaStoreTests : EdsTest.TestCase
       c2.set (Edsf.Persona.email_fields[0], (owned) v);
       this.eds_backend.add_contact (c2);
 
+      this._callbacks_received = 0;
+
       var backend_store = BackendStore.dup ();
       backend_store.prepare.begin ((o, r) =>
         {
@@ -93,7 +98,7 @@ public class PersonaStoreTests : EdsTest.TestCase
 
       backend_store.load_backends.begin ();
 
-      TestUtils.loop_run_with_non_fatal_timeout (main_loop);
+      TestUtils.loop_run_with_timeout (this._main_loop);
 
       assert (this._capabilities_received.contains ("can-add-personas"));
       assert (this._capabilities_received.contains ("can-remove-personas"));
@@ -123,11 +128,11 @@ public class PersonaStoreTests : EdsTest.TestCase
                 store.notify["can-remove-personas"].connect (
                     this._can_remove_personas_cb);
 
-              if ("alias" in store.always_writeable_properties)
-                this._check_can_alias_personas (store, null);
+              this._check_can_alias_personas (store, null);
+              this._check_can_group_personas (store, null);
 
-              if ("groups" in store.always_writeable_properties)
-                this._check_can_group_personas (store, null);
+              if (this._callbacks_received == 4)
+                this._main_loop.quit ();
             }
           catch (GLib.Error e)
             {
@@ -141,6 +146,7 @@ public class PersonaStoreTests : EdsTest.TestCase
     {
       assert (s is Edsf.PersonaStore);
       var store = (Edsf.PersonaStore) s;
+      this._callbacks_received++;
 
       if (store.can_add_personas != MaybeBool.UNSET)
         {
@@ -151,12 +157,16 @@ public class PersonaStoreTests : EdsTest.TestCase
           store.notify["can-add-personas"].disconnect (
               this._can_add_personas_cb);
         }
+
+      if (this._callbacks_received == 4)
+        this._main_loop.quit ();
     }
 
   private void _can_remove_personas_cb (GLib.Object s, ParamSpec? p)
     {
       assert (s is Edsf.PersonaStore);
       var store = (Edsf.PersonaStore) s;
+      this._callbacks_received++;
 
       if (store.can_remove_personas != MaybeBool.UNSET)
         {
@@ -167,28 +177,39 @@ public class PersonaStoreTests : EdsTest.TestCase
           store.notify["can-remove-personas"].disconnect (
               this._can_remove_personas_cb);
         }
+
+      if (this._callbacks_received == 4)
+        this._main_loop.quit ();
     }
 
   private void _check_can_alias_personas (GLib.Object s, ParamSpec? p)
     {
       assert (s is Edsf.PersonaStore);
       var store = (Edsf.PersonaStore) s;
+      this._callbacks_received++;
 
       if ("alias" in store.always_writeable_properties)
         {
           this._capabilities_received.add ("can-alias-personas");
         }
+
+      if (this._callbacks_received == 4)
+        this._main_loop.quit ();
     }
 
   private void _check_can_group_personas (GLib.Object s, ParamSpec? p)
     {
       assert (s is Edsf.PersonaStore);
       var store = (Edsf.PersonaStore) s;
+      this._callbacks_received++;
 
       if ("groups" in store.always_writeable_properties)
         {
           this._capabilities_received.add ("can-group-personas");
         }
+
+      if (this._callbacks_received == 4)
+        this._main_loop.quit ();
     }
 }
 
diff --git a/tests/eds/phone-details.vala b/tests/eds/phone-details.vala
index 05059da..2611098 100644
--- a/tests/eds/phone-details.vala
+++ b/tests/eds/phone-details.vala
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2011 Collabora Ltd.
+ * Copyright (C) 2011, 2015 Collabora Ltd.
  *
  * This library is free software: you can redistribute it and/or modify
  * it under the terms of the GNU Lesser General Public License as published by
@@ -15,6 +15,7 @@
  * along with this library.  If not, see <http://www.gnu.org/licenses/>.
  *
  * Authors: Raul Gutierrez Segales <raul gutierrez segales collabora co uk>
+ *          Philip Withnall <philip withnall collabora co uk>
  *
  */
 
@@ -79,7 +80,7 @@ public class PhoneDetailsTests : EdsTest.TestCase
 
       this._test_phone_numbers_async.begin ();
 
-      TestUtils.loop_run_with_non_fatal_timeout (this._main_loop, 5);
+      TestUtils.loop_run_with_timeout (this._main_loop);
 
       assert (this._phones_count == 6);
       assert (this._phone_types.size == 3);
@@ -174,6 +175,7 @@ public class PhoneDetailsTests : EdsTest.TestCase
             }
         }
 
+        /* Finished? */
         if (this._phones_count == 6)
           {
             this._main_loop.quit ();
diff --git a/tests/eds/removing-contacts.vala b/tests/eds/removing-contacts.vala
index 7c70cdf..230025d 100644
--- a/tests/eds/removing-contacts.vala
+++ b/tests/eds/removing-contacts.vala
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2011 Collabora Ltd.
+ * Copyright (C) 2011, 2015 Collabora Ltd.
  *
  * This library is free software: you can redistribute it and/or modify
  * it under the terms of the GNU Lesser General Public License as published by
@@ -15,6 +15,7 @@
  * along with this library.  If not, see <http://www.gnu.org/licenses/>.
  *
  * Authors: Raul Gutierrez Segales <raul gutierrez segales collabora co uk>
+ *          Philip Withnall <philip withnall collabora co uk>
  *
  */
 
@@ -54,7 +55,7 @@ public class RemovingContactsTests : EdsTest.TestCase
 
       this._test_removal_async.begin ();
 
-      TestUtils.loop_run_with_non_fatal_timeout (this._main_loop, 5);
+      TestUtils.loop_run_with_timeout (this._main_loop);
 
       assert (this._added == true);
       assert (this._removed == true);
@@ -108,6 +109,8 @@ public class RemovingContactsTests : EdsTest.TestCase
           var name = (Folks.NameDetails) i;
           assert (name.full_name == "bernie h. innocenti");
           this._removed = true;
+
+          /* Finished. */
           this._main_loop.quit ();
         }
     }


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