lordgamez commented on code in PR #1411:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1411#discussion_r958409018
##########
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:
We put 3 different resources in the queue 1, 2 and 3, and if we add those to
the set and the set size is 3 then we can be sure that none of the resources
was reused, but new resources were created for every instance. I mean you are
right that asserting on the `"Number of instances: 3"` is kind of the same, but
I would not rely on log messages if not necessary.
--
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]