From 6d37b0aeb27701c9a1a250df7e4bde912a5fa448 Mon Sep 17 00:00:00 2001 From: "Maksym Ked (GitHub)" Date: Wed, 19 Sep 2018 16:41:45 +0300 Subject: fixing resumption smoke test --- .../include/application_manager/message_helper.h | 2 +- .../application_manager/resumption/resumption_data_processor.h | 3 +++ .../application_manager/src/message_helper/message_helper.cc | 8 ++++---- .../src/resumption/resumption_data_processor.cc | 8 ++++++-- .../test/include/application_manager/mock_message_helper.h | 2 +- .../test/message_helper/message_helper_test.cc | 10 ++++++---- src/components/application_manager/test/mock_message_helper.cc | 4 ++-- .../application_manager/test/resumption/resume_ctrl_test.cc | 2 +- 8 files changed, 24 insertions(+), 15 deletions(-) diff --git a/src/components/application_manager/include/application_manager/message_helper.h b/src/components/application_manager/include/application_manager/message_helper.h index e1ba083db6..3f6f869514 100644 --- a/src/components/application_manager/include/application_manager/message_helper.h +++ b/src/components/application_manager/include/application_manager/message_helper.h @@ -372,7 +372,7 @@ class MessageHelper { static void SendAddSubMenuRequestToHMI(ApplicationConstSharedPtr app, ApplicationManager& app_mngr); static smart_objects::SmartObjectList CreateAddSubMenuRequestsToHMI( - ApplicationConstSharedPtr app, const uint32_t correlation_id); + ApplicationConstSharedPtr app, ApplicationManager& app_mngr); /* * @brief Creates BasicCommunication.OnAppUnregistered notification diff --git a/src/components/application_manager/include/application_manager/resumption/resumption_data_processor.h b/src/components/application_manager/include/application_manager/resumption/resumption_data_processor.h index 434bd9ed4b..aa72423173 100644 --- a/src/components/application_manager/include/application_manager/resumption/resumption_data_processor.h +++ b/src/components/application_manager/include/application_manager/resumption/resumption_data_processor.h @@ -40,6 +40,7 @@ #include "application_manager/application.h" #include "application_manager/event_engine/event_observer.h" #include "application_manager/resumption/resume_ctrl.h" +#include "utils/lock.h" namespace resumption { @@ -300,6 +301,8 @@ class ResumptionDataProcessor : public app_mngr::event_engine::EventObserver { /** * @brief A map of the IDs and Application Resumption Status for these ID **/ + + sync_primitives::Lock resumption_data_procesoor_lock_; app_mngr::ApplicationManager& application_manager_; std::map resumption_status_; std::map register_callbacks_; diff --git a/src/components/application_manager/src/message_helper/message_helper.cc b/src/components/application_manager/src/message_helper/message_helper.cc index 673e066f4e..206043441c 100644 --- a/src/components/application_manager/src/message_helper/message_helper.cc +++ b/src/components/application_manager/src/message_helper/message_helper.cc @@ -1689,7 +1689,7 @@ void MessageHelper::SendAddSubMenuRequestToHMI(ApplicationConstSharedPtr app, } smart_objects::SmartObjectList requests = - CreateAddSubMenuRequestsToHMI(app, app_mngr.GetNextHMICorrelationID()); + CreateAddSubMenuRequestsToHMI(app, app_mngr); for (smart_objects::SmartObjectList::iterator it = requests.begin(); it != requests.end(); ++it) { @@ -1698,14 +1698,14 @@ void MessageHelper::SendAddSubMenuRequestToHMI(ApplicationConstSharedPtr app, } smart_objects::SmartObjectList MessageHelper::CreateAddSubMenuRequestsToHMI( - ApplicationConstSharedPtr app, const uint32_t correlation_id) { + ApplicationConstSharedPtr app, ApplicationManager& app_mngr) { smart_objects::SmartObjectList requsets; const DataAccessor accessor = app->sub_menu_map(); const SubMenuMap& sub_menu = accessor.GetData(); SubMenuMap::const_iterator i = sub_menu.begin(); for (; sub_menu.end() != i; ++i) { - smart_objects::SmartObjectSPtr ui_sub_menu = - CreateMessageForHMI(hmi_apis::messageType::request, correlation_id); + smart_objects::SmartObjectSPtr ui_sub_menu = CreateMessageForHMI( + hmi_apis::messageType::request, app_mngr.GetNextHMICorrelationID()); if (!ui_sub_menu) { return requsets; } diff --git a/src/components/application_manager/src/resumption/resumption_data_processor.cc b/src/components/application_manager/src/resumption/resumption_data_processor.cc index 7a98e93173..5912fe3c2a 100644 --- a/src/components/application_manager/src/resumption/resumption_data_processor.cc +++ b/src/components/application_manager/src/resumption/resumption_data_processor.cc @@ -176,7 +176,10 @@ void ResumptionDataProcessor::on_event(const event_engine::Event& event) { CheckVehicleDataResponse(request_ptr->message, response, status); } - list_of_sent_requests.erase(request_ptr); + { + sync_primitives::AutoLock lock(resumption_data_procesoor_lock_); + list_of_sent_requests.erase(request_ptr); + } if (!list_of_sent_requests.empty()) { LOG4CXX_DEBUG(logger_, @@ -234,6 +237,7 @@ void ResumptionDataProcessor::WaitForResponse( << request.request_ids.correlation_id); subscribe_on_event(request.request_ids.function_id, request.request_ids.correlation_id); + sync_primitives::AutoLock lock(resumption_data_procesoor_lock_); resumption_status_[app_id].list_of_sent_requests.push_back(request); request_app_ids_.insert(std::make_pair(request.request_ids, app_id)); } @@ -331,7 +335,7 @@ void ResumptionDataProcessor::AddSubmenues( } ProcessHMIRequests(MessageHelper::CreateAddSubMenuRequestsToHMI( - application, application_manager_.GetNextHMICorrelationID())); + application, application_manager_)); } void ResumptionDataProcessor::DeleteSubmenues( diff --git a/src/components/application_manager/test/include/application_manager/mock_message_helper.h b/src/components/application_manager/test/include/application_manager/mock_message_helper.h index fdb744b048..73be350611 100644 --- a/src/components/application_manager/test/include/application_manager/mock_message_helper.h +++ b/src/components/application_manager/test/include/application_manager/mock_message_helper.h @@ -182,7 +182,7 @@ class MockMessageHelper { void(uint32_t app_id, ApplicationManager& app_mngr)); MOCK_METHOD2(CreateAddSubMenuRequestsToHMI, smart_objects::SmartObjectList(ApplicationConstSharedPtr app, - const uint32_t correlation_id)); + ApplicationManager& app_mngr)); MOCK_METHOD2(CreateAddCommandRequestToHMI, smart_objects::SmartObjectList(ApplicationConstSharedPtr app, ApplicationManager& app_mngr)); diff --git a/src/components/application_manager/test/message_helper/message_helper_test.cc b/src/components/application_manager/test/message_helper/message_helper_test.cc index 72d62f018b..e65554c9a4 100644 --- a/src/components/application_manager/test/message_helper/message_helper_test.cc +++ b/src/components/application_manager/test/message_helper/message_helper_test.cc @@ -393,9 +393,10 @@ TEST(MessageHelperTestCreate, CreateAddSubMenuRequestToHMI_SendObject_Equal) { EXPECT_CALL(*appSharedMock, sub_menu_map()).WillOnce(Return(data_accessor)); EXPECT_CALL(*appSharedMock, app_id()).Times(AtLeast(1)).WillOnce(Return(1u)); - const uint32_t cor_id = 0u; + application_manager_test::MockApplicationManager mock_application_manager; smart_objects::SmartObjectList ptr = - MessageHelper::CreateAddSubMenuRequestsToHMI(appSharedMock, cor_id); + MessageHelper::CreateAddSubMenuRequestsToHMI(appSharedMock, + mock_application_manager); EXPECT_FALSE(ptr.empty()); @@ -423,9 +424,10 @@ TEST(MessageHelperTestCreate, EXPECT_CALL(*appSharedMock, sub_menu_map()).WillOnce(Return(data_accessor)); - const uint32_t cor_id = 0u; + application_manager_test::MockApplicationManager mock_application_manager; smart_objects::SmartObjectList ptr = - MessageHelper::CreateAddSubMenuRequestsToHMI(appSharedMock, cor_id); + MessageHelper::CreateAddSubMenuRequestsToHMI(appSharedMock, + mock_application_manager); EXPECT_TRUE(ptr.empty()); } diff --git a/src/components/application_manager/test/mock_message_helper.cc b/src/components/application_manager/test/mock_message_helper.cc index c4b9719eec..815ea7565f 100644 --- a/src/components/application_manager/test/mock_message_helper.cc +++ b/src/components/application_manager/test/mock_message_helper.cc @@ -310,9 +310,9 @@ void MessageHelper::SendOnResumeAudioSourceToHMI(const uint32_t app_id, } smart_objects::SmartObjectList MessageHelper::CreateAddSubMenuRequestsToHMI( - ApplicationConstSharedPtr app, const uint32_t correlation_id) { + ApplicationConstSharedPtr app, ApplicationManager& app_mngr) { return MockMessageHelper::message_helper_mock() - ->CreateAddSubMenuRequestsToHMI(app, correlation_id); + ->CreateAddSubMenuRequestsToHMI(app, app_mngr); } smart_objects::SmartObjectList MessageHelper::CreateAddCommandRequestToHMI( diff --git a/src/components/application_manager/test/resumption/resume_ctrl_test.cc b/src/components/application_manager/test/resumption/resume_ctrl_test.cc index f9ca70197d..49e1713d75 100644 --- a/src/components/application_manager/test/resumption/resume_ctrl_test.cc +++ b/src/components/application_manager/test/resumption/resume_ctrl_test.cc @@ -349,7 +349,7 @@ TEST_F(ResumeCtrlTest, StartResumption_AppWithSubmenues) { EXPECT_CALL(mock_app_mngr_, GetNextHMICorrelationID()) .WillRepeatedly(Return(kCorId_)); EXPECT_CALL(*application_manager::MockMessageHelper::message_helper_mock(), - CreateAddSubMenuRequestsToHMI(_, kCorId_)) + CreateAddSubMenuRequestsToHMI(_, _)) .WillRepeatedly(Return(requests)); EXPECT_CALL(*application_manager::MockMessageHelper::message_helper_mock(), -- cgit v1.2.1