OSDN Git Service

Minor improvements to Module, Reactor, StackManager
authorHansong Zhang <hsz@google.com>
Tue, 3 Mar 2020 23:05:34 +0000 (15:05 -0800)
committerHansong Zhang <hsz@google.com>
Wed, 4 Mar 2020 19:35:36 +0000 (11:35 -0800)
Add some logs. Fix the timeout in StackManager because some systems are
slow.

Test: bluetooth_test_gd
Change-Id: Idd3f0b14fd66dde250eadc84c1d5cad10664154d

gd/module.cc
gd/module_unittest.cc
gd/os/linux_generic/reactor.cc
gd/stack_manager.cc

index 2136b82..c2afada 100644 (file)
@@ -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++) {
index 1ee1a8d..817e548 100644 (file)
@@ -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();
 }
 
index 44b13d8..0f3f949 100644 (file)
@@ -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;
 }
 
index 9c01d56..06a7ba2 100644 (file)
@@ -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_;
 }