moveit2
The MoveIt Motion Planning Framework for ROS 2.
Public Member Functions | Protected Attributes | List of all members
testing::AsyncTest Class Reference

Test class that allows the handling of asynchronous test objects. More...

#include <async_test.h>

Inheritance diagram for testing::AsyncTest:
Inheritance graph
[legend]

Public Member Functions

void triggerClearEvent (const std::string &event)
 Triggers a clear event. If a call to barricade is currently pending it will unblock as soon as all clear events are triggered. Else the event is put on the waitlist. This waitlist is emptied upon a call to barricade. More...
 
bool barricade (const std::string &clear_event, const int timeout_ms=-1)
 Will block until the event given by clear_event is triggered or a timeout is reached. Unblocks immediately, if the event was on the waitlist. More...
 
bool barricade (std::initializer_list< std::string > clear_events, const int timeout_ms=-1)
 Will block until all events given by clear_events are triggered or a timeout is reached. Events on the waitlist are taken into account, too. More...
 

Protected Attributes

std::mutex m_
 
std::condition_variable cv_
 
std::set< std::string > clear_events_ {}
 
std::set< std::string > waitlist_ {}
 

Detailed Description

Test class that allows the handling of asynchronous test objects.

The class provides the two basic functions AsyncTest::barricade and AsyncTest::triggerClearEvent. During the test setup gates between the steps with one or more clear events. Allow passing on by calling triggerClearEvent after a test.

Usage:
Suppose you want to test a function that calls another function asynchronously, like the following example:

void asyncCall(std::function<void()> fun)
{
std::thread t(fun);
t.detach();
}

You expect that fun gets called, so your test thread has to wait for the completion, else it would fail. This can be achieved via:

class MyTest : public testing::Test, public testing::AsyncTest
{
public:
MOCK_METHOD0(myMethod, void());
};
TEST_F(MyTest, testCase)
{
EXPECT_CALL(*this, myMethod()).Times(1).WillOnce(ACTION_OPEN_BARRIER_VOID("myMethod"));
const int timeout_ms {100};
asyncCall([this]{ myMethod(); });
BARRIER("myMethod", timeout_ms) << "Timed-out waiting for myMethod call.";
}
#define ACTION_OPEN_BARRIER_VOID(str)
Definition: async_test.h:116
#define BARRIER(...)
Definition: async_test.h:108
Test class that allows the handling of asynchronous test objects.
Definition: async_test.h:70
TEST_F(BulletCollisionDetectionTester, DISABLED_ContinuousCollisionSelf)
Continuous self collision checks are not supported yet by the bullet integration.

Definition at line 69 of file async_test.h.

Member Function Documentation

◆ barricade() [1/2]

bool testing::AsyncTest::barricade ( const std::string &  clear_event,
const int  timeout_ms = -1 
)
inline

Will block until the event given by clear_event is triggered or a timeout is reached. Unblocks immediately, if the event was on the waitlist.

Parameters
clear_eventEvent that allows the test to pass on
timeout_msTimeout [ms] (optional).
Returns
True if the event was triggered, false otherwise.

Definition at line 134 of file async_test.h.

◆ barricade() [2/2]

bool testing::AsyncTest::barricade ( std::initializer_list< std::string >  clear_events,
const int  timeout_ms = -1 
)
inline

Will block until all events given by clear_events are triggered or a timeout is reached. Events on the waitlist are taken into account, too.

Parameters
clear_eventsList of events that allow the test to pass on
timeout_msTimeout [ms] (optional).
Returns
True if all events were triggered, false otherwise.

Definition at line 139 of file async_test.h.

◆ triggerClearEvent()

void testing::AsyncTest::triggerClearEvent ( const std::string &  event)
inline

Triggers a clear event. If a call to barricade is currently pending it will unblock as soon as all clear events are triggered. Else the event is put on the waitlist. This waitlist is emptied upon a call to barricade.

Parameters
eventThe event that is triggered

Definition at line 118 of file async_test.h.

Member Data Documentation

◆ clear_events_

std::set<std::string> testing::AsyncTest::clear_events_ {}
protected

Definition at line 103 of file async_test.h.

◆ cv_

std::condition_variable testing::AsyncTest::cv_
protected

Definition at line 102 of file async_test.h.

◆ m_

std::mutex testing::AsyncTest::m_
protected

Definition at line 101 of file async_test.h.

◆ waitlist_

std::set<std::string> testing::AsyncTest::waitlist_ {}
protected

Definition at line 104 of file async_test.h.


The documentation for this class was generated from the following file: