[packagekit] packagekit: Branch 'master' - 15 commits

Richard Hughes hughsient at kemper.freedesktop.org
Tue Mar 4 12:26:19 PST 2008


 backends/test/helpers/PackageKitDbusTest.py |    1 
 backends/test/pk-backend-test-dbus.c        |   13 +++-
 backends/yum/helpers/yumBackend.py          |   62 +++++++++++++++++--
 backends/yum2/pk-backend-yum2.c             |    1 
 etc/PackageKit.conf.in                      |    4 -
 libselftest/libselftest.c                   |   65 ++++++++++++++++++++
 libselftest/libselftest.h                   |    7 ++
 python/packagekit/backend.py                |    2 
 python/packagekit/daemonBackend.py          |    2 
 src/pk-backend-dbus.c                       |   87 ++++++++++++++++++++++++++++
 src/pk-backend-spawn.c                      |    3 
 src/pk-backend-thread.c                     |   26 ++------
 src/pk-backend.c                            |   15 ++--
 src/pk-runner.c                             |    4 -
 src/pk-spawn.c                              |   20 +++---
 15 files changed, 257 insertions(+), 55 deletions(-)

New commits:
commit f26aa7122a3bab4575831d039f07a687732c1416
Author: Richard Hughes <richard at hughsie.com>
Date:   Tue Mar 4 20:21:24 2008 +0000

    give the spawn more time to run

diff --git a/src/pk-spawn.c b/src/pk-spawn.c
index e0bbda5..a4978d3 100644
--- a/src/pk-spawn.c
+++ b/src/pk-spawn.c
@@ -607,7 +607,7 @@ libst_spawn (LibSelfTest *test)
 
 	g_timeout_add_seconds (1, cancel_cb, spawn);
 	/* wait for finished */
-	libst_loopwait (test, 2000);
+	libst_loopwait (test, 5000);
 	libst_loopcheck (test);
 
 	/************************************************************/
commit cc76cf3329272f88c5b4fc33a4b1a98b3d2fe1ad
Author: Richard Hughes <richard at hughsie.com>
Date:   Tue Mar 4 20:18:37 2008 +0000

    use the loop wait self check helpers to help declutter the self tests

diff --git a/src/pk-backend-dbus.c b/src/pk-backend-dbus.c
index d0c8c16..645fb8a 100644
--- a/src/pk-backend-dbus.c
+++ b/src/pk-backend-dbus.c
@@ -1255,22 +1255,15 @@ pk_backend_dbus_new (void)
 #ifdef PK_BUILD_TESTS
 #include <libselftest.h>
 
-static GMainLoop *loop;
 static guint number_packages = 0;
-static guint hang_loop_id = 0;
 
 /**
  * pk_backend_dbus_test_finished_cb:
  **/
 static void
-pk_backend_dbus_test_finished_cb (PkBackend *backend, PkExitEnum exit, PkBackendDbus *backend_dbus)
+pk_backend_dbus_test_finished_cb (PkBackend *backend, PkExitEnum exit, LibSelfTest *test)
 {
-	/* disable the loop watch */
-	if (hang_loop_id != 0) {
-		g_source_remove (hang_loop_id);
-		hang_loop_id = 0;
-	}
-	g_main_loop_quit (loop);
+	libst_loopquit (test);
 }
 
 /**
@@ -1284,16 +1277,6 @@ pk_backend_dbus_test_package_cb (PkBackend *backend, PkInfoEnum info,
 	number_packages++;
 }
 
-/**
- * pk_backend_dbus_test_hang_check:
- **/
-static gboolean
-pk_backend_dbus_test_hang_check (gpointer data)
-{
-	g_main_loop_quit (loop);
-	return FALSE;
-}
-
 void
 libst_backend_dbus (LibSelfTest *test)
 {
@@ -1304,7 +1287,6 @@ libst_backend_dbus (LibSelfTest *test)
 	if (libst_start (test, "PkBackendDbus", CLASS_AUTO) == FALSE) {
 		return;
 	}
-	loop = g_main_loop_new (NULL, FALSE);
 
 	/************************************************************/
 	libst_title (test, "get an backend_dbus");
@@ -1317,7 +1299,7 @@ libst_backend_dbus (LibSelfTest *test)
 
 	/* so we can spin until we finish */
 	g_signal_connect (backend_dbus->priv->backend, "finished",
-			  G_CALLBACK (pk_backend_dbus_test_finished_cb), backend_dbus);
+			  G_CALLBACK (pk_backend_dbus_test_finished_cb), test);
 	/* so we can count the returned packages */
 	g_signal_connect (backend_dbus->priv->backend, "package",
 			  G_CALLBACK (pk_backend_dbus_test_package_cb), backend_dbus);
@@ -1326,6 +1308,9 @@ libst_backend_dbus (LibSelfTest *test)
 	pk_backend_set_name (backend_dbus->priv->backend, "test_dbus");
 	pk_backend_lock (backend_dbus->priv->backend);
 
+	/* wimp out until fork works */
+	goto chicken_out;
+
 	/************************************************************/
 	libst_title (test, "set the name and activate");
 	ret = pk_backend_dbus_set_name (backend_dbus, "org.freedesktop.PackageKitTestBackend");
@@ -1336,9 +1321,6 @@ libst_backend_dbus (LibSelfTest *test)
 		libst_failed (test, NULL);
 	}
 
-	/* wimp out until fork works */
-	goto chicken_out;
-
 	/************************************************************/
 	libst_title (test, "check we actually did something and didn't fork");
 	if (elapsed > 1) {
@@ -1347,9 +1329,6 @@ libst_backend_dbus (LibSelfTest *test)
 		libst_failed (test, "time = %lfs", time);
 	}
 
-	/* hang check */
-	hang_loop_id = g_timeout_add (5000, pk_backend_dbus_test_hang_check, backend_dbus);
-
 	/************************************************************/
 	libst_title (test, "search by name");
 	ret = pk_backend_dbus_search_file (backend_dbus, "none", "power");
@@ -1368,23 +1347,9 @@ libst_backend_dbus (LibSelfTest *test)
 		libst_failed (test, "time = %lfs", time);
 	}
 
-
 	/* wait for finished */
