From 25d2e71e1ed50413442815be144cf5b306f57ec1 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Mon, 15 Sep 2014 18:56:52 +0100 Subject: [PATCH] dbus-daemon test: don't disconnect before WaitForever call is delivered --- test/dbus-daemon.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/test/dbus-daemon.c b/test/dbus-daemon.c index efff40d..1db4e44 100644 --- a/test/dbus-daemon.c +++ b/test/dbus-daemon.c @@ -57,6 +57,7 @@ typedef struct { DBusConnection *right_conn; gboolean right_conn_echo; + gboolean wait_forever_called; } Fixture; #define assert_no_error(e) _assert_no_error (e, __FILE__, __LINE__) @@ -157,6 +158,7 @@ echo_filter (DBusConnection *connection, DBusMessage *message, void *user_data) { + Fixture *f = user_data; DBusMessage *reply; if (dbus_message_get_type (message) != DBUS_MESSAGE_TYPE_METHOD_CALL) @@ -164,7 +166,10 @@ echo_filter (DBusConnection *connection, /* WaitForever() never replies, emulating a service that has got stuck */ if (dbus_message_is_method_call (message, "com.example", "WaitForever")) - return DBUS_HANDLER_RESULT_HANDLED; + { + f->wait_forever_called = TRUE; + return DBUS_HANDLER_RESULT_HANDLED; + } reply = dbus_message_new_method_return (message); @@ -261,7 +266,7 @@ setup (Fixture *f, static void add_echo_filter (Fixture *f) { - if (!dbus_connection_add_filter (f->right_conn, echo_filter, NULL, NULL)) + if (!dbus_connection_add_filter (f->right_conn, echo_filter, f, NULL)) g_error ("OOM"); f->right_conn_echo = TRUE; @@ -392,7 +397,10 @@ test_no_reply (Fixture *f, if (mode == DISCONNECT) { - dbus_connection_remove_filter (f->right_conn, echo_filter, NULL); + while (!f->wait_forever_called) + test_main_context_iterate (f->ctx, TRUE); + + dbus_connection_remove_filter (f->right_conn, echo_filter, f); dbus_connection_close (f->right_conn); dbus_connection_unref (f->right_conn); f->right_conn = NULL; @@ -550,7 +558,7 @@ teardown (Fixture *f, { if (f->right_conn_echo) { - dbus_connection_remove_filter (f->right_conn, echo_filter, NULL); + dbus_connection_remove_filter (f->right_conn, echo_filter, f); f->right_conn_echo = FALSE; } -- 2.1.0