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
61
vendor/github.com/eapache/channels/resizable_channel_test.go
generated
vendored
Normal file
61
vendor/github.com/eapache/channels/resizable_channel_test.go
generated
vendored
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
package channels
|
||||
|
||||
import (
|
||||
"math/rand"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestResizableChannel(t *testing.T) {
|
||||
var ch *ResizableChannel
|
||||
|
||||
ch = NewResizableChannel()
|
||||
testChannel(t, "default resizable channel", ch)
|
||||
|
||||
ch = NewResizableChannel()
|
||||
testChannelPair(t, "default resizable channel", ch, ch)
|
||||
|
||||
ch = NewResizableChannel()
|
||||
ch.Resize(Infinity)
|
||||
testChannel(t, "infinite resizable channel", ch)
|
||||
|
||||
ch = NewResizableChannel()
|
||||
ch.Resize(Infinity)
|
||||
testChannelPair(t, "infinite resizable channel", ch, ch)
|
||||
|
||||
ch = NewResizableChannel()
|
||||
ch.Resize(5)
|
||||
testChannel(t, "5-buffer resizable channel", ch)
|
||||
|
||||
ch = NewResizableChannel()
|
||||
ch.Resize(5)
|
||||
testChannelPair(t, "5-buffer resizable channel", ch, ch)
|
||||
|
||||
ch = NewResizableChannel()
|
||||
testChannelConcurrentAccessors(t, "resizable channel", ch)
|
||||
}
|
||||
|
||||
func TestResizableChannelOnline(t *testing.T) {
|
||||
stopper := make(chan bool)
|
||||
ch := NewResizableChannel()
|
||||
go func() {
|
||||
for i := 0; i < 1000; i++ {
|
||||
ch.In() <- i
|
||||
}
|
||||
<-stopper
|
||||
ch.Close()
|
||||
}()
|
||||
|
||||
go func() {
|
||||
for i := 0; i < 1000; i++ {
|
||||
ch.Resize(BufferCap(rand.Intn(50) + 1))
|
||||
}
|
||||
close(stopper)
|
||||
}()
|
||||
|
||||
for i := 0; i < 1000; i++ {
|
||||
val := <-ch.Out()
|
||||
if i != val.(int) {
|
||||
t.Fatal("resizable channel expected", i, "but got", val.(int))
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue