Skip to content

Commit 4aad61b

Browse files
committed
unit test for concurrent execution done
1 parent 9f942ff commit 4aad61b

File tree

3 files changed

+57
-22
lines changed

3 files changed

+57
-22
lines changed

tests/gtest_reactive_tree.cpp

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,14 @@ struct ComplexReactiveTree : testing::Test
6464
TEST_F(ComplexReactiveTree, ConditionsFalse)
6565
{
6666

67+
auto t0 = std::chrono::high_resolution_clock::now();
68+
69+
6770
condition_1.setBoolean(false);
6871
condition_2.setBoolean(false);
6972

7073
BT::NodeStatus state = root.executeTick();
7174

72-
state = root.executeTick();
73-
7475
ASSERT_EQ(NodeStatus::RUNNING, state);
7576
ASSERT_EQ(NodeStatus::RUNNING, fal_1.status());
7677
ASSERT_EQ(NodeStatus::FAILURE, condition_1.status());
@@ -97,29 +98,19 @@ TEST_F(ComplexReactiveTree, ConditionsFalse)
9798

9899
std::this_thread::sleep_for(milliseconds(300));
99100
condition_1.setBoolean(false);
100-
101+
std::cout << "Ticking..." << std::endl;
101102
state = root.executeTick();
103+
std::cout << "...done" << std::endl;
104+
102105

103-
ASSERT_EQ(NodeStatus::RUNNING, state);
104-
ASSERT_EQ(NodeStatus::RUNNING, fal_1.status());
105-
ASSERT_EQ(NodeStatus::FAILURE, condition_1.status());
106-
ASSERT_EQ(NodeStatus::RUNNING, action_1.status());
107-
ASSERT_EQ(NodeStatus::IDLE, fal_2.status());
108-
ASSERT_EQ(NodeStatus::IDLE, condition_2.status());
109-
ASSERT_EQ(NodeStatus::IDLE, action_2.status());
110106

111-
// std::this_thread::sleep_for(milliseconds(300));
107+
std::this_thread::sleep_for(milliseconds(300));
112108

113-
// condition_1.setBoolean(false);
109+
std::cout << action_1.startTimePoint().time_since_epoch().count() << std::endl;
110+
std::cout << action_2.stopTimePoint().time_since_epoch().count() << std::endl;
114111

115-
// state = root.executeTick();
112+
ASSERT_TRUE(action_1.startTimePoint().time_since_epoch().count() >
113+
action_2.stopTimePoint().time_since_epoch().count() );
116114

117-
// ASSERT_EQ(NodeStatus::RUNNING, state);
118-
// ASSERT_EQ(NodeStatus::RUNNING, fal_1.status());
119-
// ASSERT_EQ(NodeStatus::FAILURE, condition_1.status());
120-
// ASSERT_EQ(NodeStatus::RUNNING, action_1.status());
121-
// ASSERT_EQ(NodeStatus::IDLE, fal_2.status());
122-
// ASSERT_EQ(NodeStatus::IDLE, condition_2.status());
123-
// ASSERT_EQ(NodeStatus::IDLE, action_2.status());
124115

125116
}

tests/include/action_test_node.h

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,39 @@ class AsyncActionTest : public AsyncActionNode
5858
tick_count_ = 0;
5959
}
6060

61-
private:
61+
void setStartTimePoint(std::chrono::high_resolution_clock::time_point now)
62+
{
63+
std::cout << this->name() << " Setting Start Time: " << now.time_since_epoch().count() << std::endl;
64+
65+
start_time_ = now;
66+
}
67+
68+
std::chrono::high_resolution_clock::time_point startTimePoint() const
69+
{
70+
return start_time_;
71+
}
72+
73+
74+
void setStopTimePoint(std::chrono::high_resolution_clock::time_point now)
75+
{
76+
std::cout << this->name() << " Setting Stop Time: " << now.time_since_epoch().count() << std::endl;
77+
78+
stop_time_ = now;
79+
}
80+
81+
std::chrono::high_resolution_clock::time_point stopTimePoint() const
82+
{
83+
return stop_time_;
84+
}
85+
86+
87+
private:
6288
// using atomic because these variables might be accessed from different threads
6389
BT::Duration time_;
6490
std::atomic_bool boolean_value_;
6591
std::atomic<int> tick_count_;
6692
std::atomic_bool stop_loop_;
93+
std::chrono::high_resolution_clock::time_point start_time_, stop_time_;
6794
};
6895
}
6996

tests/src/action_test_node.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@
1313

1414
#include "action_test_node.h"
1515
#include <string>
16+
#include <ctime>
17+
#include <chrono>
18+
#include <time.h>
19+
#include <ratio>
20+
#include <iomanip>
21+
using namespace std::chrono;
1622

1723
BT::AsyncActionTest::AsyncActionTest(const std::string& name, BT::Duration deadline_ms) :
1824
AsyncActionNode(name, {})
@@ -30,17 +36,26 @@ BT::AsyncActionTest::~AsyncActionTest()
3036

3137
BT::NodeStatus BT::AsyncActionTest::tick()
3238
{
39+
setStartTimePoint(high_resolution_clock::now());
3340
setStatus(NodeStatus::RUNNING);
3441
using std::chrono::high_resolution_clock;
3542
tick_count_++;
3643
stop_loop_ = false;
3744
auto initial_time = high_resolution_clock::now();
3845

46+
3947
while (!stop_loop_ && high_resolution_clock::now() < initial_time + time_)
4048
{
41-
std::this_thread::sleep_for(std::chrono::milliseconds(1));
49+
// high_resolution_clock::time_point t2 = high_resolution_clock::now();
50+
51+
// std::cout << this->name() << " Running. Time: " << std::chrono::system_clock::to_time_t(t2) << std::endl;
52+
53+
54+
std::this_thread::sleep_for(std::chrono::milliseconds(100));
4255
}
4356

57+
setStopTimePoint(high_resolution_clock::now());
58+
4459
if (!stop_loop_)
4560
{
4661
return boolean_value_ ? NodeStatus::SUCCESS : NodeStatus::FAILURE;
@@ -51,6 +66,8 @@ BT::NodeStatus BT::AsyncActionTest::tick()
5166
}
5267
}
5368

69+
70+
5471
void BT::AsyncActionTest::halt()
5572
{
5673
stop_loop_ = true;

0 commit comments

Comments
 (0)