instance->second->handler_->Clear();
instance->second->handler_->WaitUntilStopped(kModuleStopTimeout);
instance->second->Stop();
-
+ }
+ for (auto it = start_order_.rbegin(); it != start_order_.rend(); it++) {
+ auto instance = started_modules_.find(*it);
+ ASSERT(instance != started_modules_.end());
delete instance->second->handler_;
delete instance->second;
started_modules_.erase(instance);
*/
#include "module.h"
+#include "os/handler.h"
+#include "os/thread.h"
#include "gtest/gtest.h"
Thread* thread_;
};
+os::Handler* test_module_no_dependency_handler = nullptr;
+
class TestModuleNoDependency : public Module {
public:
static const ModuleFactory Factory;
void Start() override {
// A module is not considered started until Start() finishes
EXPECT_FALSE(GetModuleRegistry()->IsStarted<TestModuleNoDependency>());
+ test_module_no_dependency_handler = GetHandler();
}
void Stop() override {
// A module is not considered stopped until after Stop() finishes
+ test_module_no_dependency_handler = nullptr;
EXPECT_TRUE(GetModuleRegistry()->IsStarted<TestModuleNoDependency>());
}
};
return new TestModuleNoDependency();
});
+os::Handler* test_module_one_dependency_handler = nullptr;
+
class TestModuleOneDependency : public Module {
public:
static const ModuleFactory Factory;
// A module is not considered started until Start() finishes
EXPECT_FALSE(GetModuleRegistry()->IsStarted<TestModuleOneDependency>());
+ test_module_one_dependency_handler = GetHandler();
}
void Stop() override {
+ test_module_one_dependency_handler = GetHandler();
EXPECT_TRUE(GetModuleRegistry()->IsStarted<TestModuleNoDependency>());
// A module is not considered stopped until after Stop() finishes
EXPECT_FALSE(registry_->IsStarted<TestModuleTwoDependencies>());
}
+void post_two_module_one_handler() {
+ std::this_thread::sleep_for(std::chrono::milliseconds(100));
+ test_module_one_dependency_handler->Post(common::BindOnce([] { FAIL(); }));
+}
+
+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));
+ registry_->StopAll();
+}
+
} // namespace
} // namespace bluetooth