~indicator-applet-developers/dbus-test-runner/trunk.16.10

« back to all changes in this revision

Viewing changes to tests/test-own-name.c

  • Committer: CI Train Bot
  • Author(s): Lars Uebernickel
  • Date: 2015-10-02 17:09:55 UTC
  • mfrom: (95.1.1 trunk)
  • Revision ID: ci-train-bot@canonical.com-20151002170955-c5y1arqd0vx9ond6
test-param-wait-system: fix race between tasks

Calling RequestName with gdbus-tool to signal the tested binary that a name is owned is racy: since the name is only owned very shortly, the watch might not have been established before the name is already gone again.

Fix this by holding on to the name a bit longer with the test-own-name helper (add a --system flag to that).  A better fix would be to only start the second task when the watch has been established. dbus-test-runner always starts tasks in parallel though and changing this would further complicate its command line interface.
Approved by: Iain Lane, PS Jenkins bot

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
int
19
19
main (int argc, char * argv[])
20
20
{
 
21
        gboolean system_bus = FALSE;
 
22
        GOptionContext *options;
 
23
        GError *error = NULL;
 
24
 
 
25
        const GOptionEntry option_entries[] = {
 
26
                { "system", 'y', G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, &system_bus, "Own the name on the system bus", NULL },
 
27
                { NULL }
 
28
        };
 
29
 
21
30
#ifndef GLIB_VERSION_2_36
22
31
        g_type_init();
23
32
#endif
24
33
 
 
34
        options = g_option_context_new(NULL);
 
35
        g_option_context_add_main_entries(options, option_entries, NULL);
 
36
        if (!g_option_context_parse(options, &argc, &argv, &error)) {
 
37
                g_printerr("%s", error->message);
 
38
                g_error_free(error);
 
39
                return 1;
 
40
        }
 
41
 
25
42
        if (argc != 2) {
26
43
                g_error("ARG, need a single argument");
27
44
                return 1;
29
46
 
30
47
        g_debug("Trying for name: %s", argv[1]);
31
48
 
32
 
        g_bus_own_name(G_BUS_TYPE_SESSION,
 
49
        g_bus_own_name(system_bus ? G_BUS_TYPE_SYSTEM : G_BUS_TYPE_SESSION,
33
50
                       argv[1],
34
51
                       G_BUS_NAME_OWNER_FLAGS_NONE,
35
52
                       NULL, /* bus aquired */
43
60
        g_timeout_add_seconds(2, end_of_line, mainloop);
44
61
 
45
62
        g_main_loop_run(mainloop);
 
63
 
46
64
        g_main_loop_unref(mainloop);
 
65
        g_option_context_free(options);
47
66
 
48
67
        g_debug("Quitting");
49
68