[evolution-data-server/treitter-client-gdbus] Add tests to stress-test the calendar factory.



commit d0fc2bd9c6ac9fc2407b4deedfe2698958802734
Author: Travis Reitter <treitter gmail com>
Date:   Mon Dec 28 16:40:05 2009 -0800

    Add tests to stress-test the calendar factory.

 calendar/tests/ecal/Makefile.am                    |   12 ++++
 calendar/tests/ecal/ecal-test-utils.c              |   27 ++++++---
 calendar/tests/ecal/ecal-test-utils.h              |    5 ++
 .../tests/ecal/test-ecal-stress-factory--fifo.c    |   34 ++++++++++
 .../ecal/test-ecal-stress-factory--open-async.c    |   65 ++++++++++++++++++++
 .../tests/ecal/test-ecal-stress-factory--serial.c  |   31 +++++++++
 .../ecal/test-ecal-stress-factory--single-cal.c    |   36 +++++++++++
 7 files changed, 201 insertions(+), 9 deletions(-)
---
diff --git a/calendar/tests/ecal/Makefile.am b/calendar/tests/ecal/Makefile.am
index 34d7b67..eeae03a 100644
--- a/calendar/tests/ecal/Makefile.am
+++ b/calendar/tests/ecal/Makefile.am
@@ -53,6 +53,10 @@ TESTS = \
         test-ecal-send-objects			\
         test-ecal-receive-objects		\
         test-ecal-get-query			\
+        test-ecal-stress-factory--serial	\
+        test-ecal-stress-factory--fifo		\
+        test-ecal-stress-factory--single-cal	\
+        test-ecal-stress-factory--open-async	\
         $(NULL)
 
 # The test program
@@ -105,6 +109,14 @@ test_ecal_set_default_timezone_LDADD=$(TEST_ECAL_LIBS)
 test_ecal_set_default_timezone_CPPFLAGS=$(TEST_ECAL_CPPFLAGS)
 test_ecal_set_mode_LDADD=$(TEST_ECAL_LIBS)
 test_ecal_set_mode_CPPFLAGS=$(TEST_ECAL_CPPFLAGS)
+test_ecal_stress_factory__fifo_LDADD=$(TEST_ECAL_LIBS)
+test_ecal_stress_factory__fifo_CPPFLAGS=$(TEST_ECAL_CPPFLAGS)
+test_ecal_stress_factory__open_async_LDADD=$(TEST_ECAL_LIBS)
+test_ecal_stress_factory__open_async_CPPFLAGS=$(TEST_ECAL_CPPFLAGS)
+test_ecal_stress_factory__serial_LDADD=$(TEST_ECAL_LIBS)
+test_ecal_stress_factory__serial_CPPFLAGS=$(TEST_ECAL_CPPFLAGS)
+test_ecal_stress_factory__single_cal_LDADD=$(TEST_ECAL_LIBS)
+test_ecal_stress_factory__single_cal_CPPFLAGS=$(TEST_ECAL_CPPFLAGS)
 
 # monolithic tests
 test_ecal_SOURCES = test-ecal.c
diff --git a/calendar/tests/ecal/ecal-test-utils.c b/calendar/tests/ecal/ecal-test-utils.c
index 2195db6..6aaed34 100644
--- a/calendar/tests/ecal/ecal-test-utils.c
+++ b/calendar/tests/ecal/ecal-test-utils.c
@@ -51,6 +51,20 @@ test_print (const char *format,
 }
 
 ECal*
