BewareMyPower commented on code in PR #510:
URL: https://github.com/apache/pulsar-client-cpp/pull/510#discussion_r2435743247
##########
tests/ConsumerTest.cc:
##########
@@ -1519,4 +1519,46 @@ TEST(ConsumerTest, testDuplicatedTopics) {
}
}
+TEST(ConsumerTest, testConsumerListenerShouldNotSegfaultAfterClose) {
+ Client client(lookupUrl);
+
+ const int MSG_COUNT = 100;
+ std::string topicName = "persistent://public/default/my-topic-" +
std::to_string(time(nullptr));
+
+ // 1. Create producer send 100 msgs
+ Producer producer;
+ ProducerConfiguration producerConfig;
+ producerConfig.setBatchingEnabled(false);
+ ASSERT_EQ(ResultOk, client.createProducer(topicName, producerConfig,
producer));
+ for (int i = 0; i < MSG_COUNT; ++i) {
+ std::string msg = "my-message-" + std::to_string(i);
+ Message message = MessageBuilder().setContent(msg).build();
+ ASSERT_EQ(ResultOk, producer.send(message));
+ }
+ ASSERT_EQ(ResultOk, producer.flush());
+
+ // 2. Create consumer with listener
+ Consumer consumer;
+ ConsumerConfiguration consumerConfig;
+ consumerConfig.setSubscriptionInitialPosition(InitialPositionEarliest);
+ Latch latchFirstReceiveMsg(1);
+ Latch latchAfterClosed(1);
+ consumerConfig.setMessageListener(
+ [&latchFirstReceiveMsg, &latchAfterClosed](Consumer consumer, const
Message& msg) {
+ latchFirstReceiveMsg.countdown();
+ std::cout << "Consume message: " << msg.getDataAsString() <<
std::endl;
Review Comment:
```suggestion
LOG_INFO("Consume message: " << msg.getDataAsString());
```
##########
tests/ConsumerTest.cc:
##########
@@ -1519,4 +1519,46 @@ TEST(ConsumerTest, testDuplicatedTopics) {
}
}
+TEST(ConsumerTest, testConsumerListenerShouldNotSegfaultAfterClose) {
+ Client client(lookupUrl);
+
+ const int MSG_COUNT = 100;
+ std::string topicName = "persistent://public/default/my-topic-" +
std::to_string(time(nullptr));
+
+ // 1. Create producer send 100 msgs
+ Producer producer;
+ ProducerConfiguration producerConfig;
+ producerConfig.setBatchingEnabled(false);
+ ASSERT_EQ(ResultOk, client.createProducer(topicName, producerConfig,
producer));
+ for (int i = 0; i < MSG_COUNT; ++i) {
+ std::string msg = "my-message-" + std::to_string(i);
+ Message message = MessageBuilder().setContent(msg).build();
+ ASSERT_EQ(ResultOk, producer.send(message));
+ }
+ ASSERT_EQ(ResultOk, producer.flush());
Review Comment:
```suggestion
```
No need to call `flush` because `send` is synchronous
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]