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

fgerlits pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/nifi-minifi-cpp.git

commit e775efaffa7681d8543f8ff766546620fa6e1e74
Author: Gabor Gyimesi <[email protected]>
AuthorDate: Mon Mar 20 13:54:32 2023 +0100

    MINIFICPP-1713 Fix transient segfault in RepoTests
    
    Signed-off-by: Ferenc Gerlits <[email protected]>
    This closes #1537
---
 libminifi/test/rocksdb-tests/RepoTests.cpp | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/libminifi/test/rocksdb-tests/RepoTests.cpp 
b/libminifi/test/rocksdb-tests/RepoTests.cpp
index 19cd38f31..5d921fff0 100644
--- a/libminifi/test/rocksdb-tests/RepoTests.cpp
+++ b/libminifi/test/rocksdb-tests/RepoTests.cpp
@@ -344,7 +344,7 @@ TEST_CASE("Flush deleted flowfiles before shutdown", 
"[TestFFR7]") {
    public:
     explicit TestFlowFileRepository(const std::string& name)
       : FlowFileRepository(name, 
core::repository::FLOWFILE_REPOSITORY_DIRECTORY,
-                           10min, 
core::repository::MAX_FLOWFILE_REPOSITORY_STORAGE_SIZE, 1ms) {}
+                           10min, 
core::repository::MAX_FLOWFILE_REPOSITORY_STORAGE_SIZE, 50ms) {}
 
     void flush() override {
       FlowFileRepository::flush();
@@ -367,11 +367,12 @@ TEST_CASE("Flush deleted flowfiles before shutdown", 
"[TestFFR7]") {
   std::map<std::string, core::Connectable*> 
connectionMap{{connection->getUUIDStr(), connection.get()}};
   // initialize repository
   {
-    std::shared_ptr<TestFlowFileRepository> ff_repository = 
std::make_shared<TestFlowFileRepository>("flowFileRepository");
+    std::mutex flush_counter_mutex;
+    int flush_counter{0};
+    std::atomic<bool> stop{false};
 
-    std::atomic<int> flush_counter{0};
+    std::shared_ptr<TestFlowFileRepository> ff_repository = 
std::make_shared<TestFlowFileRepository>("flowFileRepository");
 
-    std::atomic<bool> stop{false};
     std::thread shutdown{[&] {
       while (!stop.load()) {
         std::this_thread::sleep_for(std::chrono::milliseconds{10});
@@ -380,8 +381,11 @@ TEST_CASE("Flush deleted flowfiles before shutdown", 
"[TestFFR7]") {
     }};
 
     ff_repository->onFlush_ = [&] {
-      if (++flush_counter != 1) {
-        return;
+      {
+        std::lock_guard<std::mutex> lock(flush_counter_mutex);
+        if (++flush_counter != 1) {
+          return;
+        }
       }
 
       for (int keyIdx = 0; keyIdx < 100; ++keyIdx) {
@@ -404,7 +408,9 @@ TEST_CASE("Flush deleted flowfiles before shutdown", 
"[TestFFR7]") {
     ff_repository->loadComponent(content_repo);
     ff_repository->start();
 
-    shutdown.join();
+    if (shutdown.joinable()) {
+      shutdown.join();
+    }
   }
 
   // check if the deleted flowfiles are indeed deleted

Reply via email to