Mir

Merge lp:~afrantzis/mir/fix-1354446 into lp:mir

Proposed by Alexandros Frantzis
Status: Merged
Approved by: Alexandros Frantzis
Approved revision: no longer in the source branch.
Merged at revision: 1842
Proposed branch: lp:~afrantzis/mir/fix-1354446
Merge into: lp:mir
Diff against target: 42 lines (+17/-1)
1 file modified
tests/mir_test_framework/input_testing_server_options.cpp (+17/-1)
To merge this branch: bzr merge lp:~afrantzis/mir/fix-1354446
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Daniel van Vugt Approve
Kevin DuBois (community) Approve
Alan Griffiths Approve
Review via email: mp+230259@code.launchpad.net

Commit message

tests: Fix race in InputTestingServerConfiguration

We need to wait for the 'input_injection_thread' variable to be
assigned to before starting. Otherwise we may end up calling
on_exit() before assignment and try to join an unjoinable thread.

Description of the change

tests: Fix race in InputTestingServerConfiguration

We need to wait for the 'input_injection_thread' variable to be
assigned to before starting. Otherwise we may end up calling
on_exit() before assignment and try to join an unjoinable thread.

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
Alan Griffiths (alan-griffiths) wrote :

LGTM

review: Approve
Revision history for this message
Kevin DuBois (kdub) :
review: Approve
Revision history for this message
Daniel van Vugt (vanvugt) wrote :

Should we be concerned that on_exit is being called before on_start? Because that appears to be the only way for the bug to occur.

review: Needs Information
Revision history for this message
Daniel van Vugt (vanvugt) wrote :

Providing both functions are executed from the same thread then you could just say:

void mtf::InputTestingServerConfiguration::on_start()
{
    if (exited) return;
    input_injection_thread =
        std::thread(std::mem_fn(&mtf::InputTestingServerConfiguration::inject_input), this);
}

void mtf::InputTestingServerConfiguration::on_exit()
{
    if (input_injection_thread.joinable())
        input_injection_thread.join();
    exited = true;
}

Revision history for this message
Alexandros Frantzis (afrantzis) wrote :

> Should we be concerned that on_exit is being called before on_start? Because\
> Providing both functions are executed from the same thread then you could just say

on_exit() is called from a different thread during the call to on_start() because the the input injection thread may run first and cause the test to finish before we have left on_start().

Revision history for this message
Daniel van Vugt (vanvugt) wrote :

Bugger. That's somewhat unexpected but does convince me then this is the right fix.

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Alexandros Frantzis (afrantzis) wrote :

Building remotely on cyclops-node07 in workspace /home/ubuntu/jenkins/workspace/mir-mediumtests-builder-utopic-armhf
java.io.IOException: Failed to mkdirs: /home/ubuntu/jenkins/workspace/mir-mediumtests-builder-utopic-armhf

It seems cyclops-node07 is stuck in a bad state.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'tests/mir_test_framework/input_testing_server_options.cpp'
2--- tests/mir_test_framework/input_testing_server_options.cpp 2014-08-06 01:40:20 +0000
3+++ tests/mir_test_framework/input_testing_server_options.cpp 2014-08-11 08:51:07 +0000
4@@ -27,6 +27,7 @@
5
6 #include "mir_test/fake_event_hub.h"
7 #include "mir_test/fake_event_hub_input_configuration.h"
8+#include "mir_test/wait_condition.h"
9
10 #include <boost/throw_exception.hpp>
11
12@@ -34,6 +35,7 @@
13 #include <stdexcept>
14
15 namespace mtf = mir_test_framework;
16+namespace mt = mir::test;
17
18 namespace mf = mir::frontend;
19 namespace mg = mir::graphics;
20@@ -55,7 +57,21 @@
21
22 void mtf::InputTestingServerConfiguration::on_start()
23 {
24- input_injection_thread = std::thread(std::mem_fn(&mtf::InputTestingServerConfiguration::inject_input), this);
25+ auto const start_input_injection = std::make_shared<mt::WaitCondition>();
26+
27+ input_injection_thread = std::thread{
28+ [this, start_input_injection]
29+ {
30+ // We need to wait for the 'input_injection_thread' variable to be
31+ // assigned to before starting. Otherwise we may end up calling
32+ // on_exit() before assignment and try to join an unjoinable thread.
33+ start_input_injection->wait_for_at_most_seconds(3);
34+ if (!start_input_injection->woken())
35+ BOOST_THROW_EXCEPTION(std::runtime_error("Input injection thread start signal timed out"));
36+ inject_input();
37+ }};
38+
39+ start_input_injection->wake_up_everyone();
40 }
41
42 void mtf::InputTestingServerConfiguration::on_exit()

Subscribers

People subscribed via source and target branches