Merge lp:~larsu/dbus-test-runner/fix-test-race into lp:dbus-test-runner/15.10

Proposed by Lars Karlitski
Status: Merged
Approved by: Iain Lane
Approved revision: 96
Merged at revision: 96
Proposed branch: lp:~larsu/dbus-test-runner/fix-test-race
Merge into: lp:dbus-test-runner/15.10
Diff against target: 65 lines (+22/-3)
2 files modified
tests/Makefile.am (+2/-2)
tests/test-own-name.c (+20/-1)
To merge this branch: bzr merge lp:~larsu/dbus-test-runner/fix-test-race
Reviewer Review Type Date Requested Status
Iain Lane Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+270488@code.launchpad.net

Commit message

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.

Description of the change

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.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Iain Lane (laney) wrote :

thanks, let's upload this!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'tests/Makefile.am'
--- tests/Makefile.am 2015-01-30 17:10:47 +0000
+++ tests/Makefile.am 2015-09-09 07:37:42 +0000
@@ -121,9 +121,9 @@
121XFAIL_TESTS += test-param-only-wait121XFAIL_TESTS += test-param-only-wait
122122
123TESTS += test-param-wait-system123TESTS += test-param-wait-system
124test-param-wait-system: Makefile.am124test-param-wait-system: Makefile.am test-own-name
125 @echo "#!/bin/sh" > $@125 @echo "#!/bin/sh" > $@
126 @echo $(DBUS_RUNNER) --bus-type=system --task ls --task-bus=system --wait-for org.test.test --task gdbus --parameter call --parameter --system --parameter --dest --parameter org.freedesktop.DBus --parameter --object-path --parameter / --parameter --method --parameter org.freedesktop.DBus.RequestName --parameter org.test.test --parameter 0 --task-bus=system >> $@126 @echo $(DBUS_RUNNER) --bus-type=system --task ls --task-bus=system --wait-for org.test.test --task $(builddir)/test-own-name --parameter --system --parameter org.test.test --ignore-return --task-bus=system >> $@
127 @chmod +x $@127 @chmod +x $@
128128
129TESTS += test-param-multi-wait129TESTS += test-param-multi-wait
130130
=== modified file 'tests/test-own-name.c'
--- tests/test-own-name.c 2013-01-29 20:32:11 +0000
+++ tests/test-own-name.c 2015-09-09 07:37:42 +0000
@@ -18,10 +18,27 @@
18int18int
19main (int argc, char * argv[])19main (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#ifndef GLIB_VERSION_2_3630#ifndef GLIB_VERSION_2_36
22 g_type_init();31 g_type_init();
23#endif32#endif
2433
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 if (argc != 2) {42 if (argc != 2) {
26 g_error("ARG, need a single argument");43 g_error("ARG, need a single argument");
27 return 1;44 return 1;
@@ -29,7 +46,7 @@
2946
30 g_debug("Trying for name: %s", argv[1]);47 g_debug("Trying for name: %s", argv[1]);
3148
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 argv[1],50 argv[1],
34 G_BUS_NAME_OWNER_FLAGS_NONE,51 G_BUS_NAME_OWNER_FLAGS_NONE,
35 NULL, /* bus aquired */52 NULL, /* bus aquired */
@@ -43,7 +60,9 @@
43 g_timeout_add_seconds(2, end_of_line, mainloop);60 g_timeout_add_seconds(2, end_of_line, mainloop);
4461
45 g_main_loop_run(mainloop);62 g_main_loop_run(mainloop);
63
46 g_main_loop_unref(mainloop);64 g_main_loop_unref(mainloop);
65 g_option_context_free(options);
4766
48 g_debug("Quitting");67 g_debug("Quitting");
4968

Subscribers

People subscribed via source and target branches