Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 374c1df4 authored by Automerger Merge Worker's avatar Automerger Merge Worker
Browse files

Minor improvements to Module, Reactor, StackManager am: 7421ab60 am:...

Minor improvements to Module, Reactor, StackManager am: 7421ab60 am: 18177f68 am: 64930ac3 am: 60a414e5

Change-Id: I0d36c2f836e34ae072f5f050b753a831eaea6130
parents 42848c86 60a414e5
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -95,8 +95,10 @@ void ModuleRegistry::StopAll() {
    ASSERT(instance != started_modules_.end());

    // Clear the handler before stopping the module to allow it to shut down gracefully.
    LOG_INFO("Stopping Handler of Module %s", instance->second->ToString().c_str());
    instance->second->handler_->Clear();
    instance->second->handler_->WaitUntilStopped(kModuleStopTimeout);
    LOG_INFO("Stopping Module %s", instance->second->ToString().c_str());
    instance->second->Stop();
  }
  for (auto it = start_order_.rbegin(); it != start_order_.rend(); it++) {
+5 −2
Original line number Diff line number Diff line
@@ -20,6 +20,9 @@

#include "gtest/gtest.h"

#include <functional>
#include <future>

using ::bluetooth::os::Thread;

namespace bluetooth {
@@ -207,7 +210,7 @@ TEST_F(ModuleTest, two_dependencies) {
  EXPECT_FALSE(registry_->IsStarted<TestModuleTwoDependencies>());
}

void post_two_module_one_handler() {
void post_to_module_one_handler() {
  std::this_thread::sleep_for(std::chrono::milliseconds(100));
  test_module_one_dependency_handler->Post(common::BindOnce([] { FAIL(); }));
}
@@ -216,7 +219,7 @@ TEST_F(ModuleTest, shutdown_with_unhandled_callback) {
  ModuleList list;
  list.add<TestModuleOneDependency>();
  registry_->Start(&list, thread_);
  test_module_no_dependency_handler->Post(common::BindOnce(&post_two_module_one_handler));
  test_module_no_dependency_handler->Post(common::BindOnce(&post_to_module_one_handler));
  registry_->StopAll();
}

+3 −0
Original line number Diff line number Diff line
@@ -197,6 +197,9 @@ bool Reactor::WaitForUnregisteredReactable(std::chrono::milliseconds timeout) {
    return true;
  }
  auto stop_status = executing_reactable_finished_->wait_for(timeout);
  if (stop_status != std::future_status::ready) {
    LOG_ERROR("Unregister reactable timed out");
  }
  return stop_status == std::future_status::ready;
}

+2 −2
Original line number Diff line number Diff line
@@ -57,11 +57,11 @@ void StackManager::ShutDown() {
  auto future = promise.get_future();
  handler_->Post(common::BindOnce(&StackManager::handle_shut_down, common::Unretained(this), std::move(promise)));

  auto stop_status = future.wait_for(std::chrono::seconds(3));
  auto stop_status = future.wait_for(std::chrono::seconds(5));
  ASSERT_LOG(stop_status == std::future_status::ready, "Can't stop stack");

  handler_->Clear();
  handler_->WaitUntilStopped(std::chrono::milliseconds(20));
  handler_->WaitUntilStopped(std::chrono::milliseconds(2000));
  delete handler_;
  delete management_thread_;
}