From 4c08ec1575497c5fd8f68e8a7bf5b5c5724618f0 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 6 Dec 2019 18:57:28 +0100 Subject: clients: in debug builds randomly use sync init of NMClient for testing This affects nmtui and nm-cloud-setup, which use nmc_client_new_waitsync(). --- shared/nm-libnm-aux/nm-libnm-aux.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/shared/nm-libnm-aux/nm-libnm-aux.c b/shared/nm-libnm-aux/nm-libnm-aux.c index 83b6f71b6b..169416b9c4 100644 --- a/shared/nm-libnm-aux/nm-libnm-aux.c +++ b/shared/nm-libnm-aux/nm-libnm-aux.c @@ -102,6 +102,31 @@ nmc_client_new_waitsync (GCancellable *cancellable, }; va_list ap; +#if NM_MORE_ASSERTS > 10 + /* The sync initialization of NMClient is generally a bad idea, because it + * brings the overhead of an additional GMainContext. Anyway, since our own + * code no longer uses that, we hardly test those code paths. But they should + * work just the same. Randomly use instead the sync initialization in a debug + * build... */ + if ((g_random_int () % 2) == 0) { + gboolean success; + + va_start (ap, first_property_name); + nmc = NM_CLIENT (g_object_new_valist (NM_TYPE_CLIENT, first_property_name, ap)); + va_end (ap); + + /* iterate the context at least once, just so that the behavior from POV of the + * caller is roughly the same. */ + g_main_context_iteration (nm_client_get_main_context (nmc), FALSE); + + success = g_initable_init (G_INITABLE (nmc), + cancellable, + error); + NM_SET_OUT (out_nmc, g_steal_pointer (&nmc)); + return success; + } +#endif + va_start (ap, first_property_name); nmc = nmc_client_new_async_valist (cancellable, _nmc_client_new_waitsync_cb, -- cgit v1.2.1