summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Withnall <philip.withnall@collabora.co.uk>2015-06-16 17:47:42 +0100
committerPhilip Withnall <philip.withnall@collabora.co.uk>2015-06-16 17:47:42 +0100
commitcce549de95c9faa621b39960ca741cb397cfe7c5 (patch)
treebbb6e3b198d473a1657e02fec2cf8dc60207e95b
parent1c6f6fd2ffdb08b3d64179bd65d1d9379cf71f2d (diff)
downloadfolks-cce549de95c9faa621b39960ca741cb397cfe7c5.tar.gz
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.
-rw-r--r--tests/eds/avatar-details.vala5
-rw-r--r--tests/eds/email-details.vala9
-rw-r--r--tests/eds/individual-retrieval.vala5
-rw-r--r--tests/eds/name-details.vala17
-rw-r--r--tests/eds/persona-store-tests.vala35
-rw-r--r--tests/eds/phone-details.vala6
-rw-r--r--tests/eds/removing-contacts.vala7
7 files changed, 59 insertions, 25 deletions
diff --git a/tests/eds/avatar-details.vala b/tests/eds/avatar-details.vala
index 6c674669..d7f341f3 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 99380b2f..17618b2d 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 b3ea06d3..aed73857 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 31add088..9f5cc282 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 2714ea56..ba2f543d 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 05059daf..26110984 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 7c70cdfd..230025d7 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 ();
}
}