Skip to content
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

Merge TopicMessages by topic in sendBatch #626

Merged
merged 3 commits into from
Jan 9, 2020

Conversation

Nevon
Copy link
Collaborator

@Nevon Nevon commented Jan 8, 2020

Fixes #622

I'm not entirely satisfied with the testing here. Basically what I'm asserting is that the expected number of messages are produced, but I'm not asserting message ordering.

Unfortunately I can't really validate that without consuming the topic, which means that the producer test depends on the consumer. Maybe that's okay? On the other hand, the logic is pretty trivial, but still.

@Nevon Nevon requested review from tulios and JaapRood January 8, 2020 15:29
if (!topicBatch) {
merged.push({ topic, messages })
} else {
topicBatch.messages.concat(messages)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

surprisingly enough, the spread operation is faster than concat.

topicBatch.messages = [...topicBatch.messages, ...messages]

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Totally bike shedding here, but I wonder whether that's because concatenation to any empty array is faster 🧐. Doesn't matter, move on, nothing to see here 😇.

Copy link
Collaborator

@JaapRood JaapRood left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implementation looks fine to me. Test wise, I think it's probably worth consuming the messages we've produced in batch to verify their order has been preserved.

if (!topicBatch) {
merged.push({ topic, messages })
} else {
topicBatch.messages.concat(messages)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Totally bike shedding here, but I wonder whether that's because concatenation to any empty array is faster 🧐. Doesn't matter, move on, nothing to see here 😇.

@Nevon
Copy link
Collaborator Author

Nevon commented Jan 9, 2020

Implementation looks fine to me. Test wise, I think it's probably worth consuming the messages we've produced in batch to verify their order has been preserved.

I should learn to trust my gut, because of course we missed something and the implementation didn't actually work. I was using merged.find to find the TopicMessages for each topic, and was relying on mutating that to add the messages, but that didn't actually work:

const topicBatch = merged.find(({ topic: batchTopic }) => batchTopic === topic)

if (!topicBatch) {
  merged.push({ topic, messages })
} else {
  // this doesn't actually mutate `merged`
  topicBatch.messages.concat(messages)
}

return merged

Noticed when I updated the tests to actually consume the produced messages.

Copy link
Collaborator

@JaapRood JaapRood left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 LGTM. +1 for integration tests 😅

@Nevon Nevon merged commit 0b70749 into master Jan 9, 2020
@Nevon Nevon deleted the merge-topic-messages-by-topic branch January 9, 2020 15:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

sendBatch not sending multiple batches for the same topic
3 participants