-
Notifications
You must be signed in to change notification settings - Fork 85
Fix hasMessageAvailable will return true after seeking to a timestamp newer than the last message #556
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix hasMessageAvailable will return true after seeking to a timestamp newer than the last message #556
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,6 +38,7 @@ | |
| #include "lib/Latch.h" | ||
| #include "lib/LogUtils.h" | ||
| #include "lib/ReaderImpl.h" | ||
| #include "lib/TimeUtils.h" | ||
| DECLARE_LOG_OBJECT() | ||
|
|
||
| using namespace pulsar; | ||
|
|
@@ -865,13 +866,7 @@ TEST_P(ReaderSeekTest, testHasMessageAvailableAfterSeekToEnd) { | |
| } | ||
|
|
||
| ASSERT_EQ(ResultOk, reader.seek(MessageId::latest())); | ||
| // After seek-to-end the broker may close the consumer and trigger reconnect; allow a short | ||
| // delay for hasMessageAvailable to become false (avoids flakiness when reconnect completes). | ||
| for (int i = 0; i < 50; i++) { | ||
| ASSERT_EQ(ResultOk, reader.hasMessageAvailable(hasMessageAvailable)); | ||
| if (!hasMessageAvailable) break; | ||
| std::this_thread::sleep_for(std::chrono::milliseconds(100)); | ||
| } | ||
| ASSERT_EQ(ResultOk, reader.hasMessageAvailable(hasMessageAvailable)); | ||
|
BewareMyPower marked this conversation as resolved.
|
||
| ASSERT_FALSE(hasMessageAvailable); | ||
|
|
||
| producer.send(MessageBuilder().setContent("msg-2").build()); | ||
|
|
@@ -983,6 +978,26 @@ TEST_F(ReaderSeekTest, testSeekInclusiveChunkMessage) { | |
| assertStartMessageId(false, secondMsgId); | ||
| } | ||
|
|
||
| TEST_P(ReaderSeekTest, testSeekToEndByTimestamp) { | ||
| auto topic = "test-seek-to-end-by-timestamp-" + std::to_string(time(nullptr)); | ||
| Producer producer; | ||
| ASSERT_EQ(ResultOk, client.createProducer(topic, producer)); | ||
|
|
||
| ReaderConfiguration readerConf; | ||
| readerConf.setStartMessageIdInclusive(GetParam()); | ||
|
|
||
| Reader reader; | ||
| ASSERT_EQ(ResultOk, client.createReader(topic, MessageId::earliest(), readerConf, reader)); | ||
|
|
||
| ASSERT_EQ(ResultOk, producer.send(MessageBuilder().setContent("msg").build())); | ||
| auto now = TimeUtils::currentTimeMillis() + 1000; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why we add
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To seek to a timestamp that is later than the last message. Sorry I forgot to push the local changes when addressing #556 (comment) |
||
| ASSERT_EQ(ResultOk, reader.seek(now)); | ||
|
|
||
|
BewareMyPower marked this conversation as resolved.
|
||
| bool hasMessageAvailable; | ||
| ASSERT_EQ(ResultOk, reader.hasMessageAvailable(hasMessageAvailable)); | ||
| ASSERT_FALSE(hasMessageAvailable); | ||
| } | ||
|
|
||
| // Regression test for segfault when Reader is used with messageListenerThreads=0. | ||
| // Verifies ExecutorServiceProvider(0) does not cause undefined behavior and | ||
| // ConsumerImpl::messageReceived does not dereference null listenerExecutor_. | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.