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
58
vendor/github.com/eapache/channels/native_channel_test.go
generated
vendored
Normal file
58
vendor/github.com/eapache/channels/native_channel_test.go
generated
vendored
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
package channels
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestNativeChannels(t *testing.T) {
|
||||
var ch Channel
|
||||
|
||||
ch = NewNativeChannel(None)
|
||||
testChannel(t, "bufferless native channel", ch)
|
||||
|
||||
ch = NewNativeChannel(None)
|
||||
testChannelPair(t, "bufferless native channel", ch, ch)
|
||||
|
||||
ch = NewNativeChannel(5)
|
||||
testChannel(t, "5-buffer native channel", ch)
|
||||
|
||||
ch = NewNativeChannel(5)
|
||||
testChannelPair(t, "5-buffer native channel", ch, ch)
|
||||
|
||||
ch = NewNativeChannel(None)
|
||||
testChannelConcurrentAccessors(t, "native channel", ch)
|
||||
}
|
||||
|
||||
func TestNativeInOutChannels(t *testing.T) {
|
||||
ch1 := make(chan interface{})
|
||||
ch2 := make(chan interface{})
|
||||
|
||||
Pipe(NativeOutChannel(ch1), NativeInChannel(ch2))
|
||||
NativeInChannel(ch1).Close()
|
||||
}
|
||||
|
||||
func TestDeadChannel(t *testing.T) {
|
||||
ch := NewDeadChannel()
|
||||
|
||||
if ch.Len() != 0 {
|
||||
t.Error("dead channel length not 0")
|
||||
}
|
||||
if ch.Cap() != 0 {
|
||||
t.Error("dead channel cap not 0")
|
||||
}
|
||||
|
||||
select {
|
||||
case <-ch.Out():
|
||||
t.Error("read from a dead channel")
|
||||
default:
|
||||
}
|
||||
|
||||
select {
|
||||
case ch.In() <- nil:
|
||||
t.Error("wrote to a dead channel")
|
||||
default:
|
||||
}
|
||||
|
||||
ch.Close()
|
||||
|
||||
ch = NewDeadChannel()
|
||||
testChannelConcurrentAccessors(t, "dead channel", ch)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue