-
-
Notifications
You must be signed in to change notification settings - Fork 527
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
Conversation
src/producer/messageProducer.js
Outdated
if (!topicBatch) { | ||
merged.push({ topic, messages }) | ||
} else { | ||
topicBatch.messages.concat(messages) |
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.
surprisingly enough, the spread operation is faster than concat.
topicBatch.messages = [...topicBatch.messages, ...messages]
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.
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 😇.
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.
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.
src/producer/messageProducer.js
Outdated
if (!topicBatch) { | ||
merged.push({ topic, messages }) | ||
} else { | ||
topicBatch.messages.concat(messages) |
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.
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 😇.
I should learn to trust my gut, because of course we missed something and the implementation didn't actually work. I was using 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. |
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.
👍 LGTM. +1 for integration tests 😅
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.