-
Notifications
You must be signed in to change notification settings - Fork 66
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
Enhance consumer test util #601
Enhance consumer test util #601
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wonderful to see someone pick up and improve spring-pulsar based on the work I did a couple of weeks back! Way to go @KartikShrivastava 🎉
You did a really nice job and it's definitely a worthwhile contribution. I did raise a couple of questions.
There are also some formatting violations that are easy to fix simply by running ./gradlew format
...ulsar-test/src/main/java/org/springframework/pulsar/test/support/PulsarConsumerTestUtil.java
Outdated
Show resolved
Hide resolved
@@ -85,6 +122,12 @@ public ConditionsSpec<T> awaitAtMost(Duration timeout) { | |||
|
|||
@Override | |||
public ConditionsSpec<T> until(ConsumedMessagesCondition<T> condition) { | |||
if (calledUntil) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really need to introduce a new variable? Is there a reason why we can't rely on this.condition
being not being null
to verify if until
has been called before?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe we do since we do not have to specify a condition (e.g. PCTUT.whenConditionIsNotSpecifiedMessagesAreConsumedUntilAwaitDuration
).
I would like to suggest to rename the var to untilMethodAlreadyCalled
as the word until
in general is a confusing one that makes my brain pause when reading the code "until something happens". It seems nit picky but including the "method" in there helps readability for me anyways.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
untilMethodAlreadyCalled
is better than calledUntil
imo
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@KartikShrivastava, I could not agree w/ @jonas-grgt more on this being a great contribution. Thank you for this.
I also like that you submitted the WIP before investing too much into testing etc..that way we can align on current direction. Good call.
I have left a few comments/suggestions.
Great work.
...ulsar-test/src/main/java/org/springframework/pulsar/test/support/PulsarConsumerTestUtil.java
Outdated
Show resolved
Hide resolved
@@ -85,6 +122,12 @@ public ConditionsSpec<T> awaitAtMost(Duration timeout) { | |||
|
|||
@Override | |||
public ConditionsSpec<T> until(ConsumedMessagesCondition<T> condition) { | |||
if (calledUntil) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe we do since we do not have to specify a condition (e.g. PCTUT.whenConditionIsNotSpecifiedMessagesAreConsumedUntilAwaitDuration
).
I would like to suggest to rename the var to untilMethodAlreadyCalled
as the word until
in general is a confusing one that makes my brain pause when reading the code "until something happens". It seems nit picky but including the "method" in there helps readability for me anyways.
...-test/src/test/java/org/springframework/pulsar/test/support/PulsarConsumerTestUtilTests.java
Outdated
Show resolved
Hide resolved
...ulsar-test/src/main/java/org/springframework/pulsar/test/support/PulsarConsumerTestUtil.java
Outdated
Show resolved
Hide resolved
Thank you @jonas-grgt and @onobc, for your kind words and detailed suggestion for improvements. Checking them out now |
...ulsar-test/src/main/java/org/springframework/pulsar/test/support/PulsarConsumerTestUtil.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@KartikShrivastava, thanks for the updates. LGTM.
The only remaining piece is to add a few tests to cover the newly added methods.
void messagesAreConsumedWhenContainerIsStoppedAndConsumeMessagesIsCalledWithoutArguments() { | ||
PulsarTestContainerSupport.stopContainer(); | ||
PulsarConsumerTestUtil.<String>consumeMessages(); | ||
// TODO: Complete this test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to request some assistance writing this test
- Basically I want to test if consumeMessages works properly even if
PULSAR_CONTAINER
is not running - When I try to
get()
the consumeMessages I get connection refused error for the localhost pulsar client - Also I'm not sure at what point should I send messages to the topic, if I do it before stopping the container will it still work? since the pulsarClient instance would be different after container is stopped
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, this one is tricky to test. We actually can't stop the container as the other tests will fail. The "magic" of the PTCS is that it has the @BeforeAll
that starts it for the test class. If we stopped it we would have to restart it and then it gets into a bit of flaky-test-land at that point.
I think instead we can static mock the "isContainerStarted" that it uses to decide what to do.
We are releasing 1.1.0-M2
tomorrow so I am going to take what you have in this current state and add a polish commit on top so that we can get this in. I will include this test adjustment in that commit.
Great work @KartikShrivastava !
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, if you are wondering why we did not have (or need) the stop container method annotated w/ a @AfterAll
to match the start w/ / @BeforeAll
it is because Testcontainers does
At the end of the test suite the Ryuk container that is started by Testcontainers core will take care of stopping the singleton container.
However, I think I will add it in the polish commit to avoid future confusion
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note
Adding the @AfterAll
to the new stopContainer
method had unintended side-effects when used in a Jupiter @Nested
test. I removed the annotation but left the method (9bc6bda)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool, thanks for taking this up @onobc, really appreciate that.
I've one minor question seeing the improvements you've made: Is there a recommended way or methodology we follow to name test methods in this project? If so, then I would like to learn/read more about it :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are welcome @KartikShrivastava .
In general we follow the "when-THIS-then-OUTCOME" but more than anything the principle I follow is consistency w/in a test suite and enough information in the name to understand what it is testing. I will also typically group tests together using @Nested
which groups them and allows us to not have ultra long test names. I was tempted to do some grouping on this test but ended up leaving as is.
I also noticed that the negative test cases I named a bit different than the other ones (they are shorter in nature).
So there is no doc that describes this but it would be a good idea for us to add one. I will note this.
Thanks
...ulsar-test/src/main/java/org/springframework/pulsar/test/support/PulsarConsumerTestUtil.java
Show resolved
Hide resolved
Hey folks, I've added the tests for the changes made in |
Closing via 2c7e3b2 |
@KartikShrivastava thanks for this great contribution. Take a peek at the follow on commit I did d99101f. You can see how I uses static mocks to test our difficult case. I re-ordered the test methods a bit as well. Great work. Thank you. |
Thanks @onobc! |
Resolves #599