Mir

Merge lp:~afrantzis/mir/fix-1462033-NestedInput-test-race into lp:mir

Proposed by Alexandros Frantzis
Status: Merged
Approved by: Daniel van Vugt
Approved revision: no longer in the source branch.
Merged at revision: 2665
Proposed branch: lp:~afrantzis/mir/fix-1462033-NestedInput-test-race
Merge into: lp:mir
Diff against target: 76 lines (+30/-13)
1 file modified
tests/acceptance-tests/test_nested_input.cpp (+30/-13)
To merge this branch: bzr merge lp:~afrantzis/mir/fix-1462033-NestedInput-test-race
Reviewer Review Type Date Requested Status
Daniel van Vugt Approve
Alberto Aguirre (community) Approve
PS Jenkins bot (community) continuous-integration Approve
Kevin DuBois (community) Needs Information
Review via email: mp+261955@code.launchpad.net

Commit message

tests: Fix race in NestedInput test (LP: #1462033)

Because we are testing a nested setup, it's difficult to guarantee
that the nested framebuffer surface (and consenquently the client surface
contained in it) is going to be ready (i.e., exposed and focused) to receive
events when we send them. We work around this issue by first sending some
dummy events and waiting until we receive one of them.

Description of the change

tests: Fix race in NestedInput test (LP: #1462033)

Because we are testing a nested setup, it's difficult to guarantee
that the nested framebuffer surface (and consenquently the client surface
contained in it) is going to be ready (i.e., exposed and focused) to receive
events when we send them. We work around this issue by first sending some
dummy events and waiting until we receive one of them.

To post a comment you must log in.
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 :

"Temporary failure resolving 'ports.ubuntu.com'". Rebuilding.

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

49+ EXPECT_CALL(*nested_mir.mock_event_filter, handle(mt::KeyOfScanCode(KEY_A))).
50+ Times(AtLeast(0)).
51+ WillRepeatedly(DoAll(InvokeWithoutArgs(increase_key_a_events), Return(true)));
Why not "Times(AtLeast(1))" ?

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

> Why not "Times(AtLeast(1))" ?

Fixed, thanks.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Alberto Aguirre (albaguirre) wrote :

OK.

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

Not an easy problem to solve, and impossible to solve reliably when you add a real human into the mix... Because there's a delay in the user seeing the screen and reacting, still sometimes you will click on something that's not there any more.

Seems reasonable.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'tests/acceptance-tests/test_nested_input.cpp'
2--- tests/acceptance-tests/test_nested_input.cpp 2015-05-19 21:34:34 +0000
3+++ tests/acceptance-tests/test_nested_input.cpp 2015-06-15 17:38:30 +0000
4@@ -28,6 +28,7 @@
5 #include "mir_test_framework/any_surface.h"
6 #include "mir_test_doubles/nested_mock_egl.h"
7 #include "mir_test/event_factory.h"
8+#include "mir_test/event_matchers.h"
9 #include "mir_test/fake_shared.h"
10 #include "mir_test/wait_condition.h"
11 #include "mir_test/spin_wait.h"
12@@ -38,6 +39,7 @@
13 #include <gmock/gmock.h>
14
15 #include <linux/input.h>
16+#include <atomic>
17
18 namespace mi = mir::input;
19 namespace mis = mi::synthesis;
20@@ -112,15 +114,6 @@
21 connection = mir_connect_sync(connect_string.c_str(), __PRETTY_FUNCTION__);
22 surface = mtf::make_any_surface(connection);
23 mir_buffer_stream_swap_buffers_sync(mir_surface_get_buffer_stream(surface));
24-
25- bool became_exposed_and_focused = mir::test::spin_wait_for_condition_or_timeout(
26- [this]
27- {
28- return mir_surface_get_visibility(surface) == mir_surface_visibility_exposed
29- && mir_surface_get_focus(surface) == mir_surface_focused;
30- },
31- std::chrono::seconds{10});
32- EXPECT_TRUE(became_exposed_and_focused);
33 }
34
35 ~ExposedSurface()
36@@ -143,12 +136,36 @@
37 {
38 NestedServerWithMockEventFilter nested_mir{new_connection()};
39 ExposedSurface client(nested_mir.new_connection());
40+ std::atomic<int> num_key_a_events{0};
41+
42+ auto const increase_key_a_events = [&num_key_a_events] { ++num_key_a_events; };
43
44 InSequence seq;
45- EXPECT_CALL(*nested_mir.mock_event_filter, handle(_)).Times(AtLeast(1)).WillOnce(Return(true));
46- EXPECT_CALL(*nested_mir.mock_event_filter, handle(_)).Times(AtLeast(1)).WillOnce(
47- DoAll(mt::WakeUp(&all_events_received), Return(true)));
48-
49+ EXPECT_CALL(*nested_mir.mock_event_filter, handle(mt::KeyOfScanCode(KEY_A))).
50+ Times(AtLeast(1)).
51+ WillRepeatedly(DoAll(InvokeWithoutArgs(increase_key_a_events), Return(true)));
52+
53+ EXPECT_CALL(*nested_mir.mock_event_filter, handle(mt::KeyOfScanCode(KEY_RIGHTSHIFT))).
54+ Times(2).
55+ WillOnce(Return(true)).
56+ WillOnce(DoAll(mt::WakeUp(&all_events_received), Return(true)));
57+
58+ // Because we are testing a nested setup, it's difficult to guarantee
59+ // that the nested framebuffer surface (and consenquently the client surface
60+ // contained in it) is going to be ready (i.e., exposed and focused) to receive
61+ // events when we send them. We work around this issue by first sending some
62+ // dummy events and waiting until we receive one of them.
63+ auto const dummy_events_received = mt::spin_wait_for_condition_or_timeout(
64+ [&]
65+ {
66+ if (num_key_a_events > 0) return true;
67+ fake_keyboard->emit_event(mis::a_key_down_event().of_scancode(KEY_A));
68+ fake_keyboard->emit_event(mis::a_key_up_event().of_scancode(KEY_A));
69+ return false;
70+ },
71+ std::chrono::seconds{5});
72+
73+ EXPECT_TRUE(dummy_events_received);
74
75 fake_keyboard->emit_event(mis::a_key_down_event().of_scancode(KEY_RIGHTSHIFT));
76 fake_keyboard->emit_event(mis::a_key_up_event().of_scancode(KEY_RIGHTSHIFT));

Subscribers

People subscribed via source and target branches