fgerlits commented on code in PR #1411:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1411#discussion_r958253268


##########
libminifi/test/unit/ResourceQueueTests.cpp:
##########
@@ -28,19 +28,21 @@ using namespace std::literals::chrono_literals;
 
 namespace org::apache::nifi::minifi::utils::testing {
 
-TEST_CASE("maximum_number_of_creatable_resources", "[utils::ResourceQueue]") {
+TEST_CASE("Limiting resource queue to a maximum of 2 resources", 
"[utils::ResourceQueue]") {
   std::shared_ptr<core::logging::Logger> 
logger_{core::logging::LoggerFactory<ResourceQueue<int>>::getLogger()};
   LogTestController::getInstance().setTrace<ResourceQueue<int>>();
 
+  std::mutex resources_created_mutex;
   std::set<int> resources_created;
 
   auto worker = [&](int value, const std::shared_ptr<ResourceQueue<int>>& 
resource_queue) {
     auto resource = resource_queue->getResource([value]{return 
std::make_unique<int>(value);});
     std::this_thread::sleep_for(10ms);
+    std::lock_guard<std::mutex> lock(resources_created_mutex);
     resources_created.emplace(*resource);
   };
 
-  SECTION("Maximum 2 resources") {
+  SECTION("") {

Review Comment:
   there is no point of having a SECTION if there is only one, I would remove it



##########
libminifi/test/unit/ResourceQueueTests.cpp:
##########
@@ -53,23 +55,26 @@ TEST_CASE("maximum_number_of_creatable_resources", 
"[utils::ResourceQueue]") {
     CHECK(!resources_created.empty());
     CHECK(resources_created.size() <= 2);
   }
+}
 
-  SECTION("No Maximum resources") {
-    LogTestController::getInstance().clear();
-    auto resource_queue = ResourceQueue<int>::create(std::nullopt, logger_);
-    std::thread thread_one{[&] { worker(1, resource_queue); }};
-    std::thread thread_two{[&] { worker(2, resource_queue); }};
-    std::thread thread_three{[&] { worker(3, resource_queue); }};
+TEST_CASE("Resource limitation is not set to the resource queue", 
"[utils::ResourceQueue]") {
+  std::shared_ptr<core::logging::Logger> 
logger_{core::logging::LoggerFactory<ResourceQueue<int>>::getLogger()};
+  LogTestController::getInstance().setTrace<ResourceQueue<int>>();
+  LogTestController::getInstance().clear();
+  auto resource_queue = ResourceQueue<int>::create(std::nullopt, logger_);
+  std::set<int> resources_created;
 
-    thread_one.join();
-    thread_two.join();
-    thread_three.join();
+  auto resource_one = resource_queue->getResource([]{return 
std::make_unique<int>(1);});
+  auto resource_two = resource_queue->getResource([]{return 
std::make_unique<int>(2);});
+  auto resource_three = resource_queue->getResource([]{return 
std::make_unique<int>(3);});
 
-    CHECK(!resources_created.empty());
-    CHECK(!LogTestController::getInstance().contains("Waiting for resource", 
0ms));
-    CHECK(LogTestController::getInstance().contains("Number of instances: 3", 
0ms));
-    CHECK(resources_created.size() <= 3);
-  }
+  resources_created.emplace(*resource_one);
+  resources_created.emplace(*resource_two);
+  resources_created.emplace(*resource_three);

Review Comment:
   I don't think we need the `resources_created` set, as the `resource_x` 
variables hold onto the wrappers already.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to