In test_events, wait for discovery to be complete bidirectionally before moving on (#451)
Signed-off-by: Emerson Knapp <eknapp@amazon.com>
This commit is contained in:
parent
5f0d331712
commit
d55f015296
1 changed files with 20 additions and 14 deletions
|
@ -28,7 +28,6 @@
|
||||||
#include "osrf_testing_tools_cpp/scope_exit.hpp"
|
#include "osrf_testing_tools_cpp/scope_exit.hpp"
|
||||||
|
|
||||||
using namespace std::chrono_literals;
|
using namespace std::chrono_literals;
|
||||||
using std::chrono::milliseconds;
|
|
||||||
using std::chrono::seconds;
|
using std::chrono::seconds;
|
||||||
using std::chrono::duration_cast;
|
using std::chrono::duration_cast;
|
||||||
|
|
||||||
|
@ -43,6 +42,9 @@ constexpr seconds MAX_WAIT_PER_TESTCASE = 10s;
|
||||||
# define CLASSNAME(NAME, SUFFIX) NAME
|
# define CLASSNAME(NAME, SUFFIX) NAME
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define EXPECT_OK(varname) EXPECT_EQ(varname, RCL_RET_OK) << rcl_get_error_string().str
|
||||||
|
|
||||||
|
|
||||||
class CLASSNAME (TestEventFixture, RMW_IMPLEMENTATION) : public ::testing::Test
|
class CLASSNAME (TestEventFixture, RMW_IMPLEMENTATION) : public ::testing::Test
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -149,21 +151,24 @@ public:
|
||||||
ret = rcl_subscription_event_init(&subscription_event, &subscription, sub_event_type);
|
ret = rcl_subscription_event_init(&subscription_event, &subscription, sub_event_type);
|
||||||
ASSERT_EQ(ret, RCL_RET_OK) << rcl_get_error_string().str;
|
ASSERT_EQ(ret, RCL_RET_OK) << rcl_get_error_string().str;
|
||||||
|
|
||||||
// wait for discovery
|
// wait for discovery, time out after 10s
|
||||||
// total wait time of 10 seconds, if never ready
|
static const size_t max_iterations = 1000;
|
||||||
size_t max_iterations = 1000;
|
static const auto wait_period = 10ms;
|
||||||
milliseconds wait_period(10);
|
bool subscribe_success = false;
|
||||||
size_t iteration = 0;
|
for (size_t i = 0; i < max_iterations; ++i) {
|
||||||
do {
|
size_t subscription_count = 0;
|
||||||
iteration++;
|
size_t publisher_count = 0;
|
||||||
size_t count = 0;
|
ret = rcl_subscription_get_publisher_count(&subscription, &publisher_count);
|
||||||
rcl_ret_t ret = rcl_subscription_get_publisher_count(&subscription, &count);
|
EXPECT_OK(ret);
|
||||||
ASSERT_EQ(ret, RCL_RET_OK);
|
ret = rcl_publisher_get_subscription_count(&publisher, &subscription_count);
|
||||||
if (count > 0) {
|
EXPECT_OK(ret);
|
||||||
|
if (subscription_count && publisher_count) {
|
||||||
|
subscribe_success = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
std::this_thread::sleep_for(wait_period);
|
std::this_thread::sleep_for(wait_period);
|
||||||
} while (iteration < max_iterations);
|
}
|
||||||
|
ASSERT_TRUE(subscribe_success) << "Publisher/Subscription discovery timed out";
|
||||||
}
|
}
|
||||||
|
|
||||||
void tear_down_publisher_subscriber()
|
void tear_down_publisher_subscriber()
|
||||||
|
@ -280,7 +285,8 @@ wait_for_msgs_and_events(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
ret = rcl_wait_set_fini(&wait_set);
|
||||||
|
EXPECT_OK(ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue