Skip to content

Commit 3356151

Browse files
committed
Update the description and test codes
Signed-off-by: Barry Xu <barry.xu@sony.com>
1 parent 071b068 commit 3356151

3 files changed

Lines changed: 24 additions & 87 deletions

File tree

rcl/include/rcl/publisher.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ rcl_publisher_assert_liveliness(const rcl_publisher_t * publisher);
439439
/**
440440
* This function waits until all published message data were acknowledged by peer node or timeout.
441441
*
442-
* The unit of timeout is nanoseconds.
442+
* The timeout unit is nanoseconds.
443443
* If the timeout is negative then this function will block indefinitely until all published message
444444
* data were acknowledged.
445445
* If the timeout is 0 then this function will be non-blocking; checking all published message data
@@ -449,7 +449,7 @@ rcl_publisher_assert_liveliness(const rcl_publisher_t * publisher);
449449
* elapsed (return RCL_RET_TIMEOUT) or all published message data were acknowledged (return
450450
* RCL_RET_OK).
451451
*
452-
* This function only works effectively while QOS profile of publisher is set to RELIABLE.
452+
* This function only waits for acknowledgments if the publisher's QOS profile is RELIABLE.
453453
* Otherwise this function will immediately return RCL_RET_OK.
454454
*
455455
* <hr>
@@ -464,7 +464,7 @@ rcl_publisher_assert_liveliness(const rcl_publisher_t * publisher);
464464
* \param[in] timeout the duration to wait for all published message data were acknowledged, in
465465
* nanoseconds.
466466
* \return #RCL_RET_OK if successful, or
467-
* \return #RCL_RET_TIMEOUT if wait timed out, or
467+
* \return #RCL_RET_TIMEOUT if timed out, or
468468
* \return #RCL_RET_PUBLISHER_INVALID if publisher is invalid, or
469469
* \return #RCL_RET_ERROR if an unspecified error occurs, or
470470
* \return #RCL_RET_UNSUPPORTED if the middleware does not support that feature.

rcl/src/rcl/publisher.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,10 +327,11 @@ rcl_publisher_wait_for_all_acked(const rcl_publisher_t * publisher, rcl_duration
327327

328328
rmw_ret_t ret = rmw_publisher_wait_for_all_acked(publisher->impl->rmw_handle, rmw_timeout);
329329
if (ret != RMW_RET_OK) {
330-
RCL_SET_ERROR_MSG(rmw_get_error_string().str);
331330
if (ret == RMW_RET_TIMEOUT) {
332331
return RCL_RET_TIMEOUT;
333-
} else if (ret == RMW_RET_UNSUPPORTED) {
332+
}
333+
RCL_SET_ERROR_MSG(rmw_get_error_string().str);
334+
if (ret == RMW_RET_UNSUPPORTED) {
334335
return RCL_RET_UNSUPPORTED;
335336
} else {
336337
return RCL_RET_ERROR;

rcl/test/rcl/test_publisher_wait_all_ack.cpp

Lines changed: 18 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,7 @@ class CLASSNAME (TestPublisherFixtureSpecial, RMW_IMPLEMENTATION) : public ::tes
5151

5252
void SetUp()
5353
{
54-
is_fastdds = (std::string(rmw_get_implementation_identifier()).find("rmw_fastrtps") == 0);
55-
is_cyclonedds = (std::string(rmw_get_implementation_identifier()).find("rmw_cyclonedds") == 0);
56-
is_connextdds = (std::string(rmw_get_implementation_identifier()).find("rmw_connextdds") == 0);
54+
bool is_fastdds = (std::string(rmw_get_implementation_identifier()).find("rmw_fastrtps") == 0);
5755

5856
if (is_fastdds) {
5957
// By default, fastdds use intraprocess mode in this scenario. But this leads to high-speed
@@ -100,13 +98,24 @@ class CLASSNAME (TestPublisherFixtureSpecial, RMW_IMPLEMENTATION) : public ::tes
10098
delete this->context_ptr;
10199
EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
102100
}
103-
104-
protected:
105-
bool is_fastdds;
106-
bool is_cyclonedds;
107-
bool is_connextdds;
108101
};
109102

103+
#define INIT_SUBSCRIPTION(idx) \
104+
rcl_subscription_t subscription ## idx = rcl_get_zero_initialized_subscription(); \
105+
ret = rcl_subscription_init( \
106+
&subscription ## idx, \
107+
this->node_ptr, \
108+
ts, \
109+
topic_name, \
110+
&subscription_options); \
111+
ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str; \
112+
OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT( \
113+
{ \
114+
ret = rcl_subscription_fini(&subscription ## idx, this->node_ptr); \
115+
EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str; \
116+
});
117+
118+
#define ONE_MEGABYTE (1024 * 1024)
110119

111120
TEST_F(CLASSNAME(TestPublisherFixtureSpecial, RMW_IMPLEMENTATION), test_wait_for_all_acked) {
112121
rcl_ret_t ret;
@@ -129,29 +138,12 @@ TEST_F(CLASSNAME(TestPublisherFixtureSpecial, RMW_IMPLEMENTATION), test_wait_for
129138
subscription_options.qos.depth = 1;
130139
subscription_options.qos.reliability = RMW_QOS_POLICY_RELIABILITY_RELIABLE;
131140

132-
#define INIT_SUBSCRIPTION(idx) \
133-
rcl_subscription_t subscription ## idx = rcl_get_zero_initialized_subscription(); \
134-
ret = rcl_subscription_init( \
135-
&subscription ## idx, \
136-
this->node_ptr, \
137-
ts, \
138-
topic_name, \
139-
&subscription_options); \
140-
ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str; \
141-
OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT( \
142-
{ \
143-
ret = rcl_subscription_fini(&subscription ## idx, this->node_ptr); \
144-
EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str; \
145-
});
146-
147141
INIT_SUBSCRIPTION(1)
148142
INIT_SUBSCRIPTION(2)
149143
INIT_SUBSCRIPTION(3)
150144

151145
ASSERT_TRUE(wait_for_established_subscription(&publisher, 10, 100));
152146

153-
// Prepare 1MB message
154-
#define ONE_MEGABYTE (1024 * 1024)
155147
char test_string[ONE_MEGABYTE];
156148
memset(test_string, 'a', ONE_MEGABYTE);
157149
test_string[ONE_MEGABYTE - 1] = '\0';
@@ -179,13 +171,8 @@ TEST_F(CLASSNAME(TestPublisherFixtureSpecial, RMW_IMPLEMENTATION), test_wait_for
179171
ret = rcl_publisher_wait_for_all_acked(
180172
&publisher,
181173
RCL_MS_TO_NS(500));
174+
EXPECT_TRUE(ret == RCL_RET_OK || ret == RCL_RET_TIMEOUT);
182175

183-
if (is_cyclonedds) {
184-
// cyclonedds use sync publish, so above scenario cannot lead to timeout.
185-
EXPECT_EQ(RCL_RET_OK, ret);
186-
} else {
187-
EXPECT_EQ(RCL_RET_TIMEOUT, ret);
188-
}
189176
ret = rcl_publisher_wait_for_all_acked(&publisher, -1);
190177
EXPECT_EQ(RCL_RET_OK, ret);
191178
}
@@ -210,57 +197,6 @@ TEST_F(
210197
EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
211198
});
212199

213-
rcl_subscription_options_t subscription_options = rcl_subscription_get_default_options();
214-
subscription_options.qos.depth = 1;
215-
subscription_options.qos.reliability = RMW_QOS_POLICY_RELIABILITY_BEST_EFFORT;
216-
217-
#define INIT_SUBSCRIPTION(idx) \
218-
rcl_subscription_t subscription ## idx = rcl_get_zero_initialized_subscription(); \
219-
ret = rcl_subscription_init( \
220-
&subscription ## idx, \
221-
this->node_ptr, \
222-
ts, \
223-
topic_name, \
224-
&subscription_options); \
225-
ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str; \
226-
OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT( \
227-
{ \
228-
ret = rcl_subscription_fini(&subscription ## idx, this->node_ptr); \
229-
EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str; \
230-
});
231-
232-
INIT_SUBSCRIPTION(1)
233-
INIT_SUBSCRIPTION(2)
234-
INIT_SUBSCRIPTION(3)
235-
236-
ASSERT_TRUE(wait_for_established_subscription(&publisher, 10, 100));
237-
238-
// Prepare 1MB message
239-
#define ONE_MEGABYTE (1024 * 1024)
240-
char test_string[ONE_MEGABYTE];
241-
memset(test_string, 'a', ONE_MEGABYTE);
242-
test_string[ONE_MEGABYTE - 1] = '\0';
243-
test_msgs__msg__Strings msg;
244-
test_msgs__msg__Strings__init(&msg);
245-
ASSERT_TRUE(rosidl_runtime_c__String__assign(&msg.string_value, test_string));
246-
OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT(
247-
{
248-
test_msgs__msg__Strings__fini(&msg);
249-
});
250-
251-
ret = rcl_publish(&publisher, &msg, nullptr);
252-
ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
253-
254-
ASSERT_TRUE(wait_for_subscription_to_be_ready(&subscription1, context_ptr, 10, 100));
255-
ASSERT_TRUE(wait_for_subscription_to_be_ready(&subscription2, context_ptr, 10, 100));
256-
ASSERT_TRUE(wait_for_subscription_to_be_ready(&subscription3, context_ptr, 10, 100));
257-
258-
int i = 0;
259-
for (; i < 500; i++) {
260-
ret = rcl_publish(&publisher, &msg, nullptr);
261-
ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
262-
}
263-
264200
ret = rcl_publisher_wait_for_all_acked(
265201
&publisher,
266202
RCL_MS_TO_NS(500));

0 commit comments

Comments
 (0)