summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Lais Andrade <lsandrade@google.com> 2020-09-07 10:13:34 +0000
committer Lais Andrade <lsandrade@google.com> 2020-09-07 18:58:44 +0000
commita3c8a600fe6b218f528edac793481e8f60e47d24 (patch)
tree1c829b4d42183a18dbee949a780b1ead9c83c192
parentad321cd93840d11440f80f49452d4631697033e5 (diff)
Fix flaky IThermalListenerTest
Lock mutex before triggering the operation so listener will always be processed after the call to mCondition.wait_for. Bug: 167843342 Test: atest libpowermanager_test Change-Id: I0b1a87f14f8d0efe52c6927b1b3a00d5bb7ed8a1
-rw-r--r--services/powermanager/tests/IThermalManagerTest.cpp5
1 files changed, 4 insertions, 1 deletions
diff --git a/services/powermanager/tests/IThermalManagerTest.cpp b/services/powermanager/tests/IThermalManagerTest.cpp
index 575b9ee1c4..b62be5f5d4 100644
--- a/services/powermanager/tests/IThermalManagerTest.cpp
+++ b/services/powermanager/tests/IThermalManagerTest.cpp
@@ -86,12 +86,14 @@ void IThermalServiceTest::SetUp() {
EXPECT_NE(binder, nullptr);
mThermalSvc = interface_cast<IThermalService>(binder);
EXPECT_NE(mThermalSvc, nullptr);
+ // Lock mutex for operation, so listener will only be processed after wait_for is called
+ std::unique_lock<std::mutex> lock(mMutex);
bool success = false;
binder::Status ret = mThermalSvc->registerThermalStatusListener(this, &success);
+ // Check the result
ASSERT_TRUE(success);
ASSERT_TRUE(ret.isOk());
// Wait for listener called after registration, shouldn't timeout
- std::unique_lock<std::mutex> lock(mMutex);
EXPECT_NE(mCondition.wait_for(lock, 1s), std::cv_status::timeout);
}
@@ -111,6 +113,7 @@ class IThermalListenerTest : public IThermalServiceTest, public testing::WithPar
TEST_P(IThermalListenerTest, TestListener) {
int level = GetParam();
+ // Lock mutex for operation, so listener will only be processed after wait_for is called
std::unique_lock<std::mutex> lock(mMutex);
// Set the override thermal status
setThermalOverride(level);