summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2019-12-06 18:57:28 +0100
committerThomas Haller <thaller@redhat.com>2019-12-10 09:17:17 +0100
commitcb755afa2409611e4691609743d4ee8841b75bc5 (patch)
tree0d116434e3c060ea62323f98af4207436f838f27
parent030e1472f4235ec253735336a743826b8540be19 (diff)
downloadNetworkManager-cb755afa2409611e4691609743d4ee8841b75bc5.tar.gz
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().
-rw-r--r--shared/nm-libnm-aux/nm-libnm-aux.c25
1 files changed, 25 insertions, 0 deletions
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,