+ecal_test_utils_cal_new_from_uri (const char     *uri,
+				  ECalSourceType  type)
+{
+        ECal *cal;
+
+        test_print ("loading calendar '%s'\n", uri);
+        cal = e_cal_new_from_uri (uri, type);
+        if (!cal)
+                g_error ("failed to create calendar: `%s'", uri);
+
+        return cal;
+}
+
+ECal*
 ecal_test_utils_cal_new_temp (char           **uri,
                               ECalSourceType   type)
 {
@@ -65,19 +79,12 @@ ecal_test_utils_cal_new_temp (char           **uri,
 
         uri_result = g_filename_to_uri (file_template, NULL, &error);
         if (!uri_result) {
-                g_warning ("failed to convert %s to an URI: %s", file_template,
+                g_error ("failed to convert %s to an URI: %s", file_template,
                                 error->message);
-                exit (1);
         }
         g_free (file_template);
 
-        /* create a temp calendar in /tmp */
-        test_print ("loading calendar\n");
-        cal = e_cal_new_from_uri (uri_result, type);
-        if (!cal) {
-                g_warning ("failed to create calendar: `%s'", *uri);
-                exit(1);
-        }
+	cal = ecal_test_utils_cal_new_from_uri (uri_result, type);
 
         if (uri)
                 *uri = g_strdup (uri_result);
@@ -119,6 +126,8 @@ open_cb (ECal            *cal,
                 exit (1);
         }
 
+	closure->cal = cal;
+
         test_print ("successfully asynchronously removed the temporary "
                         "calendar\n");
         if (closure)
diff --git a/calendar/tests/ecal/ecal-test-utils.h b/calendar/tests/ecal/ecal-test-utils.h
index 3a0d77b..4d16a0a 100644
--- a/calendar/tests/ecal/ecal-test-utils.h
+++ b/calendar/tests/ecal/ecal-test-utils.h
@@ -29,6 +29,7 @@ typedef struct {
         GSourceFunc  cb;
         gpointer     user_data;
 	CalMode      mode;
+	ECal        *cal;
 } ECalTestClosure;
 
 void
@@ -36,6 +37,10 @@ test_print (const char *format,
             ...);
 
 ECal*
+ecal_test_utils_cal_new_from_uri (const char     *uri,
+				  ECalSourceType  type);
+
+ECal*
 ecal_test_utils_cal_new_temp (char           **uri,
 		              ECalSourceType   type);
 
diff --git a/calendar/tests/ecal/test-ecal-stress-factory--fifo.c b/calendar/tests/ecal/test-ecal-stress-factory--fifo.c
new file mode 100644
index 0000000..27fac7d
--- /dev/null
+++ b/calendar/tests/ecal/test-ecal-stress-factory--fifo.c
@@ -0,0 +1,34 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+#include <stdlib.h>
+#include <libecal/e-cal.h>
+
+#include "ecal-test-utils.h"
+
+#define NUM_CALS 200
+
+gint
+main (gint argc, gchar **argv)
+{
+	char *uri = NULL;
+	ECal *cals[NUM_CALS];
+	gint i;
+
+	g_type_init ();
+
+	/* Create and open many calendars; then remove each of them */
+
+	for (i = 0; i < NUM_CALS; i++) {
+		cals[i] = ecal_test_utils_cal_new_temp (&uri,
+				E_CAL_SOURCE_TYPE_EVENT);
+		ecal_test_utils_cal_open (cals[i], FALSE);
+
+		g_free (uri);
+	}
+
+	for (i = 0; i < NUM_CALS; i++) {
+		ecal_test_utils_cal_remove (cals[i]);
+	}
+
+	return 0;
+}
diff --git a/calendar/tests/ecal/test-ecal-stress-factory--open-async.c b/calendar/tests/ecal/test-ecal-stress-factory--open-async.c
new file mode 100644
index 0000000..b148490
--- /dev/null
+++ b/calendar/tests/ecal/test-ecal-stress-factory--open-async.c
@@ -0,0 +1,65 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+#include <stdlib.h>
+#include <libecal/e-cal.h>
+
+#include "ecal-test-utils.h"
+
+#define OPEN_ASYNC_TIMEOUT 200
+#define NUM_CALS 200
+
+static void open_timeout_cb (gpointer user_data) __attribute__ ((noreturn));
+
+static guint open_timeout_id = 0;
+static ECal *cals[NUM_CALS];
+static gint cals_processed = 0;
+
+static void
+open_complete_cb (ECalTestClosure *closure)
+{
+	g_source_remove (open_timeout_id);
+	ecal_test_utils_cal_remove (closure->cal);
+
+	cals_processed++;
+
+	if (cals_processed == NUM_CALS) {
+		test_print ("asynchronously opened all calendars successfully\n");
+		g_main_loop_quit ((GMainLoop*) closure->user_data);
+	}
+}
+
+static void
+open_timeout_cb (gpointer user_data)
+{
+	g_error ("failed to get a response for the async 'open' within a "
+			"reasonable time frame");
+}
+
+gint
+main (gint argc, gchar **argv)
+{
+	char *uri = NULL;
+	GMainLoop *loop;
+	gint i;
+
+	g_type_init ();
+
+	open_timeout_id = g_timeout_add_seconds (OPEN_ASYNC_TIMEOUT,
+			(GSourceFunc) open_timeout_cb, NULL);
+
+	loop = g_main_loop_new (NULL, TRUE);
+
+        /* open and close many calendars in parallel */
+        for (i = 0; i < NUM_CALS; i++) {
+                cals[i] = ecal_test_utils_cal_new_temp (&uri,
+                                E_CAL_SOURCE_TYPE_EVENT);
+		ecal_test_utils_cal_async_open (cals[i], FALSE,
+				(GSourceFunc) open_complete_cb, loop);
+
+		g_free (uri);
+        }
+
+	g_main_loop_run (loop);
+
+	return 0;
+}
diff --git a/calendar/tests/ecal/test-ecal-stress-factory--serial.c b/calendar/tests/ecal/test-ecal-stress-factory--serial.c
new file mode 100644
index 0000000..092e02c
--- /dev/null
+++ b/calendar/tests/ecal/test-ecal-stress-factory--serial.c
@@ -0,0 +1,31 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+#include <stdlib.h>
+#include <libecal/e-cal.h>
+
+#include "ecal-test-utils.h"
+
+#define NUM_CALS 200
+
+gint
+main (gint argc, gchar **argv)
+{
+	char *uri = NULL;
+	gint i;
+
+	g_type_init ();
+
+	/* Serially create, open, (close), and remove many calendars */
+	for (i = 0; i < NUM_CALS; i++) {
+		ECal *cal;
+
+		cal = ecal_test_utils_cal_new_temp (&uri,
+				E_CAL_SOURCE_TYPE_EVENT);
+		ecal_test_utils_cal_open (cal, FALSE);
+		ecal_test_utils_cal_remove (cal);
+
+		g_free (uri);
+	}
+
+	return 0;
+}
diff --git a/calendar/tests/ecal/test-ecal-stress-factory--single-cal.c b/calendar/tests/ecal/test-ecal-stress-factory--single-cal.c
new file mode 100644
index 0000000..3abe97b
--- /dev/null
+++ b/calendar/tests/ecal/test-ecal-stress-factory--single-cal.c
@@ -0,0 +1,36 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+#include <stdlib.h>
+#include <libecal/e-cal.h>
+
+#include "ecal-test-utils.h"
+
+#define NUM_OPENS 200
+
+gint
+main (gint argc, gchar **argv)
+{
+	char *uri = NULL;
+	ECal *cal;
+	gint i;
+
+	g_type_init ();
+
+	cal = ecal_test_utils_cal_new_temp (&uri, E_CAL_SOURCE_TYPE_EVENT);
+	g_object_unref (cal);
+
+	/* open and close the same calendar repeatedly */
+	for (i = 0; i < NUM_OPENS-1; i++) {
+		cal = ecal_test_utils_cal_new_from_uri (uri,
+				E_CAL_SOURCE_TYPE_EVENT);
+		ecal_test_utils_cal_open (cal, FALSE);
+		g_object_unref (cal);
+	}
+
+	cal = ecal_test_utils_cal_new_from_uri (uri, E_CAL_SOURCE_TYPE_EVENT);
+	ecal_test_utils_cal_remove (cal);
+
+	g_free (uri);
+
+	return 0;
+}



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