Use a ring channel to avoid blocking write of events (#2082)
* Use a ring channel to avoid blocking write of events * Add eapache/channels dependency
This commit is contained in:
parent
33475b7184
commit
9bcb5b08ea
35 changed files with 2833 additions and 78 deletions
45
vendor/github.com/eapache/channels/batching_channel_test.go
generated
vendored
Normal file
45
vendor/github.com/eapache/channels/batching_channel_test.go
generated
vendored
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
package channels
|
||||
|
||||
import "testing"
|
||||
|
||||
func testBatches(t *testing.T, ch Channel) {
|
||||
go func() {
|
||||
for i := 0; i < 1000; i++ {
|
||||
ch.In() <- i
|
||||
}
|
||||
ch.Close()
|
||||
}()
|
||||
|
||||
i := 0
|
||||
for val := range ch.Out() {
|
||||
for _, elem := range val.([]interface{}) {
|
||||
if i != elem.(int) {
|
||||
t.Fatal("batching channel expected", i, "but got", elem.(int))
|
||||
}
|
||||
i++
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestBatchingChannel(t *testing.T) {
|
||||
ch := NewBatchingChannel(Infinity)
|
||||
testBatches(t, ch)
|
||||
|
||||
ch = NewBatchingChannel(2)
|
||||
testBatches(t, ch)
|
||||
|
||||
ch = NewBatchingChannel(1)
|
||||
testChannelConcurrentAccessors(t, "batching channel", ch)
|
||||
}
|
||||
|
||||
func TestBatchingChannelCap(t *testing.T) {
|
||||
ch := NewBatchingChannel(Infinity)
|
||||
if ch.Cap() != Infinity {
|
||||
t.Error("incorrect capacity on infinite channel")
|
||||
}
|
||||
|
||||
ch = NewBatchingChannel(5)
|
||||
if ch.Cap() != 5 {
|
||||
t.Error("incorrect capacity on infinite channel")
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue