Merge lp:~thomas-voss/biometryd/do-not-trigger-respawn-if-missing-config into lp:biometryd

Proposed by Thomas Voß
Status: Merged
Approved by: Thomas Voß
Approved revision: 37
Merged at revision: 35
Proposed branch: lp:~thomas-voss/biometryd/do-not-trigger-respawn-if-missing-config
Merge into: lp:biometryd
Diff against target: 107 lines (+41/-26)
2 files modified
src/biometry/cmds/run.cpp (+20/-21)
tests/cmds/test_run.cpp (+21/-5)
To merge this branch: bzr merge lp:~thomas-voss/biometryd/do-not-trigger-respawn-if-missing-config
Reviewer Review Type Date Requested Status
Simon Fels Approve
Review via email: mp+298396@code.launchpad.net

Commit message

If default device cannot be instantiated, exit cleanly with success to prevent respawn watchdog from triggering.

Description of the change

If default device cannot be instantiated, exit cleanly with success to prevent respawn watchdog from triggering.

To post a comment you must log in.
Revision history for this message
Simon Fels (morphis) wrote :

LGTM

review: Approve
36. By Thomas Voß

Fix up test case.

37. By Thomas Voß

Prevent from restarting in case of missing device configuration.

Revision history for this message
Simon Fels (morphis) wrote :

LGTM

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/biometry/cmds/run.cpp'
2--- src/biometry/cmds/run.cpp 2016-06-20 20:56:33 +0000
3+++ src/biometry/cmds/run.cpp 2016-06-27 13:58:35 +0000
4@@ -106,37 +106,36 @@
5 action([this](const cli::Command::Context& ctxt)
6 {
7 auto trap = core::posix::trap_signals_for_all_subsequent_threads({core::posix::Signal::sig_term});
8- trap->signal_raised().connect([trap](const core::posix::Signal&)
9+ trap->signal_raised().connect([trap](const core::posix::Signal&) mutable
10 {
11 trap->stop();
12 });
13-
14- std::shared_ptr<biometry::Device> device;
15+
16 try
17 {
18- device = create_default_device(config, *Run::property_store);
19+ auto device = create_default_device(config, *Run::property_store);
20+
21+ auto runtime = Runtime::create();
22+ runtime->start();
23+
24+ auto bus = this->bus_factory();
25+ bus->install_executor(core::dbus::asio::make_executor(bus, runtime->service()));
26+
27+ auto impl = std::make_shared<biometry::DispatchingService>(
28+ biometry::util::create_dispatcher_for_runtime(runtime),device);
29+ auto skeleton = biometry::dbus::skeleton::Service::create_for_bus(bus, impl);
30+
31+ trap->run();
32+
33+ bus->stop();
34+ runtime->stop();
35 }
36 catch (...)
37 {
38- ctxt.cout << "Failed to instantiate device." << std::endl;
39- return EXIT_FAILURE;
40+ ctxt.cout << "Failed to instantiate device...going to sleep" << std::endl;
41+ trap->run();
42 }
43
44- auto runtime = Runtime::create();
45- auto impl = std::make_shared<biometry::DispatchingService>(biometry::util::create_dispatcher_for_runtime(runtime), device);
46-
47- runtime->start();
48-
49- auto bus = this->bus_factory();
50- bus->install_executor(core::dbus::asio::make_executor(bus, runtime->service()));
51-
52- auto skeleton = biometry::dbus::skeleton::Service::create_for_bus(bus, impl);
53-
54- trap->run();
55-
56- bus->stop();
57- runtime->stop();
58-
59 return EXIT_SUCCESS;
60 });
61 }
62
63=== modified file 'tests/cmds/test_run.cpp'
64--- tests/cmds/test_run.cpp 2016-06-20 20:56:33 +0000
65+++ tests/cmds/test_run.cpp 2016-06-27 13:58:35 +0000
66@@ -19,8 +19,12 @@
67
68 #include <biometry/cmds/run.h>
69
70+#include <core/posix/fork.h>
71+
72 #include <gmock/gmock.h>
73
74+#include <did_finish_successfully.h>
75+
76 #include <iostream>
77
78 namespace
79@@ -46,11 +50,23 @@
80 {
81 using namespace ::testing;
82
83- auto mock = std::make_shared<MockPropertyStore>();
84- EXPECT_CALL(*mock, get("ro.product.device")).Times(1).WillOnce(Return("turbo"));
85-
86- biometry::cmds::Run run{mock, biometry::cmds::Run::system_bus_factory()};
87- EXPECT_EQ(EXIT_FAILURE, run.run(biometry::util::cli::Command::Context{std::cin, std::cout, {}}));
88+ auto cp = core::posix::fork([]()
89+ {
90+ auto mock = std::make_shared<MockPropertyStore>();
91+ EXPECT_CALL(*mock, get("ro.product.device")).Times(1).WillOnce(Return("turbo"));
92+
93+ biometry::cmds::Run run{mock, biometry::cmds::Run::system_bus_factory()};
94+ EXPECT_EQ(EXIT_SUCCESS, run.run(biometry::util::cli::Command::Context{std::cin, std::cout, {}}));
95+
96+ return testing::Test::HasFailure() ?
97+ core::posix::exit::Status::failure :
98+ core::posix::exit::Status::success;
99+ }, core::posix::StandardStream::empty);
100+
101+ std::this_thread::sleep_for(std::chrono::milliseconds{50});
102+
103+ cp.send_signal_or_throw(core::posix::Signal::sig_term);
104+ EXPECT_TRUE(testing::did_finish_successfully(cp.wait_for(core::posix::wait::Flags::untraced)));
105 }
106
107 TEST(CmdRun, android_property_store_throws_if_getprop_missing)

Subscribers

People subscribed via source and target branches