Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions amlip_cpp/src/cpp/node/StatusNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,17 @@ void StatusNode::stop_processing()
{
if (processing_)
{
logInfo(AMLIPCPP_NODE_STATUS, "Stop processing Status Node: " << *this << ".");
processing_ = false;
status_reader_->stop(); // This must awake thread and it must finish
process_thread_.join();

change_status_(types::StateKind::stopped);
}
else
{
throw utils::InconsistencyException(
STR_ENTRY << "Status node " << this << " is already stopped.");
}
}

void StatusNode::process_routine_(
Expand All @@ -149,13 +154,20 @@ void StatusNode::process_routine_(
return;
}

// Read data
types::StatusDataType status = status_reader_->read();
try
{
// Read data
types::StatusDataType status = status_reader_->read();

logDebug(AMLIPCPP_NODE_STATUS, "Status Node " << *this << " read data :" << status << ".");
logDebug(AMLIPCPP_NODE_STATUS, "Status Node " << *this << " read data :" << status << ".");

// Call callback
callback(status);
// Call callback
callback(status);
}
catch (const eprosima::utils::InconsistencyException& e)
{
std::cerr << e.what() << '\n';
}
}
}

Expand Down
13 changes: 9 additions & 4 deletions amlip_cpp/test/blackbox/communication/agent/agentTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,13 @@ TEST(agentTest, client_repeater_client)
std::atomic<unsigned int> n_jobs_solved(0u);

// Create Main in its own Thread
auto main_node_routine = [&n_jobs_solved]()
//__FLAG__
node::MainNode main_node("TestMainNode", 10);
//__FLAG__
//Added &main_node to the lambda capture list
auto main_node_routine = [&n_jobs_solved, &main_node]()
{
node::MainNode main_node("TestMainNode", 10);
//node::MainNode main_node("TestMainNode", 10);
for (unsigned int i = 0; i < test::N_JOBS_TO_SEND; i++)
{
std::string job_str = std::string("TEST_SEND") + std::to_string(i);
Expand All @@ -144,9 +148,10 @@ TEST(agentTest, client_repeater_client)
std::thread main_thread(main_node_routine);

// Create Computing in its own Thread
auto computing_node_routine = []()
node::ComputingNode computing_node("TestComputingNode", 11);
auto computing_node_routine = [&computing_node]()
{
node::ComputingNode computing_node("TestComputingNode", 11);
//node::ComputingNode computing_node("TestComputingNode", 11);
for (unsigned int i = 0; i < test::N_JOBS_TO_SEND; i++)
{
computing_node.process_job(test::process_routine);
Expand Down
2 changes: 2 additions & 0 deletions amlip_cpp/test/labels/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

# Set list of tests that can fail using ASAN
set_test_label_file(${CMAKE_CURRENT_SOURCE_DIR}/XASAN.list "xasan")
# Set list of tests that can fail using TSAN
set_test_label_file(${CMAKE_CURRENT_SOURCE_DIR}/XTSAN.list "xtsan")

# Set list of tests that can fail in windows
if (WIN32)
Expand Down
4 changes: 4 additions & 0 deletions amlip_cpp/test/labels/XTSAN.list
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
agentTest.client_repeater_client
agentTest.repeater_n_clients
modelManagerTimeoutReplyTest.ping_pong
MultiServiceTest.communicate_service_n_to_n
17 changes: 16 additions & 1 deletion amlip_cpp/test/unittest/node/statusNodeTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <gtest_aux.hpp>
#include <gtest/gtest.h>

#include <cpp_utils/Log.hpp>
#include <cpp_utils/wait/BooleanWaitHandler.hpp>
#include <cpp_utils/wait/IntWaitHandler.hpp>

Expand Down Expand Up @@ -102,19 +103,27 @@ TEST(StatusNodeTest, run_and_stop)
*/
TEST(StatusNodeTest, process_status_parent)
{
// Activate log
eprosima::utils::Log::SetVerbosity(eprosima::utils::Log::Kind::Info);

// Create Status Node
node::StatusNode status_node("TestStatusNode");

// Create a waiter so the Parent Node is not destroyed before the status node has received first message
eprosima::utils::event::IntWaitHandler waiter(0, true);

// Create a waiter to initialise parent_id before processing incoming data
eprosima::utils::event::BooleanWaitHandler waiter_id(false, true);

// Execute Status node and store the data that arrives
types::AmlipIdDataType parent_id;
std::vector<types::StatusDataType> data_arrived;
status_node.process_status_async(
[&data_arrived, &waiter, &parent_id](const types::StatusDataType& data)
[&data_arrived, &waiter_id, &waiter, &parent_id](const types::StatusDataType& data)
{
data_arrived.push_back(data);
// Wait for parent_id to be set
waiter_id.wait();
// Only open when data comes from target. Skip data coming from this participant.
if (data.id() == parent_id)
{
Expand All @@ -125,7 +134,10 @@ TEST(StatusNodeTest, process_status_parent)
{
// Create Parent Node to be destroyed afterwards
node::test::DummyNode dummy_node("TestParentNode", types::NodeKind::undetermined);

parent_id = dummy_node.id();
// Open the waiter_id
waiter_id.open();

// Wait so status reader has time to process the data
waiter.wait_greater_equal_than(1);
Expand Down Expand Up @@ -165,6 +177,9 @@ TEST(StatusNodeTest, process_status_parent)
*/
TEST(StatusNodeTest, process_status_state)
{
// Activate log
eprosima::utils::Log::SetVerbosity(eprosima::utils::Log::Kind::Info);

// Create Status Node
node::StatusNode status_node("TestStatusNode");
auto st_id = status_node.id();
Expand Down