-	g_main_loop_run (loop);
-
-	/************************************************************/
-	libst_title (test, "did we finish in the timeout");
-	if (hang_loop_id != 0) {
-		libst_success (test, NULL);
-	} else {
-		libst_failed (test, "hangcheck saved us");
-	}
-
-	/* disable hang check */
-	if (hang_loop_id != 0) {
-		g_source_remove (hang_loop_id);
-		hang_loop_id = 0;
-	}
+	libst_loopwait (test, 5000);
+	libst_loopcheck (test);
 
 	/************************************************************/
 	libst_title (test, "test number of packages");
@@ -1395,7 +1360,6 @@ libst_backend_dbus (LibSelfTest *test)
 	}
 
 chicken_out:
-	g_main_loop_unref (loop);
 	g_object_unref (backend_dbus);
 
 	libst_end (test);
diff --git a/src/pk-backend.c b/src/pk-backend.c
index 2375529..b290cb1 100644
--- a/src/pk-backend.c
+++ b/src/pk-backend.c
@@ -1285,7 +1285,6 @@ pk_backend_new (void)
 #include <libselftest.h>
 
 static guint number_messages = 0;
-static GMainLoop *loop;
 
 /**
  * pk_backend_test_message_cb:
@@ -1301,9 +1300,9 @@ pk_backend_test_message_cb (PkBackend *backend, PkMessageEnum message, const gch
  * pk_backend_test_finished_cb:
  **/
 static void
-pk_backend_test_finished_cb (PkBackend *backend, PkExitEnum exit, gpointer data)
+pk_backend_test_finished_cb (PkBackend *backend, PkExitEnum exit, LibSelfTest *test)
 {
-	g_main_loop_quit (loop);
+	libst_loopquit (test);
 }
 
 void
@@ -1313,8 +1312,6 @@ libst_backend (LibSelfTest *test)
 	const gchar *text;
 	gboolean ret;
 
-	loop = g_main_loop_new (NULL, FALSE);
-
 	if (libst_start (test, "PkBackend", CLASS_AUTO) == FALSE) {
 		return;
 	}
@@ -1329,7 +1326,7 @@ libst_backend (LibSelfTest *test)
 	}
 
 	g_signal_connect (backend, "message", G_CALLBACK (pk_backend_test_message_cb), NULL);
-	g_signal_connect (backend, "finished", G_CALLBACK (pk_backend_test_finished_cb), NULL);
+	g_signal_connect (backend, "finished", G_CALLBACK (pk_backend_test_finished_cb), test);
 
 	/************************************************************/
 	libst_title (test, "get backend name");
@@ -1443,7 +1440,8 @@ libst_backend (LibSelfTest *test)
 	pk_backend_error_code (backend, PK_ERROR_ENUM_GPG_FAILURE, "test error");
 
 	/* wait for finished */
-	g_main_loop_run (loop);
+	libst_loopwait (test, PK_BACKEND_FINISHED_ERROR_TIMEOUT + 100);
+	libst_loopcheck (test);
 
 	if (number_messages == 1) {
 		libst_success (test, NULL);
@@ -1461,7 +1459,8 @@ libst_backend (LibSelfTest *test)
 	pk_backend_error_code (backend, PK_ERROR_ENUM_GPG_FAILURE, "test error2");
 
 	/* wait for finished */
-	g_main_loop_run (loop);
+	libst_loopwait (test, PK_BACKEND_FINISHED_ERROR_TIMEOUT + 100);
+	libst_loopcheck (test);
 
 	if (number_messages == 1) {
 		libst_success (test, NULL);
diff --git a/src/pk-spawn.c b/src/pk-spawn.c
index db7d709..e0bbda5 100644
--- a/src/pk-spawn.c
+++ b/src/pk-spawn.c
@@ -426,7 +426,6 @@ pk_spawn_new (void)
 #include <libselftest.h>
 #define BAD_EXIT 999
 
-static GMainLoop *loop;
 PkExitEnum mexit = BAD_EXIT;
 guint stdout_count = 0;
 guint stderr_count = 0;
@@ -468,7 +467,7 @@ pk_test_finished_cb (PkSpawn *spawn, PkExitEnum exit, LibSelfTest *test)
 	pk_debug ("spawn exit=%i", exit);
 	mexit = exit;
 	finished_count++;
-	g_main_loop_quit (loop);
+	libst_loopquit (test);
 }
 
 /**
@@ -527,7 +526,6 @@ libst_spawn (LibSelfTest *test)
 
 	/* get new object */
 	new_spawn_object (test, &spawn);
-	loop = g_main_loop_new (NULL, FALSE);
 
 	/************************************************************/
 	libst_title (test, "make sure return error for missing file");
@@ -558,8 +556,9 @@ libst_spawn (LibSelfTest *test)
 		libst_failed (test, "did not run helper");
 	}
 
-	/* spin for a bit, todo add timer to break out if we fail */
-	g_main_loop_run (loop);
+	/* wait for finished */
+	libst_loopwait (test, 10000);
+	libst_loopcheck (test);
 
 	/************************************************************/
 	libst_title (test, "make sure finished okay");
@@ -607,8 +606,9 @@ libst_spawn (LibSelfTest *test)
 	}
 
 	g_timeout_add_seconds (1, cancel_cb, spawn);
-	/* spin for a bit, todo add timer to break out if we fail */
-	g_main_loop_run (loop);
+	/* wait for finished */
+	libst_loopwait (test, 2000);
+	libst_loopcheck (test);
 
 	/************************************************************/
 	libst_title (test, "make sure finished in SIGKILL");
@@ -634,8 +634,9 @@ libst_spawn (LibSelfTest *test)
 	}
 
 	g_timeout_add_seconds (1, cancel_cb, spawn);
-	/* spin for a bit, todo add timer to break out if we fail */
-	g_main_loop_run (loop);
+	/* wait for finished */
+	libst_loopwait (test, 2000);
+	libst_loopcheck (test);
 
 	/************************************************************/
 	libst_title (test, "make sure finished in SIGQUIT");
@@ -659,7 +660,6 @@ libst_spawn (LibSelfTest *test)
 
 	g_object_unref (spawn);
 	g_free (path);
