[evolution-data-server/openismus-work-master] Make ETestServerFixture more reliable.



commit fc1a9f0dd3bf75b6b8b8731c88e8470d434e1a45
Author: Tristan Van Berkom <tristanvb openismus com>
Date:   Thu Jan 24 19:02:37 2013 +0900

    Make ETestServerFixture more reliable.
    
    Since e_source_registry_commit_source_sync() does not delay execution
    until the source is actually added, use the "source-added" signal instead
    to wait for the source to actually be added.
    
    Also, created loops in the fixture test and run more iterations
    (should help to catch problems with the fixture early, in case
    there are still races).

 tests/test-server-utils/e-test-server-utils.c |   43 +++++----
 tests/test-server-utils/test-fixture.c        |  116 ++++++++++++++-----------
 2 files changed, 89 insertions(+), 70 deletions(-)
---
diff --git a/tests/test-server-utils/e-test-server-utils.c b/tests/test-server-utils/e-test-server-utils.c
index 6cb03c4..a69417f 100644
--- a/tests/test-server-utils/e-test-server-utils.c
+++ b/tests/test-server-utils/e-test-server-utils.c
@@ -83,14 +83,21 @@ delete_work_directory (void)
 static gboolean
 e_test_server_utils_bootstrap_timeout (FixturePair *pair)
 {
-	ESource *source = NULL;
+	g_error ("Timed out while waiting for ESource creation from the registry");
+	return FALSE;
+}
+
+static void
+e_test_server_utils_source_added (ESourceRegistry *registry,
+				  ESource         *source,
+				  FixturePair     *pair)
+{
 	GError  *error = NULL;
 
 	switch (pair->closure->type) {
 	case E_TEST_SERVER_ADDRESS_BOOK:
-		source = e_source_registry_ref_source (pair->fixture->registry, ADDRESS_BOOK_SOURCE_UID);
-		if (!source)
-			g_error ("Unable to fetch newly created addressbook source from the registry");
+		if (g_strcmp0 (e_source_get_uid (source), ADDRESS_BOOK_SOURCE_UID) != 0)
+			return;
 
 		pair->fixture->service.book_client = e_book_client_new (source, &error);
 		if (!pair->fixture->service.book_client)
@@ -102,9 +109,8 @@ e_test_server_utils_bootstrap_timeout (FixturePair *pair)
 		break;
 
 	case E_TEST_SERVER_DEPRECATED_ADDRESS_BOOK:
-		source = e_source_registry_ref_source (pair->fixture->registry, ADDRESS_BOOK_SOURCE_UID);
-		if (!source)
-			g_error ("Unable to fetch newly created addressbook source from the registry");
+		if (g_strcmp0 (e_source_get_uid (source), ADDRESS_BOOK_SOURCE_UID) != 0)
+			return;
 
 		pair->fixture->service.book = e_book_new (source, &error);
 		if (!pair->fixture->service.book)
@@ -116,9 +122,8 @@ e_test_server_utils_bootstrap_timeout (FixturePair *pair)
 		break;
 
 	case E_TEST_SERVER_CALENDAR:
-		source = e_source_registry_ref_source (pair->fixture->registry, CALENDAR_SOURCE_UID);
-		if (!source)
-			g_error ("Unable to fetch newly created addressbook source from the registry");
+		if (g_strcmp0 (e_source_get_uid (source), CALENDAR_SOURCE_UID) != 0)
+			return;
 
 		pair->fixture->service.calendar_client = e_cal_client_new (source,
 			pair->closure->calendar_source_type,
@@ -132,9 +137,8 @@ e_test_server_utils_bootstrap_timeout (FixturePair *pair)
 		break;
 
 	case E_TEST_SERVER_DEPRECATED_CALENDAR:
-		source = e_source_registry_ref_source (pair->fixture->registry, CALENDAR_SOURCE_UID);
-		if (!source)
-			g_error ("Unable to fetch newly created addressbook source from the registry");
+		if (g_strcmp0 (e_source_get_uid (source), CALENDAR_SOURCE_UID) != 0)
+			return;
 
 		pair->fixture->service.calendar = e_cal_new (source, pair->closure->calendar_source_type);
 		if (!pair->fixture->service.calendar)
@@ -146,15 +150,10 @@ e_test_server_utils_bootstrap_timeout (FixturePair *pair)
 		break;
 
 	case E_TEST_SERVER_NONE:
-		break;
+		return;
 	}
 
-	if (source)
-		g_object_unref (source);
-
 	g_main_loop_quit (pair->fixture->loop);
-
-	return FALSE;
 }
 
 static gboolean
@@ -169,6 +168,9 @@ e_test_server_utils_bootstrap_idle (FixturePair *pair)
 	if (!pair->fixture->registry)
 		g_error ("Unable to create the test registry: %s", error->message);
 
+	g_signal_connect (pair->fixture->registry, "source-added",
+			  G_CALLBACK (e_test_server_utils_source_added), pair);
+
 	/* Create an address book */
 	switch (pair->closure->type) {
 	case E_TEST_SERVER_ADDRESS_BOOK:
@@ -211,7 +213,7 @@ e_test_server_utils_bootstrap_idle (FixturePair *pair)
 	}
 
 	if (pair->closure->type != E_TEST_SERVER_NONE)
-		g_timeout_add (20, (GSourceFunc) e_test_server_utils_bootstrap_timeout, pair);
+		g_timeout_add (20 * 1000, (GSourceFunc) e_test_server_utils_bootstrap_timeout, pair);
 	else
 		g_main_loop_quit (pair->fixture->loop);
 
@@ -252,6 +254,7 @@ e_test_server_utils_setup (ETestServerFixture *fixture,
 
 	g_idle_add ((GSourceFunc) e_test_server_utils_bootstrap_idle, &pair);
 	g_main_loop_run (fixture->loop);
+	g_signal_handlers_disconnect_by_func (fixture->registry, e_test_server_utils_source_added, &pair);
 }
 
 /**
diff --git a/tests/test-server-utils/test-fixture.c b/tests/test-server-utils/test-fixture.c
index 682db0b..33e93a4 100644
--- a/tests/test-server-utils/test-fixture.c
+++ b/tests/test-server-utils/test-fixture.c
@@ -22,6 +22,8 @@
 
 #include "e-test-server-utils.h"
 
+#define N_CYCLES 10
+
 static ETestServerClosure registry_closure = { E_TEST_SERVER_NONE, NULL, 0 };
 static ETestServerClosure book_closure     = { E_TEST_SERVER_ADDRESS_BOOK, NULL, 0 };
 static ETestServerClosure calendar_closure = { E_TEST_SERVER_CALENDAR, NULL, E_CAL_CLIENT_SOURCE_TYPE_EVENTS };
@@ -39,56 +41,70 @@ gint
 main (gint argc,
       gchar *argv[])
 {
+	gchar **registry_keys;
+	gchar **book_keys;
+	gchar **calendar_keys;
+	gchar **deprecated_book_keys;
+	gchar **deprecated_calendar_keys;
+	gint i;
+	gint ret;
+
 #if !GLIB_CHECK_VERSION (2, 35, 1)
-  g_type_init ();
+	g_type_init ();
 #endif
-  g_test_init (&argc, &argv, NULL);
-
-  /* Test that internal implementations can return all kinds of type through its api */
-  g_test_add ("/Fixture/Registry1", ETestServerFixture, &registry_closure,
-	      e_test_server_utils_setup, empty_test, e_test_server_utils_teardown);
-  g_test_add ("/Fixture/Registry2", ETestServerFixture, &registry_closure,
-	      e_test_server_utils_setup, empty_test, e_test_server_utils_teardown);
-  g_test_add ("/Fixture/Registry3", ETestServerFixture, &registry_closure,
-	      e_test_server_utils_setup, empty_test, e_test_server_utils_teardown);
-  g_test_add ("/Fixture/Registry4", ETestServerFixture, &registry_closure,
-	      e_test_server_utils_setup, empty_test, e_test_server_utils_teardown);
-
-  g_test_add ("/Fixture/Book1", ETestServerFixture, &book_closure,
-	      e_test_server_utils_setup, empty_test, e_test_server_utils_teardown);
-  g_test_add ("/Fixture/Book2", ETestServerFixture, &book_closure,
-	      e_test_server_utils_setup, empty_test, e_test_server_utils_teardown);
-  g_test_add ("/Fixture/Book3", ETestServerFixture, &book_closure,
-	      e_test_server_utils_setup, empty_test, e_test_server_utils_teardown);
-  g_test_add ("/Fixture/Book4", ETestServerFixture, &book_closure,
-	      e_test_server_utils_setup, empty_test, e_test_server_utils_teardown);
-
-  g_test_add ("/Fixture/Calendar1", ETestServerFixture, &calendar_closure,
-	      e_test_server_utils_setup, empty_test, e_test_server_utils_teardown);
-  g_test_add ("/Fixture/Calendar2", ETestServerFixture, &calendar_closure,
-	      e_test_server_utils_setup, empty_test, e_test_server_utils_teardown);
-  g_test_add ("/Fixture/Calendar3", ETestServerFixture, &calendar_closure,
-	      e_test_server_utils_setup, empty_test, e_test_server_utils_teardown);
-  g_test_add ("/Fixture/Calendar4", ETestServerFixture, &calendar_closure,
-	      e_test_server_utils_setup, empty_test, e_test_server_utils_teardown);
-
-  g_test_add ("/Fixture/Deprecated/Book1", ETestServerFixture, &deprecated_book_closure,
-	      e_test_server_utils_setup, empty_test, e_test_server_utils_teardown);
-  g_test_add ("/Fixture/Deprecated/Book2", ETestServerFixture, &deprecated_book_closure,
-	      e_test_server_utils_setup, empty_test, e_test_server_utils_teardown);
-  g_test_add ("/Fixture/Deprecated/Book3", ETestServerFixture, &deprecated_book_closure,
-	      e_test_server_utils_setup, empty_test, e_test_server_utils_teardown);
-  g_test_add ("/Fixture/Deprecated/Book4", ETestServerFixture, &deprecated_book_closure,
-	      e_test_server_utils_setup, empty_test, e_test_server_utils_teardown);
-
-  g_test_add ("/Fixture/Deprecated/Calendar1", ETestServerFixture, &deprecated_calendar_closure,
-	      e_test_server_utils_setup, empty_test, e_test_server_utils_teardown);
-  g_test_add ("/Fixture/Deprecated/Calendar2", ETestServerFixture, &deprecated_calendar_closure,
-	      e_test_server_utils_setup, empty_test, e_test_server_utils_teardown);
-  g_test_add ("/Fixture/Deprecated/Calendar3", ETestServerFixture, &deprecated_calendar_closure,
-	      e_test_server_utils_setup, empty_test, e_test_server_utils_teardown);
-  g_test_add ("/Fixture/Deprecated/Calendar4", ETestServerFixture, &deprecated_calendar_closure,
-	      e_test_server_utils_setup, empty_test, e_test_server_utils_teardown);
-
-  return e_test_server_utils_run ();
+	g_test_init (&argc, &argv, NULL);
+
+	registry_keys = g_new0 (gchar *, N_CYCLES);
+	book_keys = g_new0 (gchar *, N_CYCLES);
+	calendar_keys = g_new0 (gchar *, N_CYCLES);
+	deprecated_book_keys = g_new0 (gchar *, N_CYCLES);
+	deprecated_calendar_keys = g_new0 (gchar *, N_CYCLES);
+
+	for (i = 0; i < N_CYCLES; i++) {
+		registry_keys[i] = g_strdup_printf ("/Fixture/Registry%d", i);
+		g_test_add (registry_keys[i], ETestServerFixture, &registry_closure,
+			    e_test_server_utils_setup, empty_test, e_test_server_utils_teardown);
+	}
+
+	for (i = 0; i < N_CYCLES; i++) {
+		book_keys[i] = g_strdup_printf ("/Fixture/Book%d", i);
+		g_test_add (book_keys[i], ETestServerFixture, &book_closure,
+			    e_test_server_utils_setup, empty_test, e_test_server_utils_teardown);
+	}
+
+	for (i = 0; i < N_CYCLES; i++) {
+		calendar_keys[i] = g_strdup_printf ("/Fixture/Calendar%d", i);
+		g_test_add (calendar_keys[i], ETestServerFixture, &calendar_closure,
+			    e_test_server_utils_setup, empty_test, e_test_server_utils_teardown);
+	}
+
+	for (i = 0; i < N_CYCLES; i++) {
+		deprecated_book_keys[i] = g_strdup_printf ("/Fixture/Deprecated/Book%d", i);
+		g_test_add (deprecated_book_keys[i], ETestServerFixture, &deprecated_book_closure,
+			    e_test_server_utils_setup, empty_test, e_test_server_utils_teardown);
+	}
+
+	for (i = 0; i < N_CYCLES; i++) {
+		deprecated_calendar_keys[i] = g_strdup_printf ("/Fixture/Deprecated/Calendar%d", i);
+		g_test_add (deprecated_calendar_keys[i], ETestServerFixture, &deprecated_calendar_closure,
+			    e_test_server_utils_setup, empty_test, e_test_server_utils_teardown);
+	}
+
+	ret = e_test_server_utils_run ();
+
+	for (i = 0; i < N_CYCLES; i++) {
+		g_free (registry_keys[i]);
+		g_free (book_keys[i]);
+		g_free (calendar_keys[i]);
+		g_free (deprecated_book_keys[i]);
+		g_free (deprecated_calendar_keys[i]);
+	}
+
+	g_free (registry_keys);
+	g_free (book_keys);
+	g_free (calendar_keys);
+	g_free (deprecated_book_keys);
+	g_free (deprecated_calendar_keys);
+
+	return ret;
 }



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