You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by bb...@apache.org on 2021/03/18 15:47:48 UTC

[geode-native] branch develop updated: GEODE-9026: Fix race cond in RegisterKeysTest #2 (#769)

This is an automated email from the ASF dual-hosted git repository.

bbender pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode-native.git


The following commit(s) were added to refs/heads/develop by this push:
     new f03b5da  GEODE-9026: Fix race cond in RegisterKeysTest #2 (#769)
f03b5da is described below

commit f03b5dac93d25dc2f488eb9a5bba63f41a999092
Author: Mario Salazar de Torres <ma...@est.tech>
AuthorDate: Thu Mar 18 16:47:39 2021 +0100

    GEODE-9026: Fix race cond in RegisterKeysTest #2 (#769)
    
    - As it seems there is still a very rare race condition that might
       cause the test to fail.
     - If the listener is called before wait_for is called, the test fails
       due to timeout.
     - A flag and predicate has been added to tackle this race condition.
---
 cppcache/integration/test/RegisterKeysTest.cpp | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/cppcache/integration/test/RegisterKeysTest.cpp b/cppcache/integration/test/RegisterKeysTest.cpp
index 4b15615..2ce04a2 100644
--- a/cppcache/integration/test/RegisterKeysTest.cpp
+++ b/cppcache/integration/test/RegisterKeysTest.cpp
@@ -48,6 +48,8 @@ using apache::geode::client::IllegalStateException;
 using apache::geode::client::Region;
 using apache::geode::client::RegionShortcut;
 using ::testing::_;
+using ::testing::DoAll;
+using ::testing::InvokeWithoutArgs;
 
 ACTION_P(CvNotifyOne, cv) { cv->notify_one(); }
 
@@ -151,9 +153,13 @@ TEST(RegisterKeysTest, RegisterAllWithConsistencyDisabled) {
   }
 
   std::mutex cv_mutex;
+  bool destroyed = false;
   std::condition_variable cv;
   auto listener = std::make_shared<CacheListenerMock>();
-  EXPECT_CALL(*listener, afterDestroy(_)).Times(1).WillOnce(CvNotifyOne(&cv));
+  EXPECT_CALL(*listener, afterDestroy(_))
+      .Times(1)
+      .WillOnce(DoAll(InvokeWithoutArgs([&destroyed] { destroyed = true; }),
+                      CvNotifyOne(&cv)));
 
   {
     auto poolFactory =
@@ -175,8 +181,8 @@ TEST(RegisterKeysTest, RegisterAllWithConsistencyDisabled) {
 
   {
     std::unique_lock<std::mutex> lock(cv_mutex);
-    EXPECT_EQ(cv.wait_for(lock, std::chrono::minutes(1)),
-              std::cv_status::no_timeout);
+    EXPECT_TRUE(cv.wait_for(lock, std::chrono::minutes(1),
+                            [&destroyed] { return destroyed; }));
   }
 }