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().
This commit is contained in:
Thomas Haller 2019-12-06 18:57:28 +01:00
parent 030e1472f4
commit cb755afa24

View file

@ -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,