From 14705ea7895cd988bb4d11eafee691d5d33f3e08 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Thu, 12 Jul 2018 12:51:38 +0100 Subject: [PATCH 14/18] tests: Detach most connections from main loop before closing We don't need to do this for connections that were never set up with the main loop. Signed-off-by: Simon McVittie --- test/containers.c | 1 + test/corrupt.c | 2 ++ test/dbus-daemon-eavesdrop.c | 4 ++++ test/dbus-daemon.c | 8 +++++++- test/fdpass.c | 4 ++++ test/internals/refs.c | 3 +++ test/loopback.c | 10 ++++++++-- test/monitor.c | 6 ++++++ test/sd-activation.c | 3 +++ test/uid-permissions.c | 1 + 10 files changed, 39 insertions(+), 3 deletions(-) diff --git a/test/containers.c b/test/containers.c index eb702522..24540051 100644 --- a/test/containers.c +++ b/test/containers.c @@ -1624,6 +1624,7 @@ teardown (Fixture *f, { dbus_connection_remove_filter (f->libdbus_observer, observe_shouting_cb, f); + test_connection_shutdown (f->ctx, f->libdbus_observer); dbus_connection_close (f->libdbus_observer); } diff --git a/test/corrupt.c b/test/corrupt.c index be5314b4..758084a4 100644 --- a/test/corrupt.c +++ b/test/corrupt.c @@ -275,6 +275,7 @@ test_corrupt (Fixture *f, * fd, whereas DBusLoop + DBusSocketSetEpoll doesn't. On Unix * we could use dup() but that isn't portable to Windows :-( */ + test_connection_shutdown (f->ctx, f->server_conn); dbus_connection_close (f->server_conn); dbus_connection_unref (f->server_conn); f->server_conn = NULL; @@ -362,6 +363,7 @@ test_byte_order (Fixture *f, dbus_message_unref (message); /* Free the DBusConnection before the GSocket, as above. */ + test_connection_shutdown (f->ctx, f->server_conn); dbus_connection_close (f->server_conn); dbus_connection_unref (f->server_conn); f->server_conn = NULL; diff --git a/test/dbus-daemon-eavesdrop.c b/test/dbus-daemon-eavesdrop.c index be21d0ab..6f4d9bb5 100644 --- a/test/dbus-daemon-eavesdrop.c +++ b/test/dbus-daemon-eavesdrop.c @@ -372,6 +372,7 @@ teardown (Fixture *f, if (f->sender != NULL) { + test_connection_shutdown (f->ctx, f->sender); dbus_connection_close (f->sender); dbus_connection_unref (f->sender); f->sender = NULL; @@ -382,6 +383,7 @@ teardown (Fixture *f, dbus_connection_remove_filter (f->receiver, signal_filter, f); + test_connection_shutdown (f->ctx, f->receiver); dbus_connection_close (f->receiver); dbus_connection_unref (f->receiver); f->receiver = NULL; @@ -392,6 +394,7 @@ teardown (Fixture *f, dbus_connection_remove_filter (f->politelistener, signal_filter, f); + test_connection_shutdown (f->ctx, f->politelistener); dbus_connection_close (f->politelistener); dbus_connection_unref (f->politelistener); f->politelistener = NULL; @@ -402,6 +405,7 @@ teardown (Fixture *f, dbus_connection_remove_filter (f->eavesdropper, signal_filter, f); + test_connection_shutdown (f->ctx, f->eavesdropper); dbus_connection_close (f->eavesdropper); dbus_connection_unref (f->eavesdropper); f->eavesdropper = NULL; diff --git a/test/dbus-daemon.c b/test/dbus-daemon.c index 8faef6dd..e18a42ed 100644 --- a/test/dbus-daemon.c +++ b/test/dbus-daemon.c @@ -364,6 +364,7 @@ test_no_reply (Fixture *f, test_main_context_iterate (f->ctx, TRUE); dbus_connection_remove_filter (f->right_conn, echo_filter, f); + test_connection_shutdown (f->ctx, f->right_conn); dbus_connection_close (f->right_conn); dbus_clear_connection (&f->right_conn); } @@ -696,6 +697,7 @@ test_max_connections (Fixture *f, dbus_connection_close (failing_conn); dbus_clear_connection (&failing_conn); + test_connection_shutdown (f->ctx, third_conn); dbus_connection_close (third_conn); dbus_clear_connection (&third_conn); dbus_error_free (&error); @@ -1928,7 +1930,10 @@ teardown (Fixture *f, g_clear_error (&f->ge); if (f->left_conn != NULL) - dbus_connection_close (f->left_conn); + { + test_connection_shutdown (f->ctx, f->left_conn); + dbus_connection_close (f->left_conn); + } if (f->right_conn != NULL) { @@ -1947,6 +1952,7 @@ teardown (Fixture *f, g_queue_foreach (&f->held_messages, (GFunc) dbus_message_unref, NULL); g_queue_clear (&f->held_messages); + test_connection_shutdown (f->ctx, f->right_conn); dbus_connection_close (f->right_conn); } diff --git a/test/fdpass.c b/test/fdpass.c index 1d8ee605..d84b7fe9 100644 --- a/test/fdpass.c +++ b/test/fdpass.c @@ -831,6 +831,7 @@ teardown (Fixture *f, { if (f->left_client_conn != NULL) { + test_connection_shutdown (f->ctx, f->left_client_conn); dbus_connection_close (f->left_client_conn); dbus_connection_unref (f->left_client_conn); f->left_client_conn = NULL; @@ -838,6 +839,7 @@ teardown (Fixture *f, if (f->right_client_conn != NULL) { + test_connection_shutdown (f->ctx, f->right_client_conn); dbus_connection_close (f->right_client_conn); dbus_connection_unref (f->right_client_conn); f->right_client_conn = NULL; @@ -845,6 +847,7 @@ teardown (Fixture *f, if (f->left_server_conn != NULL) { + test_connection_shutdown (f->ctx, f->left_server_conn); dbus_connection_close (f->left_server_conn); dbus_connection_unref (f->left_server_conn); f->left_server_conn = NULL; @@ -852,6 +855,7 @@ teardown (Fixture *f, if (f->right_server_conn != NULL) { + test_connection_shutdown (f->ctx, f->right_server_conn); dbus_connection_close (f->right_server_conn); dbus_connection_unref (f->right_server_conn); f->right_server_conn = NULL; diff --git a/test/internals/refs.c b/test/internals/refs.c index 89f581aa..c0f75128 100644 --- a/test/internals/refs.c +++ b/test/internals/refs.c @@ -341,6 +341,7 @@ test_connection (Fixture *f, /* Destroy the connection. This should be the last-unref. */ g_assert (!f->last_unref); + test_connection_shutdown (f->loop, f->connection); dbus_connection_close (f->connection); dbus_connection_unref (f->connection); f->connection = NULL; @@ -593,12 +594,14 @@ teardown (Fixture *f, { if (f->server_connection != NULL) { + test_connection_shutdown (f->loop, f->server_connection); dbus_connection_close (f->server_connection); dbus_connection_unref (f->server_connection); } if (f->connection != NULL) { + test_connection_shutdown (f->loop, f->connection); dbus_connection_close (f->connection); dbus_connection_unref (f->connection); } diff --git a/test/loopback.c b/test/loopback.c index ad7e0e94..f89f5a95 100644 --- a/test/loopback.c +++ b/test/loopback.c @@ -420,10 +420,16 @@ teardown (Fixture *f, gconstpointer addr G_GNUC_UNUSED) { if (f->client_conn != NULL) - dbus_connection_close (f->client_conn); + { + test_connection_shutdown (f->ctx, f->client_conn); + dbus_connection_close (f->client_conn); + } if (f->server_conn != NULL) - dbus_connection_close (f->server_conn); + { + test_connection_shutdown (f->ctx, f->server_conn); + dbus_connection_close (f->server_conn); + } dbus_clear_connection (&f->client_conn); dbus_clear_connection (&f->server_conn); diff --git a/test/monitor.c b/test/monitor.c index 1199c85f..6f6e9212 100644 --- a/test/monitor.c +++ b/test/monitor.c @@ -1888,6 +1888,7 @@ teardown (Fixture *f, if (f->monitor != NULL) { dbus_connection_remove_filter (f->monitor, monitor_filter, f); + test_connection_shutdown (f->ctx, f->monitor); dbus_connection_close (f->monitor); dbus_connection_unref (f->monitor); f->monitor = NULL; @@ -1895,6 +1896,7 @@ teardown (Fixture *f, if (f->sender != NULL) { + test_connection_shutdown (f->ctx, f->sender); dbus_connection_close (f->sender); dbus_connection_unref (f->sender); f->sender = NULL; @@ -1906,6 +1908,8 @@ teardown (Fixture *f, if (f->recipient_enqueue_filter_added) dbus_connection_remove_filter (f->recipient, recipient_enqueue_filter, f); + + test_connection_shutdown (f->ctx, f->recipient); dbus_connection_close (f->recipient); dbus_connection_unref (f->recipient); f->recipient = NULL; @@ -1914,6 +1918,7 @@ teardown (Fixture *f, if (f->systemd != NULL) { dbus_connection_remove_filter (f->systemd, systemd_filter, f); + test_connection_shutdown (f->ctx, f->systemd); dbus_connection_close (f->systemd); dbus_connection_unref (f->systemd); f->systemd = NULL; @@ -1922,6 +1927,7 @@ teardown (Fixture *f, if (f->activated != NULL) { dbus_connection_remove_filter (f->activated, activated_filter, f); + test_connection_shutdown (f->ctx, f->activated); dbus_connection_close (f->activated); dbus_connection_unref (f->activated); f->activated = NULL; diff --git a/test/sd-activation.c b/test/sd-activation.c index b5a08bce..b60888ae 100644 --- a/test/sd-activation.c +++ b/test/sd-activation.c @@ -964,6 +964,7 @@ teardown (Fixture *f, if (f->caller_filter_added) dbus_connection_remove_filter (f->caller, caller_filter, f); + test_connection_shutdown (f->ctx, f->caller); dbus_connection_close (f->caller); dbus_connection_unref (f->caller); f->caller = NULL; @@ -974,6 +975,7 @@ teardown (Fixture *f, if (f->systemd_filter_added) dbus_connection_remove_filter (f->systemd, systemd_filter, f); + test_connection_shutdown (f->ctx, f->systemd); dbus_connection_close (f->systemd); dbus_connection_unref (f->systemd); f->systemd = NULL; @@ -984,6 +986,7 @@ teardown (Fixture *f, if (f->activated_filter_added) dbus_connection_remove_filter (f->activated, activated_filter, f); + test_connection_shutdown (f->ctx, f->activated); dbus_connection_close (f->activated); dbus_connection_unref (f->activated); f->activated = NULL; diff --git a/test/uid-permissions.c b/test/uid-permissions.c index 24f6f725..b48ab048 100644 --- a/test/uid-permissions.c +++ b/test/uid-permissions.c @@ -201,6 +201,7 @@ teardown (Fixture *f, if (f->conn != NULL) { + test_connection_shutdown (f->ctx, f->conn); dbus_connection_close (f->conn); dbus_connection_unref (f->conn); f->conn = NULL; -- 2.18.0