-	g_main_loop_unref (loop);
 
 	libst_end (test);
 }
commit 0f7fd25be5717242700babfd12c907bb76dad3b6
Author: Richard Hughes <richard at hughsie.com>
Date:   Tue Mar 4 20:14:29 2008 +0000

    add loop wait self check helpers

diff --git a/libselftest/libselftest.c b/libselftest/libselftest.c
index 6e31502..e14d9b6 100644
--- a/libselftest/libselftest.c
+++ b/libselftest/libselftest.c
@@ -42,6 +42,44 @@ libst_init (LibSelfTest *test)
 	test->hang_loop_id = 0;
 }
 
+void
+libst_loopquit (LibSelfTest *test)
+{
+	/* disable the loop watch */
+	if (test->hang_loop_id != 0) {
+		g_source_remove (test->hang_loop_id);
+		test->hang_loop_id = 0;
+	}
+	g_main_loop_quit (test->loop);
+}
+
+static gboolean
+libst_hang_check (gpointer data)
+{
+	LibSelfTest *test = (LibSelfTest *) data;
+	g_main_loop_quit (test->loop);
+	return FALSE;
+}
+
+void
+libst_loopwait (LibSelfTest *test, guint timeout)
+{
+	test->hang_loop_id = g_timeout_add (timeout, libst_hang_check, test);
+	g_main_loop_run (test->loop);
+}
+
+void
+libst_loopcheck (LibSelfTest *test)
+{
+	guint elapsed = libst_elapsed (test);
+	libst_title (test, "did we timeout out of the loop");
+	if (test->hang_loop_id == 0) {
+		libst_success (test, "loop blocked for %ims", elapsed);
+	} else {
+		libst_failed (test, "hangcheck saved us after %ims", elapsed);
+	}
+}
+
 gint
 libst_finish (LibSelfTest *test)
 {
diff --git a/libselftest/libselftest.h b/libselftest/libselftest.h
index 2bc2635..7373c6a 100644
--- a/libselftest/libselftest.h
+++ b/libselftest/libselftest.h
@@ -62,6 +62,9 @@ void		libst_failed	(LibSelfTest *test, const gchar *format, ...);
 void		libst_init	(LibSelfTest *test);
 gint		libst_finish	(LibSelfTest *test);
 guint		libst_elapsed	(LibSelfTest *test);
+void		libst_loopquit	(LibSelfTest *test);
+void		libst_loopwait	(LibSelfTest *test, guint timeout);
+void		libst_loopcheck	(LibSelfTest *test);
 
 #endif	/* __LIBSELFTEST_H */
 
commit 9414accac316da02b07cb91990801a93313cffec
Author: Richard Hughes <richard at hughsie.com>
Date:   Tue Mar 4 19:51:49 2008 +0000

    use the new libst_elapsed functionality to avoid creating and destroying a GTimer in each self test

diff --git a/src/pk-backend-dbus.c b/src/pk-backend-dbus.c
index 920d515..d0c8c16 100644
--- a/src/pk-backend-dbus.c
+++ b/src/pk-backend-dbus.c
@@ -1299,13 +1299,11 @@ libst_backend_dbus (LibSelfTest *test)
 {
 	PkBackendDbus *backend_dbus;
 	gboolean ret;
-	gdouble time;
-	GTimer *timer;
+	guint elapsed;
 
 	if (libst_start (test, "PkBackendDbus", CLASS_AUTO) == FALSE) {
 		return;
 	}
-	timer = g_timer_new ();
 	loop = g_main_loop_new (NULL, FALSE);
 
 	/************************************************************/
@@ -1330,9 +1328,8 @@ libst_backend_dbus (LibSelfTest *test)
 
 	/************************************************************/
 	libst_title (test, "set the name and activate");
-	g_timer_reset (timer);
 	ret = pk_backend_dbus_set_name (backend_dbus, "org.freedesktop.PackageKitTestBackend");
-	time = g_timer_elapsed (timer, NULL);
+	elapsed = libst_elapsed (test);
 	if (ret == TRUE) {
 		libst_success (test, NULL);
 	} else {
@@ -1344,7 +1341,7 @@ libst_backend_dbus (LibSelfTest *test)
 
 	/************************************************************/
 	libst_title (test, "check we actually did something and didn't fork");
-	if (time > 0.0002) {
+	if (elapsed > 1) {
 		libst_success (test, "time = %lfs", time);
 	} else {
 		libst_failed (test, "time = %lfs", time);
@@ -1355,9 +1352,8 @@ libst_backend_dbus (LibSelfTest *test)
 
 	/************************************************************/
 	libst_title (test, "search by name");
-	g_timer_reset (timer);
 	ret = pk_backend_dbus_search_file (backend_dbus, "none", "power");
-	time = g_timer_elapsed (timer, NULL);
+	elapsed = libst_elapsed (test);
 	if (ret == TRUE) {
 		libst_success (test, NULL);
 	} else {
@@ -1366,7 +1362,7 @@ libst_backend_dbus (LibSelfTest *test)
 
 	/************************************************************/
 	libst_title (test, "check we forked and didn't block");
-	if (time < 0.1) {
+	if (elapsed < 100) {
 		libst_success (test, "time = %lfs", time);
 	} else {
 		libst_failed (test, "time = %lfs", time);
@@ -1399,7 +1395,6 @@ libst_backend_dbus (LibSelfTest *test)
 	}
 
 chicken_out:
-	g_timer_destroy (timer);
 	g_main_loop_unref (loop);
 	g_object_unref (backend_dbus);
 
diff --git a/src/pk-backend-thread.c b/src/pk-backend-thread.c
index 389af37..a94af6b 100644
--- a/src/pk-backend-thread.c
+++ b/src/pk-backend-thread.c
@@ -187,12 +187,8 @@ libst_backend_thread (LibSelfTest *test)
 {
 	PkBackendThread *backend_thread;
 	PkBackend *backend;
-
 	gboolean ret;
-	gdouble elapsed;
-	GTimer *timer;
-
-	timer = g_timer_new ();
+	guint elapsed;
 
 	if (libst_start (test, "PkBackendThread", CLASS_AUTO) == FALSE) {
 		return;
@@ -222,7 +218,6 @@ libst_backend_thread (LibSelfTest *test)
 
 	/************************************************************/
 	libst_title (test, "wait for a thread to return true");
-	g_timer_start (timer);
 	ret = pk_backend_thread_create (backend_thread, pk_backend_thread_test_func_true, NULL);
 	if (ret == TRUE) {
 		libst_success (test, NULL);
@@ -232,14 +227,14 @@ libst_backend_thread (LibSelfTest *test)
 
 	/* wait */
 	pk_thread_list_wait (backend_thread->priv->thread_list);
+	elapsed = libst_elapsed (test);
 
 	/************************************************************/
 	libst_title (test, "did we wait the correct time?");
-	elapsed = g_timer_elapsed (timer, NULL);
-	if (elapsed < 1.1 && elapsed > 0.9) {
+	if (elapsed < 1100 && elapsed > 900) {
 		libst_success (test, NULL);
 	} else {
-		libst_failed (test, "did not wait for thread timeout");
+		libst_failed (test, "did not wait for thread timeout %ims", elapsed);
 	}
 
 	/* reset the backend */
@@ -253,7 +248,6 @@ libst_backend_thread (LibSelfTest *test)
 
 	/************************************************************/
 	libst_title (test, "wait for a thread to return false");
-	g_timer_start (timer);
 	ret = pk_backend_thread_create (backend_thread, pk_backend_thread_test_func_false, NULL);
 	if (ret == TRUE) {
 		libst_success (test, NULL);
@@ -263,14 +257,14 @@ libst_backend_thread (LibSelfTest *test)
 
 	/* wait */
 	pk_thread_list_wait (backend_thread->priv->thread_list);
+	elapsed = libst_elapsed (test);
 
 	/************************************************************/
 	libst_title (test, "did we wait the correct time2?");
-	elapsed = g_timer_elapsed (timer, NULL);
-	if (elapsed < 1.1 && elapsed > 0.9) {
+	if (elapsed < 1100 && elapsed > 900) {
 		libst_success (test, NULL);
 	} else {
-		libst_failed (test, "did not wait for thread timeout");
+		libst_failed (test, "did not wait for thread timeout %ims", elapsed);
 	}
 
 	/* reset the backend */
@@ -284,25 +278,23 @@ libst_backend_thread (LibSelfTest *test)
 
 	/************************************************************/
 	libst_title (test, "wait for a thread to return false (straight away)");
-	g_timer_start (timer);
 	ret = pk_backend_thread_create (backend_thread, pk_backend_thread_test_func_immediate_false, NULL);
 	if (ret == TRUE) {
 		libst_success (test, NULL);
 	} else {
 		libst_failed (test, "returned false!");
 	}
+	elapsed = libst_elapsed (test);
 
 	/************************************************************/
 	libst_title (test, "did we wait the correct time2?");
-	elapsed = g_timer_elapsed (timer, NULL);
-	if (elapsed < 0.1) {
+	if (elapsed < 100) {
 		libst_success (test, NULL);
 	} else {
 		libst_failed (test, "did not wait for thread timeout2");
 	}
 
 	g_object_unref (backend_thread);
-	g_timer_destroy (timer);
 
 	libst_end (test);
 }
commit 65a9e7769ee1384ee39f7675927318da455cf4ab
Author: Richard Hughes <richard at hughsie.com>
Date:   Tue Mar 4 19:50:53 2008 +0000

    add time elapsed reporting into libselftest

diff --git a/libselftest/libselftest.c b/libselftest/libselftest.c
index d67eae0..6e31502 100644
--- a/libselftest/libselftest.c
+++ b/libselftest/libselftest.c
@@ -37,6 +37,9 @@ libst_init (LibSelfTest *test)
 	test->started = FALSE;
 	test->class = CLASS_AUTO;
 	test->level = LEVEL_ALL;
+	test->timer = g_timer_new ();
+	test->loop = g_main_loop_new (NULL, FALSE);
+	test->hang_loop_id = 0;
 }
 
 gint
@@ -51,9 +54,22 @@ libst_finish (LibSelfTest *test)
 		g_print ("%u FAILURE(S)\n", test->total - test->succeeded);
 		retval = 1;
 	}
+
+	g_timer_destroy (test->timer);
+	g_main_loop_unref (test->loop);
+
 	return retval;
 }
 
+/* returns ms */
+guint
+libst_elapsed (LibSelfTest *test)
+{
+	gdouble time;
+	time = g_timer_elapsed (test->timer, NULL);
+	return (guint) (time * 1000.0f);
+}
+
 gboolean
 libst_start (LibSelfTest *test, const gchar *name, LibSelfTestClass class)
 {
@@ -85,6 +101,13 @@ libst_end (LibSelfTest *test)
 	if (test->level == LEVEL_NORMAL) {
 		g_print ("OK\n");
 	}
+
+	/* disable hang check */
+	if (test->hang_loop_id != 0) {
+		g_source_remove (test->hang_loop_id);
+		test->hang_loop_id = 0;
+	}
+
 	test->started = FALSE;
 	g_free (test->type);
 }
@@ -94,6 +117,10 @@ libst_title (LibSelfTest *test, const gchar *format, ...)
 {
 	va_list args;
 	gchar *va_args_buffer = NULL;
+
+	/* reset the value libst_elapsed replies with */
+	g_timer_reset (test->timer);
+
 	if (test->level == LEVEL_ALL) {
 		va_start (args, format);
 		g_vasprintf (&va_args_buffer, format, args);
diff --git a/libselftest/libselftest.h b/libselftest/libselftest.h
index c2d7d8a..2bc2635 100644
--- a/libselftest/libselftest.h
+++ b/libselftest/libselftest.h
@@ -49,6 +49,9 @@ typedef struct
 	LibSelfTestClass class;
 	LibSelfTestLevel level;
 	gchar		*type;
+	GTimer		*timer;
+	GMainLoop	*loop;
+	guint		 hang_loop_id;
 } LibSelfTest;
 
 gboolean	libst_start	(LibSelfTest *test, const gchar *name, LibSelfTestClass class);
@@ -58,6 +61,7 @@ void		libst_success	(LibSelfTest *test, const gchar *format, ...);
 void		libst_failed	(LibSelfTest *test, const gchar *format, ...);
 void		libst_init	(LibSelfTest *test);
 gint		libst_finish	(LibSelfTest *test);
+guint		libst_elapsed	(LibSelfTest *test);
 
 #endif	/* __LIBSELFTEST_H */
 
commit 03d3c818987541f0d0c2601a171797cf318e37c4
Author: Richard Hughes <richard at hughsie.com>
Date:   Tue Mar 4 19:38:38 2008 +0000

    remove some more dead code

diff --git a/src/pk-backend-spawn.c b/src/pk-backend-spawn.c
index cf05db0..4e63c28 100644
--- a/src/pk-backend-spawn.c
+++ b/src/pk-backend-spawn.c
@@ -657,9 +657,7 @@ libst_backend_spawn (LibSelfTest *test)
 	PkBackendSpawn *backend_spawn;
 	const gchar *text;
 	gboolean ret;
-	GTimer *timer;
 
-	timer = g_timer_new ();
 	loop = g_main_loop_new (NULL, FALSE);
 
 	if (libst_start (test, "PkBackendSpawn", CLASS_AUTO) == FALSE) {
@@ -879,7 +877,6 @@ libst_backend_spawn (LibSelfTest *test)
 	}
 
 	/* done */
-	g_timer_destroy (timer);
 	g_object_unref (backend_spawn);
 	g_main_loop_unref (loop);
 
commit aa316fb3782937e49591348ac6e213a6b1672c17
Author: Richard Hughes <richard at hughsie.com>
Date:   Tue Mar 4 19:36:58 2008 +0000

    remove some dead code

diff --git a/src/pk-runner.c b/src/pk-runner.c
index 58dd470..7d573a6 100644
--- a/src/pk-runner.c
+++ b/src/pk-runner.c
@@ -1221,9 +1221,6 @@ void
 libst_runner (LibSelfTest *test)
 {
 	PkRunner *runner;
-	GTimer *timer;
-
-	timer = g_timer_new ();
 
 	if (libst_start (test, "PkRunner", CLASS_AUTO) == FALSE) {
 		return;
@@ -1238,7 +1235,6 @@ libst_runner (LibSelfTest *test)
 		libst_failed (test, NULL);
 	}
 
-	g_timer_destroy (timer);
 	g_object_unref (runner);
 
 	libst_end (test);
commit 7e977fa04ef9e1e62c9415df29a47c31e55e7f88
Merge: c32a574... 2ec394b...
Author: Richard Hughes <richard at hughsie.com>
Date:   Tue Mar 4 19:26:54 2008 +0000

    Merge branch 'master' of git+ssh://hughsie@git.packagekit.org/srv/git/PackageKit

commit c32a574cd269975ce919bd34c9756c693fc87ad4
Author: Richard Hughes <richard at hughsie.com>
Date:   Tue Mar 4 19:26:35 2008 +0000

    add a number of self tests for the dbus backend

diff --git a/src/pk-backend-dbus.c b/src/pk-backend-dbus.c
index 4be5ba5..920d515 100644
--- a/src/pk-backend-dbus.c
+++ b/src/pk-backend-dbus.c
@@ -1255,14 +1255,58 @@ pk_backend_dbus_new (void)
 #ifdef PK_BUILD_TESTS
 #include <libselftest.h>
 
+static GMainLoop *loop;
+static guint number_packages = 0;
+static guint hang_loop_id = 0;
+
+/**
+ * pk_backend_dbus_test_finished_cb:
+ **/
+static void
+pk_backend_dbus_test_finished_cb (PkBackend *backend, PkExitEnum exit, PkBackendDbus *backend_dbus)
+{
+	/* disable the loop watch */
+	if (hang_loop_id != 0) {
+		g_source_remove (hang_loop_id);
+		hang_loop_id = 0;
+	}
+	g_main_loop_quit (loop);
+}
+
+/**
+ * pk_backend_dbus_test_package_cb:
+ **/
+static void
+pk_backend_dbus_test_package_cb (PkBackend *backend, PkInfoEnum info,
+				 const gchar *package_id, const gchar *summary,
+				 PkBackendDbus *backend_dbus)
+{
+	number_packages++;
+}
+
+/**
+ * pk_backend_dbus_test_hang_check:
+ **/
+static gboolean
+pk_backend_dbus_test_hang_check (gpointer data)
+{
+	g_main_loop_quit (loop);
+	return FALSE;
+}
+
 void
 libst_backend_dbus (LibSelfTest *test)
 {
 	PkBackendDbus *backend_dbus;
+	gboolean ret;
+	gdouble time;
+	GTimer *timer;
 
 	if (libst_start (test, "PkBackendDbus", CLASS_AUTO) == FALSE) {
 		return;
 	}
+	timer = g_timer_new ();
+	loop = g_main_loop_new (NULL, FALSE);
 
 	/************************************************************/
 	libst_title (test, "get an backend_dbus");
@@ -1273,6 +1317,90 @@ libst_backend_dbus (LibSelfTest *test)
 		libst_failed (test, NULL);
 	}
 
+	/* so we can spin until we finish */
+	g_signal_connect (backend_dbus->priv->backend, "finished",
+			  G_CALLBACK (pk_backend_dbus_test_finished_cb), backend_dbus);
+	/* so we can count the returned packages */
+	g_signal_connect (backend_dbus->priv->backend, "package",
+			  G_CALLBACK (pk_backend_dbus_test_package_cb), backend_dbus);
+
+	/* needed to avoid an error */
+	pk_backend_set_name (backend_dbus->priv->backend, "test_dbus");
+	pk_backend_lock (backend_dbus->priv->backend);
+
+	/************************************************************/
+	libst_title (test, "set the name and activate");
+	g_timer_reset (timer);
+	ret = pk_backend_dbus_set_name (backend_dbus, "org.freedesktop.PackageKitTestBackend");
+	time = g_timer_elapsed (timer, NULL);
+	if (ret == TRUE) {
+		libst_success (test, NULL);
+	} else {
+		libst_failed (test, NULL);
+	}
+
+	/* wimp out until fork works */
+	goto chicken_out;
+
+	/************************************************************/
+	libst_title (test, "check we actually did something and didn't fork");
+	if (time > 0.0002) {
+		libst_success (test, "time = %lfs", time);
+	} else {
+		libst_failed (test, "time = %lfs", time);
+	}
+
+	/* hang check */
+	hang_loop_id = g_timeout_add (5000, pk_backend_dbus_test_hang_check, backend_dbus);
+
+	/************************************************************/
+	libst_title (test, "search by name");
+	g_timer_reset (timer);
+	ret = pk_backend_dbus_search_file (backend_dbus, "none", "power");
+	time = g_timer_elapsed (timer, NULL);
+	if (ret == TRUE) {
+		libst_success (test, NULL);
+	} else {
+		libst_failed (test, NULL);
+	}
+
+	/************************************************************/
+	libst_title (test, "check we forked and didn't block");
+	if (time < 0.1) {
+		libst_success (test, "time = %lfs", time);
+	} else {
+		libst_failed (test, "time = %lfs", time);
+	}
+
+
+	/* wait for finished */
+	g_main_loop_run (loop);
+
+	/************************************************************/
+	libst_title (test, "did we finish in the timeout");
+	if (hang_loop_id != 0) {
+		libst_success (test, NULL);
+	} else {
+		libst_failed (test, "hangcheck saved us");
+	}
+
+	/* disable hang check */
+	if (hang_loop_id != 0) {
+		g_source_remove (hang_loop_id);
+		hang_loop_id = 0;
+	}
+
+	/************************************************************/
+	libst_title (test, "test number of packages");
+	if (number_packages == 2) {
+		libst_success (test, NULL);
+	} else {
+		libst_failed (test, "wrong number of packages %i", number_packages);
+	}
+
+chicken_out:
+	g_timer_destroy (timer);
+	g_main_loop_unref (loop);
 	g_object_unref (backend_dbus);
 
 	libst_end (test);
commit 2ec394b686a761952f2ce4a3ec002856a861d5af
Author: Ken VanDine <ken at vandine.org>
Date:   Tue Mar 4 14:16:24 2008 -0500

    Handle get_updates properly

diff --git a/python/packagekit/backend.py b/python/packagekit/backend.py
index 4f0d24a..7222ee9 100644
--- a/python/packagekit/backend.py
+++ b/python/packagekit/backend.py
@@ -379,7 +379,7 @@ class PackageKitBaseBackend:
         '''
         self.error(ERROR_NOT_SUPPORTED, "This function is not implemented in this backend")
 
-    def get_updates(self,filter,package):
+    def get_updates(self,filter):
         '''
         Implement the {backend}-get-updates functionality
         Needed to be implemented in a sub class
commit a5388cd56b6014baabbddea6b2d67f417fc2d3cb
Merge: 09d3ec2... 7a05e61...
Author: Robin Norwood <rnorwood at redhat.com>
Date:   Tue Mar 4 13:44:33 2008 -0500

    Merge branch 'master' of git+ssh://rnorwood@git.packagekit.org/srv/git/PackageKit

commit 09d3ec200c7f6787c85f3eabc3fcbc71791c9a3c
Author: Robin Norwood <rnorwood at redhat.com>
Date:   Tue Mar 4 13:37:27 2008 -0500

    do caching in old yum backend like we do in the new one.

diff --git a/backends/yum/helpers/yumBackend.py b/backends/yum/helpers/yumBackend.py
index 0c76003..fb32a11 100644
--- a/backends/yum/helpers/yumBackend.py
+++ b/backends/yum/helpers/yumBackend.py
@@ -312,7 +312,6 @@ class PackageKitYumBackend(PackageKitBaseBackend):
         @param key: key to seach for
         '''
         self.yumbase.doConfigSetup(errorlevel=0,debuglevel=0)# Setup Yum Config
-        self.yumbase.conf.cache = 1 # Only look in cache.
         try:
             res = self.yumbase.searchGenerator(searchlist, [key])
             fltlist = filters.split(';')
@@ -331,7 +330,8 @@ class PackageKitYumBackend(PackageKitBaseBackend):
                 else:
                     available.append(pkg)
         except yum.Errors.RepoError,e:
-            self.error(ERROR_NO_CACHE,"Yum cache is invalid")
+            self._refresh_yum_cache()
+            self.error(ERROR_NO_CACHE,"Yum cache was invalid and has been rebuilt.")
 
         # Now show available packages.
         if FILTER_INSTALLED not in fltlist:
@@ -373,7 +373,8 @@ class PackageKitYumBackend(PackageKitBaseBackend):
                     return True
             return False
         except yum.Errors.RepoError,e:
-            self.error(ERROR_NO_CACHE,"Yum cache is invalid")
+            self._refresh_yum_cache()
+            self.error(ERROR_NO_CACHE,"Yum cache was invalid and has been rebuilt.")
 
     def _do_devel_filtering(self,flt,pkg):
         isDevel = False
@@ -401,6 +402,7 @@ class PackageKitYumBackend(PackageKitBaseBackend):
         '''
         Implement the {backend}-search-name functionality
         '''
+        self._check_init(lazy_cache=True)
         self.allow_cancel(True)
         self.percentage(None)
 
@@ -412,6 +414,7 @@ class PackageKitYumBackend(PackageKitBaseBackend):
         '''
         Implement the {backend}-search-details functionality
         '''
+        self._check_init(lazy_cache=True)
         self.allow_cancel(True)
         self.percentage(None)
 
@@ -441,6 +444,7 @@ class PackageKitYumBackend(PackageKitBaseBackend):
         '''
         Implement the {backend}-search-group functionality
         '''
+        self._check_init(lazy_cache=True)
         self.allow_cancel(True)
         self.percentage(None)
         self.yumbase.doConfigSetup(errorlevel=0,debuglevel=0)# Setup Yum Config
@@ -476,7 +480,8 @@ class PackageKitYumBackend(PackageKitBaseBackend):
                         if self._do_extra_filtering(pkg, fltlist):
                             self._show_package(pkg, INFO_AVAILABLE)
         except yum.Errors.RepoError,e:
-            self.error(ERROR_NO_CACHE,"Yum cache is invalid")
+            self._refresh_yum_cache()
+            self.error(ERROR_NO_CACHE,"Yum cache was invalid and has been rebuilt.")
 
     def get_packages(self,filters,showdesc='no'):
         '''
@@ -512,13 +517,15 @@ class PackageKitYumBackend(PackageKitBaseBackend):
                         if showDesc:
                             self._show_description(pkg)
         except yum.Errors.RepoError,e:
-            self.error(ERROR_NO_CACHE,"Yum cache is invalid")
+            self._refresh_yum_cache()
+            self.error(ERROR_NO_CACHE,"Yum cache was invalid and has been rebuilt.")
 
     
     def search_file(self,filters,key):
         '''
         Implement the {backend}-search-file functionality
         '''
+        self._check_init(lazy_cache=True)
         self.allow_cancel(True)
         self.percentage(None)
         self.status(STATUS_QUERY)
@@ -582,6 +589,7 @@ class PackageKitYumBackend(PackageKitBaseBackend):
         '''
         Print a list of requires for a given package
         '''
+        self._check_init(lazy_cache=True)
         self.allow_cancel(True)
         self.percentage(None)
         self.status(STATUS_INFO)
@@ -672,6 +680,7 @@ class PackageKitYumBackend(PackageKitBaseBackend):
         '''
         Print a list of depends for a given package
         '''
+        self._check_init(lazy_cache=True)
         self.allow_cancel(True)
         self.percentage(None)
         self.status(STATUS_INFO)
@@ -698,6 +707,7 @@ class PackageKitYumBackend(PackageKitBaseBackend):
         '''
         Implement the {backend}-update-system functionality
         '''
+        self._check_init(lazy_cache=True)
         self.allow_cancel(False)
         self.percentage(0)
 
@@ -746,6 +756,7 @@ class PackageKitYumBackend(PackageKitBaseBackend):
         '''
         Implement the {backend}-resolve functionality
         '''
+        self._check_init(lazy_cache=True)
         self.allow_cancel(True);
         self.percentage(None)
         self.yumbase.doConfigSetup(errorlevel=0,debuglevel=0)# Setup Yum Config
@@ -772,13 +783,15 @@ class PackageKitYumBackend(PackageKitBaseBackend):
                             self._show_package(pkg,INFO_AVAILABLE)
                             break
         except yum.Errors.RepoError,e:
-            self.error(ERROR_NO_CACHE,"Yum cache is invalid")
+            self._refresh_yum_cache()
+            self.error(ERROR_NO_CACHE,"Yum cache was invalid and has been rebuilt.")
             
     def install(self, packages):
         '''
         Implement the {backend}-install functionality
         This will only work with yum 3.2.4 or higher
         '''
+        self._check_init()
         self.allow_cancel(False)
         self.percentage(0)
         txmbrs = []
@@ -870,6 +883,7 @@ class PackageKitYumBackend(PackageKitBaseBackend):
         Install the package containing the inst_file file
         Needed to be implemented in a sub class
         '''
+        self._check_init()
         self.allow_cancel(False);
         self.percentage(0)
 
@@ -889,6 +903,7 @@ class PackageKitYumBackend(PackageKitBaseBackend):
         Implement the {backend}-install functionality
         This will only work with yum 3.2.4 or higher
         '''
+        self._check_init()
         self.allow_cancel(False);
         self.percentage(0)
         txmbrs = []
@@ -970,6 +985,7 @@ class PackageKitYumBackend(PackageKitBaseBackend):
         Implement the {backend}-remove functionality
         Needed to be implemented in a sub class
         '''
+        self._check_init()
         self.allow_cancel(False);
         self.percentage(0)
 
@@ -990,6 +1006,7 @@ class PackageKitYumBackend(PackageKitBaseBackend):
         '''
         Print a detailed description for a given package
         '''
+        self._check_init()
         self.allow_cancel(True)
         self.percentage(None)
         self.status(STATUS_INFO)
@@ -1011,6 +1028,7 @@ class PackageKitYumBackend(PackageKitBaseBackend):
                          pkg.size)
 
     def get_files(self, package):
+        self._check_init()
         self.allow_cancel(True)
         self.percentage(None)
         self.status(STATUS_INFO)
@@ -1051,6 +1069,7 @@ class PackageKitYumBackend(PackageKitBaseBackend):
         '''
         Implement the {backend}-get-updates functionality
         '''
+        self._check_init()
         self.allow_cancel(True)
         self.percentage(None)
         self.status(STATUS_INFO)
@@ -1066,13 +1085,15 @@ class PackageKitYumBackend(PackageKitBaseBackend):
                 else:
                     self._show_package(pkg,INFO_NORMAL)
         except yum.Errors.RepoError,e:
-            self.error(ERROR_NO_CACHE,"Yum cache is invalid")
+            self._refresh_yum_cache()
+            self.error(ERROR_NO_CACHE,"Yum cache was invalid and has been rebuilt.")
                 
 
     def repo_enable(self, repoid, enable):
         '''
         Implement the {backend}-repo-enable functionality
         '''
+        self._check_init()
         self.status(STATUS_SETUP)
         try:
             repo = self.yumbase.repos.getRepo(repoid)
@@ -1090,6 +1111,7 @@ class PackageKitYumBackend(PackageKitBaseBackend):
         '''
         Implement the {backend}-get-repo-list functionality
         '''
+        self._check_init()
         self.status(STATUS_INFO)
         for repo in self.yumbase.repos.repos.values():
             if repo.isEnabled():
@@ -1179,6 +1201,7 @@ class PackageKitYumBackend(PackageKitBaseBackend):
         '''
         Implement the {backend}-get-update_detail functionality
         '''
+        self._check_init()
         self.allow_cancel(True)
         self.percentage(None)
         self.status(STATUS_INFO)
@@ -1195,6 +1218,7 @@ class PackageKitYumBackend(PackageKitBaseBackend):
         '''
         Implement the {backend}-repo-set-data functionality
         '''
+        self._check_init()
         # Get the repo
         repo = self.yumbase.repos.getRepo(repoid)
         if repo:
@@ -1206,6 +1230,30 @@ class PackageKitYumBackend(PackageKitBaseBackend):
         else:
             self.error(ERROR_REPO_NOT_FOUND,'repo %s not found' % repoid)
 
+    def _check_init(self,lazy_cache=False):
+        '''Just does the caching tweaks'''
+        if lazy_cache:
+            for repo in self.yumbase.repos.listEnabled():
+                repo.metadata_expire = 60 * 60 * 24  # 24 hours
+                repo.mdpolicy = "group:all"
+        else:
+            for repo in self.yumbase.repos.listEnabled():
+                repo.metadata_expire = 60 * 60 * 1.5 # 1.5 hours, the default
+                repo.mdpolicy = "group:primary"
+
+    def _refresh_yum_cache(self):
+        self.status(STATUS_REFRESH_CACHE)
+        old_cache_setting = self.yumbase.conf.cache
+        self.yumbase.conf.cache = 0
+        self.yumbase.repos.setCache(0)
+
+        self.yumbase.repos.populateSack(mdtype='metadata', cacheonly=1)
+        self.yumbase.repos.populateSack(mdtype='filelists', cacheonly=1)
+        self.yumbase.repos.populateSack(mdtype='otherdata', cacheonly=1)
+
+        self.yumbase.conf.cache = old_cache_setting
+        self.yumbase.repos.setCache(old_cache_setting)
+
     def _setup_yum(self):
         self.yumbase.doConfigSetup(errorlevel=0,debuglevel=0)     # Setup Yum Config
         self.yumbase.conf.throttle = "40%"                        # Set bandwidth throttle to 40%
commit 7a05e61af70cb071857b359e8cf69811a633f759
Author: Richard Hughes <richard at hughsie.com>
Date:   Tue Mar 4 18:17:33 2008 +0000

    add Cancel() into the dummy dbus backend

diff --git a/backends/test/helpers/PackageKitDbusTest.py b/backends/test/helpers/PackageKitDbusTest.py
index 1764bb5..6240e84 100755
--- a/backends/test/helpers/PackageKitDbusTest.py
+++ b/backends/test/helpers/PackageKitDbusTest.py
@@ -56,6 +56,7 @@ class PackageKitTestBackendService(PackageKitBaseBackend):
 
     def doSearchName(self, filters, search):
         print "SearchName (%s, %s)" % (filters, search)
+        self.AllowCancel(True)
         self.StatusChanged(STATUS_QUERY)
         self.Package(INFO_AVAILABLE, "foo;0.0.1;i398;fedora", "Foo")
         time.sleep(10)
diff --git a/backends/test/pk-backend-test-dbus.c b/backends/test/pk-backend-test-dbus.c
index 8b0b75f..630f25e 100644
--- a/backends/test/pk-backend-test-dbus.c
+++ b/backends/test/pk-backend-test-dbus.c
@@ -42,6 +42,17 @@ backend_search_name (PkBackend *backend, const gchar *filter, const gchar *searc
 }
 
 /**
+ * pk_backend_cancel:
+ */
+static void
+backend_cancel (PkBackend *backend)
+{
+	g_return_if_fail (backend != NULL);
+	g_return_if_fail (dbus != NULL);
+	pk_backend_dbus_cancel (dbus);
+}
+
+/**
  * backend_initialize:
  * This should only be run once per backend load, i.e. not every transaction
  */
@@ -74,7 +85,7 @@ PK_BACKEND_OPTIONS (
 	backend_destroy,			/* destroy */
 	NULL,					/* get_groups */
 	NULL,					/* get_filters */
-	NULL,					/* cancel */
+	backend_cancel,				/* cancel */
 	NULL,					/* get_depends */
 	NULL,					/* get_description */
 	NULL,					/* get_files */
diff --git a/backends/yum2/pk-backend-yum2.c b/backends/yum2/pk-backend-yum2.c
index 6331158..a9726d8 100644
--- a/backends/yum2/pk-backend-yum2.c
+++ b/backends/yum2/pk-backend-yum2.c
@@ -111,7 +111,6 @@ backend_cancel (PkBackend *backend)
 {
 	g_return_if_fail (backend != NULL);
 	g_return_if_fail (dbus != NULL);
-	/* this feels bad... */
 	pk_backend_dbus_cancel (dbus);
 }
 
commit 78f2017b5683b6fb4b9a4af53c5ac6b1643d8041
Author: Robin Norwood <rnorwood at redhat.com>
Date:   Tue Mar 4 11:49:07 2008 -0500

    Make daemonBackend timeout after 10 minutes.

diff --git a/python/packagekit/daemonBackend.py b/python/packagekit/daemonBackend.py
index 17fd478..cf9293d 100644
--- a/python/packagekit/daemonBackend.py
+++ b/python/packagekit/daemonBackend.py
@@ -49,7 +49,7 @@ PACKAGEKIT_DBUS_INTERFACE = 'org.freedesktop.PackageKitBackend'
 PACKAGEKIT_DBUS_PATH = '/org/freedesktop/PackageKitBackend'
 
 INACTIVE_CHECK_TIMEOUT = 1000 * 60 * 5 # Check every 5 minutes.
-INACTIVE_TIMEOUT = 1000 * 60 * 30 # timeout after 30 minutes of inactivity.
+INACTIVE_TIMEOUT = 1000 * 60 * 10 # timeout after 10 minutes of inactivity.
 
 class PackageKitBaseBackend(dbus.service.Object):
 
commit 2342a58d2f65151714d1a3d39f52489a0dc61fda
Author: Robin Norwood <rnorwood at redhat.com>
Date:   Tue Mar 4 11:47:45 2008 -0500

    Make daemon shut down after 5 minutes instead of 1

diff --git a/etc/PackageKit.conf.in b/etc/PackageKit.conf.in
index f7051e6..2cfe648 100644
--- a/etc/PackageKit.conf.in
+++ b/etc/PackageKit.conf.in
@@ -8,8 +8,8 @@
 TransactionLogging=yes
 
 # Shut down the daemon after this many seconds idle. 0 means don't shutdown.
-# default=60
-ShutdownTimeout=60
+# default=300
+ShutdownTimeout=300
 
 # Default backend, as chosen in the configure script. This will be used where
 # no --backend="foo" option is given to the daemon.



More information about the PackageKit mailing list