Pipe through exit statuses in AOS Run() methods
This makes it so that the sundry Run() methods can return exit statuses
when exited using the ExitHandle. This enables certain categories of
error-handling that were hard to do previously---in particular, this
enables future modifications to LogReader to propagate log reading
faults through this interface.
Change-Id: I238e7aa6b82dc3d7938630b2b0ab96eb30b573eb
Signed-off-by: James Kuszmaul <james.kuszmaul@bluerivertech.com>
diff --git a/aos/events/shm_event_loop_test.cc b/aos/events/shm_event_loop_test.cc
index bae834a..2fbe735 100644
--- a/aos/events/shm_event_loop_test.cc
+++ b/aos/events/shm_event_loop_test.cc
@@ -57,7 +57,13 @@
return loop;
}
- void Run() override { CHECK_NOTNULL(primary_event_loop_)->Run(); }
+ Result<void> Run() override {
+ return CHECK_NOTNULL(primary_event_loop_)->Run();
+ }
+
+ std::unique_ptr<ExitHandle> MakeExitHandle() override {
+ return CHECK_NOTNULL(primary_event_loop_)->MakeExitHandle();
+ }
void Exit() override { CHECK_NOTNULL(primary_event_loop_)->Exit(); }
@@ -66,7 +72,7 @@
}
private:
- ::aos::ShmEventLoop *primary_event_loop_;
+ ::aos::ShmEventLoop *primary_event_loop_ = nullptr;
};
auto CommonParameters() {
@@ -296,6 +302,21 @@
EXPECT_EQ(times.size(), 2u);
}
+// Tests that the ShmEventLoop::Exit() method causes the ShmEventLoop to return
+// with a successful status.
+TEST_P(ShmEventLoopTest, SuccessfulExitTest) {
+ auto loop1 = factory()->MakePrimary("primary");
+ auto exit_handle = factory()->MakeExitHandle();
+
+ loop1->OnRun([this, &exit_handle]() {
+ factory()->Exit();
+ // The second Exit() call should get ignored.
+ exit_handle->Exit(aos::Error::MakeUnexpectedError("Hello, World!"));
+ });
+
+ EXPECT_TRUE(factory()->Run().has_value());
+}
+
// Test GetWatcherSharedMemory in a few basic scenarios.
TEST_P(ShmEventLoopDeathTest, GetWatcherSharedMemory) {
auto generic_loop1 = factory()->MakePrimary("primary");