Merge lp:~albaguirre/mir/fix-1573572 into lp:mir
- fix-1573572
- Merge into development-branch
Status: | Merged |
---|---|
Merged at revision: | 3474 |
Proposed branch: | lp:~albaguirre/mir/fix-1573572 |
Merge into: | lp:mir |
Diff against target: |
170 lines (+90/-0) 5 files modified
src/server/frontend/screencast_buffer_tracker.cpp (+8/-0) src/server/frontend/screencast_buffer_tracker.h (+5/-0) src/server/frontend/session_mediator.cpp (+15/-0) src/server/frontend/session_mediator.h (+2/-0) tests/unit-tests/frontend/test_session_mediator.cpp (+60/-0) |
To merge this branch: | bzr merge lp:~albaguirre/mir/fix-1573572 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Mir CI Bot | continuous-integration | Needs Fixing | |
Cemil Azizoglu (community) | Approve | ||
Review via email: mp+292653@code.launchpad.net |
Commit message
Remove orphaned screencast sessions on disconnection
When a client disconnects either normally or due to a crash, remove any screencasts associated with the session.
Description of the change
Mir CI Bot (mir-ci-bot) wrote : | # |
PASSED: Continuous integration, rev:3473
https:/
Executed test runs:
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
Click here to trigger a rebuild:
https:/
Mir CI Bot (mir-ci-bot) wrote : | # |
FAILED: Autolanding.
More details in the following jenkins job:
https:/
Executed test runs:
FAILURE: https:/
None: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
FAILURE: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
Alberto Aguirre (albaguirre) wrote : | # |
"[FAILED] ClientLatency.
Unrelated.
Mir CI Bot (mir-ci-bot) wrote : | # |
FAILED: Autolanding.
More details in the following jenkins job:
https:/
Executed test runs:
FAILURE: https:/
None: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
FAILURE: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
Alberto Aguirre (albaguirre) wrote : | # |
"21:49:08 + echo 'SETUP FAILED - CAN'\''T CONTINUE'
21:49:08 SETUP FAILED - CAN'T CONTINUE"
Looks like a device setup issue.
Preview Diff
1 | === modified file 'src/server/frontend/screencast_buffer_tracker.cpp' | |||
2 | --- src/server/frontend/screencast_buffer_tracker.cpp 2016-04-21 00:30:17 +0000 | |||
3 | +++ src/server/frontend/screencast_buffer_tracker.cpp 2016-04-22 15:21:32 +0000 | |||
4 | @@ -31,3 +31,11 @@ | |||
5 | 31 | { | 31 | { |
6 | 32 | tracker.erase(id); | 32 | tracker.erase(id); |
7 | 33 | } | 33 | } |
8 | 34 | |||
9 | 35 | void mf::ScreencastBufferTracker::for_each_session(std::function<void(ScreencastSessionId)> f) const | ||
10 | 36 | { | ||
11 | 37 | for (auto const& entry : tracker) | ||
12 | 38 | { | ||
13 | 39 | f(entry.first); | ||
14 | 40 | } | ||
15 | 41 | } | ||
16 | 34 | 42 | ||
17 | === modified file 'src/server/frontend/screencast_buffer_tracker.h' | |||
18 | --- src/server/frontend/screencast_buffer_tracker.h 2016-04-21 00:30:17 +0000 | |||
19 | +++ src/server/frontend/screencast_buffer_tracker.h 2016-04-22 15:21:32 +0000 | |||
20 | @@ -20,6 +20,7 @@ | |||
21 | 20 | 20 | ||
22 | 21 | #include "mir/frontend/screencast.h" | 21 | #include "mir/frontend/screencast.h" |
23 | 22 | 22 | ||
24 | 23 | #include <functional> | ||
25 | 23 | #include <unordered_set> | 24 | #include <unordered_set> |
26 | 24 | #include <unordered_map> | 25 | #include <unordered_map> |
27 | 25 | 26 | ||
28 | @@ -49,6 +50,10 @@ | |||
29 | 49 | /* removes all tracked buffers associated with id */ | 50 | /* removes all tracked buffers associated with id */ |
30 | 50 | void remove_session(ScreencastSessionId id); | 51 | void remove_session(ScreencastSessionId id); |
31 | 51 | 52 | ||
32 | 53 | /* Iterates over all tracked session ids */ | ||
33 | 54 | void for_each_session(std::function<void(ScreencastSessionId)> f) const; | ||
34 | 55 | |||
35 | 56 | |||
36 | 52 | private: | 57 | private: |
37 | 53 | ScreencastBufferTracker(ScreencastBufferTracker const&) = delete; | 58 | ScreencastBufferTracker(ScreencastBufferTracker const&) = delete; |
38 | 54 | ScreencastBufferTracker& operator=(ScreencastBufferTracker const&) = delete; | 59 | ScreencastBufferTracker& operator=(ScreencastBufferTracker const&) = delete; |
39 | 55 | 60 | ||
40 | === modified file 'src/server/frontend/session_mediator.cpp' | |||
41 | --- src/server/frontend/session_mediator.cpp 2016-04-21 00:30:17 +0000 | |||
42 | +++ src/server/frontend/session_mediator.cpp 2016-04-22 15:21:32 +0000 | |||
43 | @@ -121,6 +121,7 @@ | |||
44 | 121 | report->session_error(session->name(), __PRETTY_FUNCTION__, "connection dropped without disconnect"); | 121 | report->session_error(session->name(), __PRETTY_FUNCTION__, "connection dropped without disconnect"); |
45 | 122 | shell->close_session(session); | 122 | shell->close_session(session); |
46 | 123 | } | 123 | } |
47 | 124 | destroy_screencast_sessions(); | ||
48 | 124 | } | 125 | } |
49 | 125 | 126 | ||
50 | 126 | void mf::SessionMediator::client_pid(int pid) | 127 | void mf::SessionMediator::client_pid(int pid) |
51 | @@ -536,6 +537,7 @@ | |||
52 | 536 | report->session_disconnect_called(session->name()); | 537 | report->session_disconnect_called(session->name()); |
53 | 537 | 538 | ||
54 | 538 | shell->close_session(session); | 539 | shell->close_session(session); |
55 | 540 | destroy_screencast_sessions(); | ||
56 | 539 | weak_session.reset(); | 541 | weak_session.reset(); |
57 | 540 | 542 | ||
58 | 541 | done->Run(); | 543 | done->Run(); |
59 | @@ -1173,3 +1175,16 @@ | |||
60 | 1173 | 1175 | ||
61 | 1174 | return config; | 1176 | return config; |
62 | 1175 | } | 1177 | } |
63 | 1178 | |||
64 | 1179 | void mf::SessionMediator::destroy_screencast_sessions() | ||
65 | 1180 | { | ||
66 | 1181 | std::vector<ScreencastSessionId> ids_to_untrack; | ||
67 | 1182 | screencast_buffer_tracker.for_each_session([this, &ids_to_untrack](ScreencastSessionId id) | ||
68 | 1183 | { | ||
69 | 1184 | screencast->destroy_session(id); | ||
70 | 1185 | ids_to_untrack.push_back(id); | ||
71 | 1186 | }); | ||
72 | 1187 | |||
73 | 1188 | for (auto const& id : ids_to_untrack) | ||
74 | 1189 | screencast_buffer_tracker.remove_session(id); | ||
75 | 1190 | } | ||
76 | 1176 | 1191 | ||
77 | === modified file 'src/server/frontend/session_mediator.h' | |||
78 | --- src/server/frontend/session_mediator.h 2016-04-21 00:30:17 +0000 | |||
79 | +++ src/server/frontend/session_mediator.h 2016-04-22 15:21:32 +0000 | |||
80 | @@ -249,6 +249,8 @@ | |||
81 | 249 | 249 | ||
82 | 250 | virtual std::function<void(std::shared_ptr<Session> const&)> prompt_session_connect_handler() const; | 250 | virtual std::function<void(std::shared_ptr<Session> const&)> prompt_session_connect_handler() const; |
83 | 251 | 251 | ||
84 | 252 | void destroy_screencast_sessions(); | ||
85 | 253 | |||
86 | 252 | pid_t client_pid_; | 254 | pid_t client_pid_; |
87 | 253 | std::shared_ptr<Shell> const shell; | 255 | std::shared_ptr<Shell> const shell; |
88 | 254 | std::shared_ptr<graphics::PlatformIpcOperations> const ipc_operations; | 256 | std::shared_ptr<graphics::PlatformIpcOperations> const ipc_operations; |
89 | 255 | 257 | ||
90 | === modified file 'tests/unit-tests/frontend/test_session_mediator.cpp' | |||
91 | --- tests/unit-tests/frontend/test_session_mediator.cpp 2016-04-21 00:30:17 +0000 | |||
92 | +++ tests/unit-tests/frontend/test_session_mediator.cpp 2016-04-22 15:21:32 +0000 | |||
93 | @@ -44,6 +44,7 @@ | |||
94 | 44 | #include "mir/test/doubles/mock_frontend_surface.h" | 44 | #include "mir/test/doubles/mock_frontend_surface.h" |
95 | 45 | #include "mir/test/doubles/mock_event_sink.h" | 45 | #include "mir/test/doubles/mock_event_sink.h" |
96 | 46 | #include "mir/test/doubles/mock_event_sink_factory.h" | 46 | #include "mir/test/doubles/mock_event_sink_factory.h" |
97 | 47 | #include "mir/test/doubles/mock_screencast.h" | ||
98 | 47 | #include "mir/test/doubles/stub_buffer.h" | 48 | #include "mir/test/doubles/stub_buffer.h" |
99 | 48 | #include "mir/test/doubles/mock_buffer.h" | 49 | #include "mir/test/doubles/mock_buffer.h" |
100 | 49 | #include "mir/test/doubles/stub_session.h" | 50 | #include "mir/test/doubles/stub_session.h" |
101 | @@ -266,6 +267,20 @@ | |||
102 | 266 | mt::fake_shared(mock_hub)); | 267 | mt::fake_shared(mock_hub)); |
103 | 267 | } | 268 | } |
104 | 268 | 269 | ||
105 | 270 | std::shared_ptr<mf::SessionMediator> create_session_mediator_with_screencast( | ||
106 | 271 | std::shared_ptr<mf::Screencast> const& screencast) | ||
107 | 272 | { | ||
108 | 273 | return std::make_shared<mf::SessionMediator>( | ||
109 | 274 | shell, mt::fake_shared(mock_ipc_operations), graphics_changer, | ||
110 | 275 | surface_pixel_formats, report, | ||
111 | 276 | std::make_shared<mtd::NullEventSinkFactory>(), | ||
112 | 277 | std::make_shared<mtd::NullMessageSender>(), | ||
113 | 278 | resource_cache, screencast, &connector, nullptr, nullptr, | ||
114 | 279 | std::make_shared<mtd::NullANRDetector>(), | ||
115 | 280 | mir::cookie::Authority::create(), | ||
116 | 281 | mt::fake_shared(mock_hub)); | ||
117 | 282 | } | ||
118 | 283 | |||
119 | 269 | MockConnector connector; | 284 | MockConnector connector; |
120 | 270 | testing::NiceMock<mtd::MockPlatformIpcOperations> mock_ipc_operations; | 285 | testing::NiceMock<mtd::MockPlatformIpcOperations> mock_ipc_operations; |
121 | 271 | testing::NiceMock<mtd::MockInputDeviceHub> mock_hub; | 286 | testing::NiceMock<mtd::MockInputDeviceHub> mock_hub; |
122 | @@ -1321,3 +1336,48 @@ | |||
123 | 1321 | 1336 | ||
124 | 1322 | EXPECT_THAT(connection.input_devices(), mt::InputDevicesMatch(devices)); | 1337 | EXPECT_THAT(connection.input_devices(), mt::InputDevicesMatch(devices)); |
125 | 1323 | } | 1338 | } |
126 | 1339 | |||
127 | 1340 | TEST_F(SessionMediator, disconnect_removes_orphaned_screencast_sessions) | ||
128 | 1341 | { | ||
129 | 1342 | using namespace ::testing; | ||
130 | 1343 | auto mock_screencast = std::make_shared<NiceMock<mtd::MockScreencast>>(); | ||
131 | 1344 | auto mediator = create_session_mediator_with_screencast(mock_screencast); | ||
132 | 1345 | |||
133 | 1346 | mf::ScreencastSessionId expected_id{7}; | ||
134 | 1347 | mtd::StubBuffer stub_buffer; | ||
135 | 1348 | ON_CALL(*mock_screencast, create_session(_,_,_,_,_)) | ||
136 | 1349 | .WillByDefault(Return(expected_id)); | ||
137 | 1350 | ON_CALL(*mock_screencast, capture(_)) | ||
138 | 1351 | .WillByDefault(Return(mt::fake_shared(stub_buffer))); | ||
139 | 1352 | |||
140 | 1353 | EXPECT_CALL(*mock_screencast, destroy_session(expected_id)); | ||
141 | 1354 | |||
142 | 1355 | mp::ScreencastParameters screencast_parameters; | ||
143 | 1356 | mp::Screencast screencast; | ||
144 | 1357 | mediator->connect(&connect_parameters, &connection, null_callback.get()); | ||
145 | 1358 | mediator->create_screencast(&screencast_parameters, &screencast, null_callback.get()); | ||
146 | 1359 | mediator->disconnect(nullptr, nullptr, null_callback.get()); | ||
147 | 1360 | } | ||
148 | 1361 | |||
149 | 1362 | TEST_F(SessionMediator, destructor_removes_orphaned_screencast_sessions) | ||
150 | 1363 | { | ||
151 | 1364 | using namespace ::testing; | ||
152 | 1365 | auto mock_screencast = std::make_shared<NiceMock<mtd::MockScreencast>>(); | ||
153 | 1366 | auto mediator = create_session_mediator_with_screencast(mock_screencast); | ||
154 | 1367 | |||
155 | 1368 | mf::ScreencastSessionId expected_id{7}; | ||
156 | 1369 | mtd::StubBuffer stub_buffer; | ||
157 | 1370 | ON_CALL(*mock_screencast, create_session(_,_,_,_,_)) | ||
158 | 1371 | .WillByDefault(Return(expected_id)); | ||
159 | 1372 | ON_CALL(*mock_screencast, capture(_)) | ||
160 | 1373 | .WillByDefault(Return(mt::fake_shared(stub_buffer))); | ||
161 | 1374 | |||
162 | 1375 | EXPECT_CALL(*mock_screencast, destroy_session(expected_id)); | ||
163 | 1376 | |||
164 | 1377 | mp::ScreencastParameters screencast_parameters; | ||
165 | 1378 | mp::Screencast screencast; | ||
166 | 1379 | mediator->create_screencast(&screencast_parameters, &screencast, null_callback.get()); | ||
167 | 1380 | |||
168 | 1381 | mediator.reset(); | ||
169 | 1382 | |||
170 | 1383 | } |
Looks good