Merge lp:~ted/ubuntu-app-launch/non-blocking-resume into lp:ubuntu-app-launch/touch-vivid
- non-blocking-resume
- Merge into trunk.touch-vivid
Proposed by
Ted Gould
Status: | Merged |
---|---|
Approved by: | Michał Sawicz |
Approved revision: | 275 |
Merged at revision: | 267 |
Proposed branch: | lp:~ted/ubuntu-app-launch/non-blocking-resume |
Merge into: | lp:ubuntu-app-launch/touch-vivid |
Diff against target: |
470 lines (+158/-126) 6 files modified
libubuntu-app-launch/application-impl-base.cpp (+97/-75) libubuntu-app-launch/application-impl-base.h (+15/-6) libubuntu-app-launch/application-impl-libertine.cpp (+1/-2) libubuntu-app-launch/registry-impl.cpp (+19/-26) libubuntu-app-launch/snapd-info.cpp (+1/-1) tests/libual-cpp-test.cc (+25/-16) |
To merge this branch: | bzr merge lp:~ted/ubuntu-app-launch/non-blocking-resume |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Michał Sawicz | Approve | ||
Review via email: mp+310492@code.launchpad.net |
Commit message
Make resume/pause non-blocking
Description of the change
To post a comment you must log in.
Revision history for this message
Michał Sawicz (saviq) wrote : | # |
This is the same as:
https:/
Just different target.
review:
Approve
Revision history for this message
Pat McGowan (pat-mcgowan) wrote : | # |
Tested silo 2181 on an MX4 running proposed and it fixed the symptoms from lp:1637996
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'libubuntu-app-launch/application-impl-base.cpp' | |||
2 | --- libubuntu-app-launch/application-impl-base.cpp 2016-10-03 23:54:20 +0000 | |||
3 | +++ libubuntu-app-launch/application-impl-base.cpp 2016-11-10 15:35:24 +0000 | |||
4 | @@ -257,8 +257,15 @@ | |||
5 | 257 | /** Returns all the PIDs that are in the cgroup for this application */ | 257 | /** Returns all the PIDs that are in the cgroup for this application */ |
6 | 258 | std::vector<pid_t> UpstartInstance::pids() | 258 | std::vector<pid_t> UpstartInstance::pids() |
7 | 259 | { | 259 | { |
10 | 260 | auto pids = registry_->impl->pidsFromCgroup(upstartJobPath()); | 260 | return pids(registry_, appId_, upstartJobPath()); |
11 | 261 | g_debug("Got %d PIDs for AppID '%s'", int(pids.size()), std::string(appId_).c_str()); | 261 | } |
12 | 262 | |||
13 | 263 | std::vector<pid_t> UpstartInstance::pids(const std::shared_ptr<Registry>& reg, | ||
14 | 264 | const AppID& appid, | ||
15 | 265 | const std::string& jobpath) | ||
16 | 266 | { | ||
17 | 267 | auto pids = reg->impl->pidsFromCgroup(jobpath); | ||
18 | 268 | g_debug("Got %d PIDs for AppID '%s'", int(pids.size()), std::string(appid).c_str()); | ||
19 | 262 | return pids; | 269 | return pids; |
20 | 263 | } | 270 | } |
21 | 264 | 271 | ||
22 | @@ -267,16 +274,23 @@ | |||
23 | 267 | void UpstartInstance::pause() | 274 | void UpstartInstance::pause() |
24 | 268 | { | 275 | { |
25 | 269 | g_debug("Pausing application: %s", std::string(appId_).c_str()); | 276 | g_debug("Pausing application: %s", std::string(appId_).c_str()); |
26 | 277 | |||
27 | 278 | auto registry = registry_; | ||
28 | 279 | auto appid = appId_; | ||
29 | 280 | auto jobpath = upstartJobPath(); | ||
30 | 281 | |||
31 | 282 | registry->impl->thread.executeOnThread([registry, appid, jobpath] { | ||
32 | 283 | auto pids = forAllPids(registry, appid, jobpath, [](pid_t pid) { | ||
33 | 284 | auto oomval = oom::paused(); | ||
34 | 285 | g_debug("Pausing PID: %d (%d)", pid, int(oomval)); | ||
35 | 286 | signalToPid(pid, SIGSTOP); | ||
36 | 287 | oomValueToPid(pid, oomval); | ||
37 | 288 | }); | ||
38 | 289 | |||
39 | 290 | pidListToDbus(registry, appid, pids, "ApplicationPaused"); | ||
40 | 291 | }); | ||
41 | 292 | |||
42 | 270 | registry_->impl->zgSendEvent(appId_, ZEITGEIST_ZG_LEAVE_EVENT); | 293 | registry_->impl->zgSendEvent(appId_, ZEITGEIST_ZG_LEAVE_EVENT); |
43 | 271 | |||
44 | 272 | auto pids = forAllPids([this](pid_t pid) { | ||
45 | 273 | auto oomval = oom::paused(); | ||
46 | 274 | g_debug("Pausing PID: %d (%d)", pid, int(oomval)); | ||
47 | 275 | signalToPid(pid, SIGSTOP); | ||
48 | 276 | oomValueToPid(pid, oomval); | ||
49 | 277 | }); | ||
50 | 278 | |||
51 | 279 | pidListToDbus(pids, "ApplicationPaused"); | ||
52 | 280 | } | 294 | } |
53 | 281 | 295 | ||
54 | 282 | /** Resumes this application by sending SIGCONT to all the PIDs in the | 296 | /** Resumes this application by sending SIGCONT to all the PIDs in the |
55 | @@ -284,16 +298,23 @@ | |||
56 | 284 | void UpstartInstance::resume() | 298 | void UpstartInstance::resume() |
57 | 285 | { | 299 | { |
58 | 286 | g_debug("Resuming application: %s", std::string(appId_).c_str()); | 300 | g_debug("Resuming application: %s", std::string(appId_).c_str()); |
59 | 301 | |||
60 | 302 | auto registry = registry_; | ||
61 | 303 | auto appid = appId_; | ||
62 | 304 | auto jobpath = upstartJobPath(); | ||
63 | 305 | |||
64 | 306 | registry->impl->thread.executeOnThread([registry, appid, jobpath] { | ||
65 | 307 | auto pids = forAllPids(registry, appid, jobpath, [](pid_t pid) { | ||
66 | 308 | auto oomval = oom::focused(); | ||
67 | 309 | g_debug("Resuming PID: %d (%d)", pid, int(oomval)); | ||
68 | 310 | signalToPid(pid, SIGCONT); | ||
69 | 311 | oomValueToPid(pid, oomval); | ||
70 | 312 | }); | ||
71 | 313 | |||
72 | 314 | pidListToDbus(registry, appid, pids, "ApplicationResumed"); | ||
73 | 315 | }); | ||
74 | 316 | |||
75 | 287 | registry_->impl->zgSendEvent(appId_, ZEITGEIST_ZG_ACCESS_EVENT); | 317 | registry_->impl->zgSendEvent(appId_, ZEITGEIST_ZG_ACCESS_EVENT); |
76 | 288 | |||
77 | 289 | auto pids = forAllPids([this](pid_t pid) { | ||
78 | 290 | auto oomval = oom::focused(); | ||
79 | 291 | g_debug("Resuming PID: %d (%d)", pid, int(oomval)); | ||
80 | 292 | signalToPid(pid, SIGCONT); | ||
81 | 293 | oomValueToPid(pid, oomval); | ||
82 | 294 | }); | ||
83 | 295 | |||
84 | 296 | pidListToDbus(pids, "ApplicationResumed"); | ||
85 | 297 | } | 318 | } |
86 | 298 | 319 | ||
87 | 299 | /** Stops this instance by asking Upstart to stop it. Upstart will then | 320 | /** Stops this instance by asking Upstart to stop it. Upstart will then |
88 | @@ -365,7 +386,7 @@ | |||
89 | 365 | */ | 386 | */ |
90 | 366 | void UpstartInstance::setOomAdjustment(const oom::Score score) | 387 | void UpstartInstance::setOomAdjustment(const oom::Score score) |
91 | 367 | { | 388 | { |
93 | 368 | forAllPids([this, &score](pid_t pid) { oomValueToPid(pid, score); }); | 389 | forAllPids(registry_, appId_, upstartJobPath(), [score](pid_t pid) { oomValueToPid(pid, score); }); |
94 | 369 | } | 390 | } |
95 | 370 | 391 | ||
96 | 371 | /** Figures out the path to the primary PID of the application and | 392 | /** Figures out the path to the primary PID of the application and |
97 | @@ -404,7 +425,10 @@ | |||
98 | 404 | 425 | ||
99 | 405 | \param eachPid Function to run on each PID | 426 | \param eachPid Function to run on each PID |
100 | 406 | */ | 427 | */ |
102 | 407 | std::vector<pid_t> UpstartInstance::forAllPids(std::function<void(pid_t)> eachPid) | 428 | std::vector<pid_t> UpstartInstance::forAllPids(const std::shared_ptr<Registry>& reg, |
103 | 429 | const AppID& appid, | ||
104 | 430 | const std::string& jobpath, | ||
105 | 431 | std::function<void(pid_t)> eachPid) | ||
106 | 408 | { | 432 | { |
107 | 409 | std::set<pid_t> seenPids; | 433 | std::set<pid_t> seenPids; |
108 | 410 | bool added = true; | 434 | bool added = true; |
109 | @@ -412,7 +436,7 @@ | |||
110 | 412 | while (added) | 436 | while (added) |
111 | 413 | { | 437 | { |
112 | 414 | added = false; | 438 | added = false; |
114 | 415 | auto pidlist = pids(); | 439 | auto pidlist = pids(reg, appid, jobpath); |
115 | 416 | for (auto pid : pidlist) | 440 | for (auto pid : pidlist) |
116 | 417 | { | 441 | { |
117 | 418 | if (seenPids.insert(pid).second) | 442 | if (seenPids.insert(pid).second) |
118 | @@ -572,61 +596,59 @@ | |||
119 | 572 | \param pids List of PIDs to turn into variants to send | 596 | \param pids List of PIDs to turn into variants to send |
120 | 573 | \param signal Name of the DBus signal to send | 597 | \param signal Name of the DBus signal to send |
121 | 574 | */ | 598 | */ |
123 | 575 | void UpstartInstance::pidListToDbus(const std::vector<pid_t>& pids, const std::string& signal) | 599 | void UpstartInstance::pidListToDbus(const std::shared_ptr<Registry>& reg, |
124 | 600 | const AppID& appid, | ||
125 | 601 | const std::vector<pid_t>& pids, | ||
126 | 602 | const std::string& signal) | ||
127 | 576 | { | 603 | { |
151 | 577 | auto registry = registry_; | 604 | auto vpids = std::shared_ptr<GVariant>( |
152 | 578 | auto lappid = appId_; | 605 | [pids]() { |
153 | 579 | 606 | GVariant* pidarray = nullptr; | |
154 | 580 | registry_->impl->thread.executeOnThread([registry, lappid, pids, signal] { | 607 | |
155 | 581 | auto vpids = std::shared_ptr<GVariant>( | 608 | if (pids.empty()) |
156 | 582 | [pids]() { | 609 | { |
157 | 583 | GVariant* pidarray = nullptr; | 610 | pidarray = g_variant_new_array(G_VARIANT_TYPE_UINT64, nullptr, 0); |
135 | 584 | |||
136 | 585 | if (pids.empty()) | ||
137 | 586 | { | ||
138 | 587 | pidarray = g_variant_new_array(G_VARIANT_TYPE_UINT64, nullptr, 0); | ||
139 | 588 | g_variant_ref_sink(pidarray); | ||
140 | 589 | return pidarray; | ||
141 | 590 | } | ||
142 | 591 | |||
143 | 592 | GVariantBuilder builder; | ||
144 | 593 | g_variant_builder_init(&builder, G_VARIANT_TYPE_ARRAY); | ||
145 | 594 | for (auto pid : pids) | ||
146 | 595 | { | ||
147 | 596 | g_variant_builder_add_value(&builder, g_variant_new_uint64(pid)); | ||
148 | 597 | } | ||
149 | 598 | |||
150 | 599 | pidarray = g_variant_builder_end(&builder); | ||
158 | 600 | g_variant_ref_sink(pidarray); | 611 | g_variant_ref_sink(pidarray); |
159 | 601 | return pidarray; | 612 | return pidarray; |
188 | 602 | }(), | 613 | } |
189 | 603 | [](GVariant* var) { g_variant_unref(var); }); | 614 | |
190 | 604 | 615 | GVariantBuilder builder; | |
191 | 605 | GVariantBuilder params; | 616 | g_variant_builder_init(&builder, G_VARIANT_TYPE_ARRAY); |
192 | 606 | g_variant_builder_init(¶ms, G_VARIANT_TYPE_TUPLE); | 617 | for (auto pid : pids) |
193 | 607 | g_variant_builder_add_value(¶ms, g_variant_new_string(std::string(lappid).c_str())); | 618 | { |
194 | 608 | g_variant_builder_add_value(¶ms, vpids.get()); | 619 | g_variant_builder_add_value(&builder, g_variant_new_uint64(pid)); |
195 | 609 | 620 | } | |
196 | 610 | GError* error = nullptr; | 621 | |
197 | 611 | g_dbus_connection_emit_signal(registry->impl->_dbus.get(), /* bus */ | 622 | pidarray = g_variant_builder_end(&builder); |
198 | 612 | nullptr, /* destination */ | 623 | g_variant_ref_sink(pidarray); |
199 | 613 | "/", /* path */ | 624 | return pidarray; |
200 | 614 | "com.canonical.UbuntuAppLaunch", /* interface */ | 625 | }(), |
201 | 615 | signal.c_str(), /* signal */ | 626 | [](GVariant* var) { g_variant_unref(var); }); |
202 | 616 | g_variant_builder_end(¶ms), /* params, the same */ | 627 | |
203 | 617 | &error); /* error */ | 628 | GVariantBuilder params; |
204 | 618 | 629 | g_variant_builder_init(¶ms, G_VARIANT_TYPE_TUPLE); | |
205 | 619 | if (error != nullptr) | 630 | g_variant_builder_add_value(¶ms, g_variant_new_string(std::string(appid).c_str())); |
206 | 620 | { | 631 | g_variant_builder_add_value(¶ms, vpids.get()); |
207 | 621 | g_warning("Unable to emit signal '%s' for appid '%s': %s", signal.c_str(), std::string(lappid).c_str(), | 632 | |
208 | 622 | error->message); | 633 | GError* error = nullptr; |
209 | 623 | g_error_free(error); | 634 | g_dbus_connection_emit_signal(reg->impl->_dbus.get(), /* bus */ |
210 | 624 | } | 635 | nullptr, /* destination */ |
211 | 625 | else | 636 | "/", /* path */ |
212 | 626 | { | 637 | "com.canonical.UbuntuAppLaunch", /* interface */ |
213 | 627 | g_debug("Emmitted '%s' to DBus", signal.c_str()); | 638 | signal.c_str(), /* signal */ |
214 | 628 | } | 639 | g_variant_builder_end(¶ms), /* params, the same */ |
215 | 629 | }); | 640 | &error); /* error */ |
216 | 641 | |||
217 | 642 | if (error != nullptr) | ||
218 | 643 | { | ||
219 | 644 | g_warning("Unable to emit signal '%s' for appid '%s': %s", signal.c_str(), std::string(appid).c_str(), | ||
220 | 645 | error->message); | ||
221 | 646 | g_error_free(error); | ||
222 | 647 | } | ||
223 | 648 | else | ||
224 | 649 | { | ||
225 | 650 | g_debug("Emmitted '%s' to DBus", signal.c_str()); | ||
226 | 651 | } | ||
227 | 630 | } | 652 | } |
228 | 631 | 653 | ||
229 | 632 | /** Create a new Upstart Instance object that can track the job and | 654 | /** Create a new Upstart Instance object that can track the job and |
230 | 633 | 655 | ||
231 | === modified file 'libubuntu-app-launch/application-impl-base.h' | |||
232 | --- libubuntu-app-launch/application-impl-base.h 2016-09-23 22:30:51 +0000 | |||
233 | +++ libubuntu-app-launch/application-impl-base.h 2016-11-10 15:35:24 +0000 | |||
234 | @@ -108,14 +108,23 @@ | |||
235 | 108 | /** A link to the registry we're using for connections */ | 108 | /** A link to the registry we're using for connections */ |
236 | 109 | std::shared_ptr<Registry> registry_; | 109 | std::shared_ptr<Registry> registry_; |
237 | 110 | 110 | ||
238 | 111 | std::vector<pid_t> forAllPids(std::function<void(pid_t)> eachPid); | ||
239 | 112 | void signalToPid(pid_t pid, int signal); | ||
240 | 113 | std::string pidToOomPath(pid_t pid); | ||
241 | 114 | void oomValueToPid(pid_t pid, const oom::Score oomvalue); | ||
242 | 115 | void oomValueToPidHelper(pid_t pid, const oom::Score oomvalue); | ||
243 | 116 | void pidListToDbus(const std::vector<pid_t>& pids, const std::string& signal); | ||
244 | 117 | std::string upstartJobPath(); | 111 | std::string upstartJobPath(); |
245 | 118 | 112 | ||
246 | 113 | static std::vector<pid_t> forAllPids(const std::shared_ptr<Registry>& reg, | ||
247 | 114 | const AppID& appid, | ||
248 | 115 | const std::string& jobpath, | ||
249 | 116 | std::function<void(pid_t)> eachPid); | ||
250 | 117 | static std::vector<pid_t> pids(const std::shared_ptr<Registry>& reg, | ||
251 | 118 | const AppID& appid, | ||
252 | 119 | const std::string& jobpath); | ||
253 | 120 | static void pidListToDbus(const std::shared_ptr<Registry>& reg, | ||
254 | 121 | const AppID& appid, | ||
255 | 122 | const std::vector<pid_t>& pids, | ||
256 | 123 | const std::string& signal); | ||
257 | 124 | static void signalToPid(pid_t pid, int signal); | ||
258 | 125 | static void oomValueToPid(pid_t pid, const oom::Score oomvalue); | ||
259 | 126 | static void oomValueToPidHelper(pid_t pid, const oom::Score oomvalue); | ||
260 | 127 | static std::string pidToOomPath(pid_t pid); | ||
261 | 119 | static std::shared_ptr<gchar*> urlsToStrv(const std::vector<Application::URL>& urls); | 128 | static std::shared_ptr<gchar*> urlsToStrv(const std::vector<Application::URL>& urls); |
262 | 120 | static void application_start_cb(GObject* obj, GAsyncResult* res, gpointer user_data); | 129 | static void application_start_cb(GObject* obj, GAsyncResult* res, gpointer user_data); |
263 | 121 | }; | 130 | }; |
264 | 122 | 131 | ||
265 | === modified file 'libubuntu-app-launch/application-impl-libertine.cpp' | |||
266 | --- libubuntu-app-launch/application-impl-libertine.cpp 2016-10-03 23:54:20 +0000 | |||
267 | +++ libubuntu-app-launch/application-impl-libertine.cpp 2016-11-10 15:35:24 +0000 | |||
268 | @@ -255,8 +255,7 @@ | |||
269 | 255 | } | 255 | } |
270 | 256 | catch (std::runtime_error& e) | 256 | catch (std::runtime_error& e) |
271 | 257 | { | 257 | { |
274 | 258 | g_debug("Unable to create application for libertine appname '%s': %s", | 258 | g_debug("Unable to create application for libertine appname '%s': %s", apps.get()[j], e.what()); |
273 | 259 | apps.get()[j], e.what()); | ||
275 | 260 | } | 259 | } |
276 | 261 | } | 260 | } |
277 | 262 | } | 261 | } |
278 | 263 | 262 | ||
279 | === modified file 'libubuntu-app-launch/registry-impl.cpp' | |||
280 | --- libubuntu-app-launch/registry-impl.cpp 2016-09-23 22:30:51 +0000 | |||
281 | +++ libubuntu-app-launch/registry-impl.cpp 2016-11-10 15:35:24 +0000 | |||
282 | @@ -222,17 +222,13 @@ | |||
283 | 222 | if (cgManager_) | 222 | if (cgManager_) |
284 | 223 | return; | 223 | return; |
285 | 224 | 224 | ||
290 | 225 | std::promise<std::shared_ptr<GDBusConnection>> promise; | 225 | cgManager_ = thread.executeOnThread<std::shared_ptr<GDBusConnection>>([this]() { |
287 | 226 | auto future = promise.get_future(); | ||
288 | 227 | |||
289 | 228 | thread.executeOnThread([this, &promise]() { | ||
291 | 229 | bool use_session_bus = g_getenv("UBUNTU_APP_LAUNCH_CG_MANAGER_SESSION_BUS") != nullptr; | 226 | bool use_session_bus = g_getenv("UBUNTU_APP_LAUNCH_CG_MANAGER_SESSION_BUS") != nullptr; |
292 | 230 | if (use_session_bus) | 227 | if (use_session_bus) |
293 | 231 | { | 228 | { |
294 | 232 | /* For working dbusmock */ | 229 | /* For working dbusmock */ |
295 | 233 | g_debug("Connecting to CG Manager on session bus"); | 230 | g_debug("Connecting to CG Manager on session bus"); |
298 | 234 | promise.set_value(_dbus); | 231 | return _dbus; |
297 | 235 | return; | ||
299 | 236 | } | 232 | } |
300 | 237 | 233 | ||
301 | 238 | auto cancel = | 234 | auto cancel = |
302 | @@ -241,28 +237,25 @@ | |||
303 | 241 | /* Ensure that we do not wait for more than a second */ | 237 | /* Ensure that we do not wait for more than a second */ |
304 | 242 | thread.timeoutSeconds(std::chrono::seconds{1}, [cancel]() { g_cancellable_cancel(cancel.get()); }); | 238 | thread.timeoutSeconds(std::chrono::seconds{1}, [cancel]() { g_cancellable_cancel(cancel.get()); }); |
305 | 243 | 239 | ||
325 | 244 | g_dbus_connection_new_for_address( | 240 | GError* error = nullptr; |
326 | 245 | CGMANAGER_DBUS_PATH, /* cgmanager path */ | 241 | auto retval = std::shared_ptr<GDBusConnection>( |
327 | 246 | G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT, /* flags */ | 242 | g_dbus_connection_new_for_address_sync(CGMANAGER_DBUS_PATH, /* cgmanager path */ |
328 | 247 | nullptr, /* Auth Observer */ | 243 | G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT, /* flags */ |
329 | 248 | cancel.get(), /* Cancellable */ | 244 | nullptr, /* Auth Observer */ |
330 | 249 | [](GObject* obj, GAsyncResult* res, gpointer data) -> void { | 245 | cancel.get(), /* Cancellable */ |
331 | 250 | GError* error = nullptr; | 246 | &error), |
332 | 251 | auto promise = reinterpret_cast<std::promise<std::shared_ptr<GDBusConnection>>*>(data); | 247 | [](GDBusConnection* con) { g_clear_object(&con); }); |
333 | 252 | 248 | ||
334 | 253 | auto gcon = g_dbus_connection_new_for_address_finish(res, &error); | 249 | if (error != nullptr) |
335 | 254 | if (error != nullptr) | 250 | { |
336 | 255 | { | 251 | g_warning("Unable to get CGManager connection: %s", error->message); |
337 | 256 | g_error_free(error); | 252 | g_error_free(error); |
338 | 257 | } | 253 | } |
339 | 258 | 254 | ||
340 | 259 | auto con = std::shared_ptr<GDBusConnection>(gcon, [](GDBusConnection* con) { g_clear_object(&con); }); | 255 | return retval; |
322 | 260 | promise->set_value(con); | ||
323 | 261 | }, | ||
324 | 262 | &promise); | ||
341 | 263 | }); | 256 | }); |
342 | 264 | 257 | ||
344 | 265 | cgManager_ = future.get(); | 258 | /* NOTE: This will execute on the thread */ |
345 | 266 | thread.timeoutSeconds(std::chrono::seconds{10}, [this]() { cgManager_.reset(); }); | 259 | thread.timeoutSeconds(std::chrono::seconds{10}, [this]() { cgManager_.reset(); }); |
346 | 267 | } | 260 | } |
347 | 268 | 261 | ||
348 | 269 | 262 | ||
349 | === modified file 'libubuntu-app-launch/snapd-info.cpp' | |||
350 | --- libubuntu-app-launch/snapd-info.cpp 2016-10-03 23:54:08 +0000 | |||
351 | +++ libubuntu-app-launch/snapd-info.cpp 2016-11-10 15:35:24 +0000 | |||
352 | @@ -217,7 +217,7 @@ | |||
353 | 217 | curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, snapd_writefunc); | 217 | curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, snapd_writefunc); |
354 | 218 | 218 | ||
355 | 219 | /* Overridable timeout */ | 219 | /* Overridable timeout */ |
357 | 220 | if (g_getenv("UBUNTU_APP_LAUNCH_DISABLE_SNAPD_TIMEOUT") != nullptr) | 220 | if (g_getenv("UBUNTU_APP_LAUNCH_DISABLE_SNAPD_TIMEOUT") == nullptr) |
358 | 221 | { | 221 | { |
359 | 222 | curl_easy_setopt(curl, CURLOPT_TIMEOUT_MS, 100L); | 222 | curl_easy_setopt(curl, CURLOPT_TIMEOUT_MS, 100L); |
360 | 223 | } | 223 | } |
361 | 224 | 224 | ||
362 | === modified file 'tests/libual-cpp-test.cc' | |||
363 | --- tests/libual-cpp-test.cc 2016-09-23 20:36:31 +0000 | |||
364 | +++ tests/libual-cpp-test.cc 2016-11-10 15:35:24 +0000 | |||
365 | @@ -1523,13 +1523,7 @@ | |||
366 | 1523 | } | 1523 | } |
367 | 1524 | }; | 1524 | }; |
368 | 1525 | 1525 | ||
376 | 1526 | static void signal_increment(GDBusConnection* connection, | 1526 | static void signal_increment(const gchar* appid, GPid* pids, gpointer user_data) |
370 | 1527 | const gchar* sender, | ||
371 | 1528 | const gchar* path, | ||
372 | 1529 | const gchar* interface, | ||
373 | 1530 | const gchar* signal, | ||
374 | 1531 | GVariant* params, | ||
375 | 1532 | gpointer user_data) | ||
377 | 1533 | { | 1527 | { |
378 | 1534 | guint* count = (guint*)user_data; | 1528 | guint* count = (guint*)user_data; |
379 | 1535 | g_debug("Count incremented to: %d", *count + 1); | 1529 | g_debug("Count incremented to: %d", *count + 1); |
380 | @@ -1577,12 +1571,9 @@ | |||
381 | 1577 | /* Setup signal handling */ | 1571 | /* Setup signal handling */ |
382 | 1578 | guint paused_count = 0; | 1572 | guint paused_count = 0; |
383 | 1579 | guint resumed_count = 0; | 1573 | guint resumed_count = 0; |
390 | 1580 | guint paused_signal = | 1574 | |
391 | 1581 | g_dbus_connection_signal_subscribe(bus, nullptr, "com.canonical.UbuntuAppLaunch", "ApplicationPaused", "/", | 1575 | ASSERT_TRUE(ubuntu_app_launch_observer_add_app_paused(signal_increment, &paused_count)); |
392 | 1582 | nullptr, G_DBUS_SIGNAL_FLAGS_NONE, signal_increment, &paused_count, nullptr); | 1576 | ASSERT_TRUE(ubuntu_app_launch_observer_add_app_resumed(signal_increment, &resumed_count)); |
387 | 1583 | guint resumed_signal = g_dbus_connection_signal_subscribe( | ||
388 | 1584 | bus, nullptr, "com.canonical.UbuntuAppLaunch", "ApplicationResumed", "/", nullptr, G_DBUS_SIGNAL_FLAGS_NONE, | ||
389 | 1585 | signal_increment, &resumed_count, nullptr); | ||
393 | 1586 | 1577 | ||
394 | 1587 | /* Get our app object */ | 1578 | /* Get our app object */ |
395 | 1588 | auto appid = ubuntu::app_launch::AppID::find(registry, "com.test.good_application_1.2.3"); | 1579 | auto appid = ubuntu::app_launch::AppID::find(registry, "com.test.good_application_1.2.3"); |
396 | @@ -1639,8 +1630,8 @@ | |||
397 | 1639 | 1630 | ||
398 | 1640 | g_spawn_command_line_sync("rm -rf " CMAKE_BINARY_DIR "/libual-proc", NULL, NULL, NULL, NULL); | 1631 | g_spawn_command_line_sync("rm -rf " CMAKE_BINARY_DIR "/libual-proc", NULL, NULL, NULL, NULL); |
399 | 1641 | 1632 | ||
402 | 1642 | g_dbus_connection_signal_unsubscribe(bus, paused_signal); | 1633 | ASSERT_TRUE(ubuntu_app_launch_observer_delete_app_paused(signal_increment, &paused_count)); |
403 | 1643 | g_dbus_connection_signal_unsubscribe(bus, resumed_signal); | 1634 | ASSERT_TRUE(ubuntu_app_launch_observer_delete_app_resumed(signal_increment, &resumed_count)); |
404 | 1644 | } | 1635 | } |
405 | 1645 | 1636 | ||
406 | 1646 | TEST_F(LibUAL, MultiPause) | 1637 | TEST_F(LibUAL, MultiPause) |
407 | @@ -1686,10 +1677,17 @@ | |||
408 | 1686 | do | 1677 | do |
409 | 1687 | { | 1678 | { |
410 | 1688 | g_debug("Giving mocks a chance to start"); | 1679 | g_debug("Giving mocks a chance to start"); |
412 | 1689 | pause(200); | 1680 | pause(20); |
413 | 1690 | } while (dbus_test_task_get_state(DBUS_TEST_TASK(cgmock2)) != DBUS_TEST_TASK_STATE_RUNNING && | 1681 | } while (dbus_test_task_get_state(DBUS_TEST_TASK(cgmock2)) != DBUS_TEST_TASK_STATE_RUNNING && |
414 | 1691 | dbus_test_task_get_state(DBUS_TEST_TASK(zgmock)) != DBUS_TEST_TASK_STATE_RUNNING); | 1682 | dbus_test_task_get_state(DBUS_TEST_TASK(zgmock)) != DBUS_TEST_TASK_STATE_RUNNING); |
415 | 1692 | 1683 | ||
416 | 1684 | /* Setup signal handling */ | ||
417 | 1685 | guint paused_count = 0; | ||
418 | 1686 | guint resumed_count = 0; | ||
419 | 1687 | |||
420 | 1688 | ASSERT_TRUE(ubuntu_app_launch_observer_add_app_paused(signal_increment, &paused_count)); | ||
421 | 1689 | ASSERT_TRUE(ubuntu_app_launch_observer_add_app_resumed(signal_increment, &resumed_count)); | ||
422 | 1690 | |||
423 | 1693 | /* Get our app object */ | 1691 | /* Get our app object */ |
424 | 1694 | auto appid = ubuntu::app_launch::AppID::find(registry, "com.test.good_application_1.2.3"); | 1692 | auto appid = ubuntu::app_launch::AppID::find(registry, "com.test.good_application_1.2.3"); |
425 | 1695 | auto app = ubuntu::app_launch::Application::create(appid, registry); | 1693 | auto app = ubuntu::app_launch::Application::create(appid, registry); |
426 | @@ -1705,6 +1703,8 @@ | |||
427 | 1705 | /* Pause the app */ | 1703 | /* Pause the app */ |
428 | 1706 | instance->pause(); | 1704 | instance->pause(); |
429 | 1707 | 1705 | ||
430 | 1706 | EXPECT_EVENTUALLY_EQ(1, paused_count); | ||
431 | 1707 | |||
432 | 1708 | std::for_each(spews.begin(), spews.end(), [](SpewMaster& spew) { spew.reset(); }); | 1708 | std::for_each(spews.begin(), spews.end(), [](SpewMaster& spew) { spew.reset(); }); |
433 | 1709 | pause(50); | 1709 | pause(50); |
434 | 1710 | 1710 | ||
435 | @@ -1715,6 +1715,8 @@ | |||
436 | 1715 | /* Now Resume the App */ | 1715 | /* Now Resume the App */ |
437 | 1716 | instance->resume(); | 1716 | instance->resume(); |
438 | 1717 | 1717 | ||
439 | 1718 | EXPECT_EVENTUALLY_EQ(1, resumed_count); | ||
440 | 1719 | |||
441 | 1718 | pause(50); | 1720 | pause(50); |
442 | 1719 | 1721 | ||
443 | 1720 | EXPECT_NE(0, std::accumulate(spews.begin(), spews.end(), int{0}, | 1722 | EXPECT_NE(0, std::accumulate(spews.begin(), spews.end(), int{0}, |
444 | @@ -1723,6 +1725,8 @@ | |||
445 | 1723 | /* Pause the app */ | 1725 | /* Pause the app */ |
446 | 1724 | instance->pause(); | 1726 | instance->pause(); |
447 | 1725 | 1727 | ||
448 | 1728 | EXPECT_EVENTUALLY_EQ(2, paused_count); | ||
449 | 1729 | |||
450 | 1726 | std::for_each(spews.begin(), spews.end(), [](SpewMaster& spew) { spew.reset(); }); | 1730 | std::for_each(spews.begin(), spews.end(), [](SpewMaster& spew) { spew.reset(); }); |
451 | 1727 | pause(50); | 1731 | pause(50); |
452 | 1728 | 1732 | ||
453 | @@ -1733,12 +1737,17 @@ | |||
454 | 1733 | /* Now Resume the App */ | 1737 | /* Now Resume the App */ |
455 | 1734 | instance->resume(); | 1738 | instance->resume(); |
456 | 1735 | 1739 | ||
457 | 1740 | EXPECT_EVENTUALLY_EQ(2, resumed_count); | ||
458 | 1741 | |||
459 | 1736 | pause(50); | 1742 | pause(50); |
460 | 1737 | 1743 | ||
461 | 1738 | EXPECT_NE(0, std::accumulate(spews.begin(), spews.end(), int{0}, | 1744 | EXPECT_NE(0, std::accumulate(spews.begin(), spews.end(), int{0}, |
462 | 1739 | [](const int& acc, SpewMaster& spew) { return acc + spew.dataCnt(); })); | 1745 | [](const int& acc, SpewMaster& spew) { return acc + spew.dataCnt(); })); |
463 | 1740 | 1746 | ||
464 | 1741 | g_spawn_command_line_sync("rm -rf " CMAKE_BINARY_DIR "/libual-proc", NULL, NULL, NULL, NULL); | 1747 | g_spawn_command_line_sync("rm -rf " CMAKE_BINARY_DIR "/libual-proc", NULL, NULL, NULL, NULL); |
465 | 1748 | |||
466 | 1749 | ASSERT_TRUE(ubuntu_app_launch_observer_delete_app_paused(signal_increment, &paused_count)); | ||
467 | 1750 | ASSERT_TRUE(ubuntu_app_launch_observer_delete_app_resumed(signal_increment, &resumed_count)); | ||
468 | 1742 | } | 1751 | } |
469 | 1743 | 1752 | ||
470 | 1744 | TEST_F(LibUAL, OOMSet) | 1753 | TEST_F(LibUAL, OOMSet) |
Kaboom: http:// pastebin. ubuntu. com/23455077/