From e0c6bda4d776345befdd7b77d6b56b1e67429eb2 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Thu, 8 Aug 2013 17:48:54 +0100 Subject: [PATCH 5/5] Tests: don't assume that other things can sneak in ahead of cancellation The porter test asserted that if you cancelled the sending of a stanza after it had already been (sent and) received, the send reported success, not cancellation; and the SASL auth test asserted that if you closed a connection at around the same time that a cancellable had been cancelled, the close reported success, not cancellation. However, recent GLib seems to be either more careful about deferring the results of async operations to an idle, or more consistent about reporting the cancellation as an error even if the operation's success had already been recorded. As a result, these operations reported cancellation. To avoid that, delay the cancellation a little. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=67900 Signed-off-by: Simon McVittie --- tests/Makefile.am | 2 ++ tests/wocky-porter-test.c | 2 +- tests/wocky-test-helper.c | 16 ++++++++++++++++ tests/wocky-test-helper.h | 2 ++ tests/wocky-test-sasl-auth-server.c | 6 ++---- 5 files changed, 23 insertions(+), 5 deletions(-) diff --git a/tests/Makefile.am b/tests/Makefile.am index c4112cb..43578fa 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -125,6 +125,8 @@ wocky_data_form_test_SOURCES = \ wocky_dummy_xmpp_server_DEPENDENCIES = $(LIBWOCKY) wocky_dummy_xmpp_server_SOURCES = wocky-dummy-xmpp-server.c \ wocky-test-connector-server.c wocky-test-connector-server.h \ + wocky-test-helper.c wocky-test-helper.h \ + wocky-test-stream.c wocky-test-stream.h \ wocky-test-sasl-auth-server.c wocky-test-sasl-auth-server.h wocky_dummy_xmpp_server_LDADD = $(LDADD) @LIBSASL2_LIBS@ wocky_dummy_xmpp_server_CFLAGS = $(AM_CFLAGS) @LIBSASL2_CFLAGS@ $(TLSDEFS) diff --git a/tests/wocky-porter-test.c b/tests/wocky-porter-test.c index abcd5c3..d36bc00 100644 --- a/tests/wocky-porter-test.c +++ b/tests/wocky-porter-test.c @@ -1190,7 +1190,7 @@ test_cancel_sent_stanza_cb (WockyPorter *porter, test_data_t *test = (test_data_t *) user_data; test_expected_stanza_received (test, stanza); - g_cancellable_cancel (test->cancellable); + test_cancel_in_idle (test->cancellable); return TRUE; } diff --git a/tests/wocky-test-helper.c b/tests/wocky-test-helper.c index d2b262e..f7148e5 100644 --- a/tests/wocky-test-helper.c +++ b/tests/wocky-test-helper.c @@ -305,3 +305,19 @@ test_deinit (void) { wocky_deinit (); } + +static gboolean +cancel_in_idle_cb (gpointer cancellable) +{ + g_cancellable_cancel (cancellable); + return FALSE; +} + +void +test_cancel_in_idle (GCancellable *cancellable) +{ + g_idle_add_full (G_PRIORITY_DEFAULT_IDLE, + cancel_in_idle_cb, + g_object_ref (cancellable), + g_object_unref); +} diff --git a/tests/wocky-test-helper.h b/tests/wocky-test-helper.h index 4c9b25c..3810985 100644 --- a/tests/wocky-test-helper.h +++ b/tests/wocky-test-helper.h @@ -45,6 +45,8 @@ void test_expected_stanza_received (test_data_t *test, void test_close_both_porters (test_data_t *test); +void test_cancel_in_idle (GCancellable *cancellable); + #define test_assert_nodes_equal(n1, n2) \ G_STMT_START { \ if (!wocky_node_equal ((n1), (n2))) \ diff --git a/tests/wocky-test-sasl-auth-server.c b/tests/wocky-test-sasl-auth-server.c index b5b4c76..35c8328 100644 --- a/tests/wocky-test-sasl-auth-server.c +++ b/tests/wocky-test-sasl-auth-server.c @@ -30,7 +30,7 @@ #include #include "wocky-test-sasl-auth-server.h" - +#include "wocky-test-helper.h" #ifdef HAVE_LIBSASL2 @@ -988,9 +988,7 @@ test_sasl_auth_server_stop (TestSaslAuthServer *self) if (priv->cancellable != NULL) { - if (!g_cancellable_is_cancelled (priv->cancellable)) - g_cancellable_cancel (priv->cancellable); - + test_cancel_in_idle (priv->cancellable); g_object_unref (priv->cancellable); priv->cancellable = NULL; } -- 1.8.4.rc1