-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
[pkg/queue] Add StartConsumersWithFactory
function
#2714
[pkg/queue] Add StartConsumersWithFactory
function
#2714
Conversation
This provides a way to keep state for each consumer of a bounded queue, which is useful in certain performance-critical setups. Fixes jaegertracing#2685. Signed-off-by: Pablo Baeyens <pablo.baeyens@datadoghq.com>
Codecov Report
@@ Coverage Diff @@
## master #2714 +/- ##
==========================================
+ Coverage 95.73% 95.74% +0.01%
==========================================
Files 216 216
Lines 9588 9593 +5
==========================================
+ Hits 9179 9185 +6
Misses 336 336
+ Partials 73 72 -1
Continue to review full report at Codecov.
|
The common part with the assertions was moved to a new `checkQueue` function that is used by `TestBoundedQueue` and `TestBoundedQueueWithFactory`. Signed-off-by: Pablo Baeyens <pablo.baeyens@datadoghq.com>
Signed-off-by: Pablo Baeyens <pablo.baeyens@datadoghq.com>
Refactor unit tests using a `helper` function that takes a function to start consumers. Signed-off-by: Pablo Baeyens <pablo.baeyens@datadoghq.com>
@yurishkuro Thanks for the comments, I think I addressed everything, hopefully this looks better :) |
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.
Thanks!
@@ -33,7 +33,7 @@ import ( | |||
// In this test we run a queue with capacity 1 and a single consumer. | |||
// We want to test the overflow behavior, so we block the consumer | |||
// by holding a startLock before submitting items to the queue. | |||
func TestBoundedQueue(t *testing.T) { | |||
func helper(t *testing.T, startConsumers func(q *BoundedQueue, consumerFn func(item interface{}))) { |
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.
hehe, I didn't mean the name helper
literally, was just too lazy to type what you had, but that's fine.
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.
hahaha, I couldn't come up with anything better so I left it like you said 😄
@@ -112,6 +112,18 @@ func TestBoundedQueue(t *testing.T) { | |||
assert.False(t, q.Produce("x"), "cannot push to closed queue") | |||
} | |||
|
|||
func TestBoundedQueue(t *testing.T) { |
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.
much cleaner, minimal changes
) * [pkg/queue] Add `StartConsumersWithFactory` function This provides a way to keep state for each consumer of a bounded queue, which is useful in certain performance-critical setups. Fixes jaegertracing#2685. Signed-off-by: Pablo Baeyens <pablo.baeyens@datadoghq.com> * Refactor bounded queue tests to extract common parts The common part with the assertions was moved to a new `checkQueue` function that is used by `TestBoundedQueue` and `TestBoundedQueueWithFactory`. Signed-off-by: Pablo Baeyens <pablo.baeyens@datadoghq.com> * Use http.HandlerFunc pattern for getting a Consumer from a callback Signed-off-by: Pablo Baeyens <pablo.baeyens@datadoghq.com> * Address review comment about unit tests Refactor unit tests using a `helper` function that takes a function to start consumers. Signed-off-by: Pablo Baeyens <pablo.baeyens@datadoghq.com>
Which problem is this PR solving?
Short description of the changes
StartConsumersWithFactory
function to allow for keeping state per-consumer.StartConsumers
with a dummy factory function.