summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrii Kalinich (GitHub) <AKalinich@luxoft.com>2021-11-08 09:10:25 -0500
committerGitHub <noreply@github.com>2021-11-08 09:10:25 -0500
commita626f4205e5f6aaefb29b38336b75524d1a3643f (patch)
tree0ad9d7f2d06cced0f53464274436d2e22bfd20df
parent95512d7beba6be8598102be2ab49ed37197132ae (diff)
downloadsdl_core-a626f4205e5f6aaefb29b38336b75524d1a3643f.tar.gz
Fix unstable policy handler test (#3810)
* Fix unstable policy handler unit tests Looks like there was a missing async waiter in some unit tests so Async thread is still working when unit test is already finalized. That causes a core crashes and random unit tests failures. Was added `UnloadPolicyLibrary()` call to stop the async thread before finalizing the unit test. * Increase timeout for tests
-rw-r--r--src/components/application_manager/test/policy_handler_test.cc54
1 files changed, 25 insertions, 29 deletions
diff --git a/src/components/application_manager/test/policy_handler_test.cc b/src/components/application_manager/test/policy_handler_test.cc
index 353f3f05b7..50f2153616 100644
--- a/src/components/application_manager/test/policy_handler_test.cc
+++ b/src/components/application_manager/test/policy_handler_test.cc
@@ -127,7 +127,7 @@ class PolicyHandlerTest : public ::testing::Test {
, kGroupNameAllowed_("name_allowed")
, kGroupNameDisallowed_("name_disallowed")
, kCallsCount_(1u)
- , kTimeout_(1000u)
+ , kTimeout_(2000u)
, mock_message_helper_(*MockMessageHelper::message_helper_mock()) {
Mock::VerifyAndClearExpectations(&mock_message_helper_);
}
@@ -195,13 +195,15 @@ class PolicyHandlerTest : public ::testing::Test {
.WillByDefault(ReturnRef(mock_session_observer));
mock_app_ = std::make_shared<application_manager_test::MockApplication>();
+ ON_CALL(*mock_app_, IsRegistered()).WillByDefault(Return(true));
}
virtual void TearDown() OVERRIDE {
- Mock::VerifyAndClearExpectations(&mock_message_helper_);
+ EXPECT_TRUE(policy_handler_.UnloadPolicyLibrary());
ON_CALL(
mock_event_dispatcher_,
remove_observer(_, testing::Matcher<event_engine::EventObserver&>(_)));
+ Mock::VerifyAndClearExpectations(&mock_message_helper_);
}
void ChangePolicyManagerToMock() {
@@ -2268,34 +2270,26 @@ TEST_F(PolicyHandlerTest,
EXPECT_CALL(*mock_app_, policy_app_id()).WillOnce(Return(kPolicyAppId_));
EXPECT_CALL(*mock_app_, device()).WillOnce(Return(device));
- auto waiter_first = TestAsyncWaiter::createInstance();
-#ifdef EXTERNAL_PROPRIETARY_MODE
- EXPECT_CALL(*mock_policy_manager_, SetUserConsentForApp(_, _))
- .WillOnce(NotifyTestAsyncWaiter(waiter_first));
-#else
- EXPECT_CALL(*mock_policy_manager_, SetUserConsentForApp(_))
- .WillOnce(NotifyTestAsyncWaiter(waiter_first));
-#endif
ExternalConsentStatusItem item(1u, 1u, kStatusOn);
ExternalConsentStatus external_consent_status;
external_consent_status.insert(item);
+ auto waiter = TestAsyncWaiter::createInstance();
#ifdef EXTERNAL_PROPRIETARY_MODE
- auto waiter_second = TestAsyncWaiter::createInstance();
-
EXPECT_CALL(*mock_policy_manager_,
SetExternalConsentStatus(external_consent_status))
- .WillOnce(Return(true));
+ .WillOnce(DoAll(NotifyTestAsyncWaiter(waiter), Return(true)));
+
policy_handler_.OnAppPermissionConsent(
kConnectionKey_, permissions, external_consent_status);
#else
- policy_handler_.OnAppPermissionConsent(kConnectionKey_, permissions);
+ EXPECT_CALL(*mock_policy_manager_, SetUserConsentForApp(_))
+ .WillOnce(NotifyTestAsyncWaiter(waiter));
+ policy_handler_.OnAppPermissionConsent(kConnectionKey_, permissions);
#endif
- EXPECT_TRUE(waiter_first->WaitFor(kCallsCount_, kTimeout_));
-#ifdef EXTERNAL_PROPRIETARY_MODE
- EXPECT_TRUE(waiter_second->WaitFor(kCallsCount_, kTimeout_));
-#endif
+
+ EXPECT_TRUE(waiter->WaitFor(kCallsCount_, kTimeout_));
}
TEST_F(PolicyHandlerTest,
@@ -2401,6 +2395,7 @@ TEST_F(PolicyHandlerTest,
EXPECT_CALL(*mock_app_, device()).WillRepeatedly(Return(1u));
EXPECT_CALL(*mock_app_, policy_app_id())
.WillRepeatedly(Return(kPolicyAppId_));
+ EXPECT_CALL(*mock_app_, mac_address()).WillRepeatedly(ReturnRef(kMacAddr_));
EXPECT_CALL(
mock_session_observer,
@@ -2418,22 +2413,21 @@ TEST_F(PolicyHandlerTest,
ExternalConsentStatusItem item = {1u, 1u, kStatusOn};
ExternalConsentStatus external_consent_status;
external_consent_status.insert(item);
-#ifdef EXTERNAL_PROPRIETARY_MODE
- auto waiter = TestAsyncWaiter::createInstance();
+ auto waiter = TestAsyncWaiter::createInstance();
+#ifdef EXTERNAL_PROPRIETARY_MODE
EXPECT_CALL(*mock_policy_manager_,
SetExternalConsentStatus(external_consent_status))
.WillOnce(DoAll(NotifyTestAsyncWaiter(waiter), Return(true)));
policy_handler_.OnAppPermissionConsent(
invalid_connection_key, permissions, external_consent_status);
#else
+ EXPECT_CALL(*mock_policy_manager_, SetUserConsentForApp(_))
+ .WillOnce(NotifyTestAsyncWaiter(waiter));
policy_handler_.OnAppPermissionConsent(invalid_connection_key, permissions);
#endif
- Mock::VerifyAndClearExpectations(mock_app_.get());
-#ifdef EXTERNAL_PROPRIETARY_MODE
EXPECT_TRUE(waiter->WaitFor(kCallsCount_, kTimeout_));
-#endif
}
TEST_F(PolicyHandlerTest,
@@ -2463,6 +2457,7 @@ TEST_F(PolicyHandlerTest,
EXPECT_CALL(*mock_app_, device()).WillRepeatedly(Return(1u));
EXPECT_CALL(*mock_app_, policy_app_id())
.WillRepeatedly(Return(kPolicyAppId_));
+ EXPECT_CALL(*mock_app_, mac_address()).WillRepeatedly(ReturnRef(kMacAddr_));
EXPECT_CALL(
mock_session_observer,
@@ -2480,24 +2475,25 @@ TEST_F(PolicyHandlerTest,
ExternalConsentStatusItem item = {1u, 1u, kStatusOn};
ExternalConsentStatus external_consent_status;
external_consent_status.insert(item);
-#ifdef EXTERNAL_PROPRIETARY_MODE
- auto waiter = TestAsyncWaiter::createInstance();
+ auto waiter = TestAsyncWaiter::createInstance();
+#ifdef EXTERNAL_PROPRIETARY_MODE
ON_CALL(*mock_policy_manager_, IsNeedToUpdateExternalConsentStatus(_))
.WillByDefault(Return(false));
EXPECT_CALL(*mock_policy_manager_,
SetExternalConsentStatus(external_consent_status))
.WillOnce(Return(true));
+ EXPECT_CALL(*mock_policy_manager_, SetUserConsentForApp(_, _))
+ .WillOnce(NotifyTestAsyncWaiter(waiter));
policy_handler_.OnAppPermissionConsent(
invalid_connection_key, permissions, external_consent_status);
#else
+ EXPECT_CALL(*mock_policy_manager_, SetUserConsentForApp(_))
+ .WillOnce(NotifyTestAsyncWaiter(waiter));
policy_handler_.OnAppPermissionConsent(invalid_connection_key, permissions);
#endif
- Mock::VerifyAndClearExpectations(mock_app_.get());
-#ifdef EXTERNAL_PROPRIETARY_MODE
- EXPECT_FALSE(waiter->WaitFor(kCallsCount_, kTimeout_));
-#endif
+ EXPECT_TRUE(waiter->WaitFor(kCallsCount_, kTimeout_));
}
ACTION_P(SetEndpoint, endpoint) {