Update go dependencies
This commit is contained in:
parent
15ffb51394
commit
bb4d483837
1621 changed files with 86368 additions and 284392 deletions
45
vendor/github.com/eapache/channels/batching_channel_test.go
generated
vendored
45
vendor/github.com/eapache/channels/batching_channel_test.go
generated
vendored
|
|
@ -1,45 +0,0 @@
|
|||
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")
|
||||
}
|
||||
}
|
||||
26
vendor/github.com/eapache/channels/black_hole_test.go
generated
vendored
26
vendor/github.com/eapache/channels/black_hole_test.go
generated
vendored
|
|
@ -1,26 +0,0 @@
|
|||
package channels
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestBlackHole(t *testing.T) {
|
||||
discard := NewBlackHole()
|
||||
|
||||
for i := 0; i < 1000; i++ {
|
||||
discard.In() <- i
|
||||
}
|
||||
|
||||
discard.Close()
|
||||
|
||||
if discard.Len() != 1000 {
|
||||
t.Error("blackhole expected 1000 was", discard.Len())
|
||||
}
|
||||
|
||||
// no asserts here, this is just for the race detector's benefit
|
||||
ch := NewBlackHole()
|
||||
go ch.Len()
|
||||
go ch.Cap()
|
||||
|
||||
go func() {
|
||||
ch.In() <- nil
|
||||
}()
|
||||
}
|
||||
265
vendor/github.com/eapache/channels/channels_test.go
generated
vendored
265
vendor/github.com/eapache/channels/channels_test.go
generated
vendored
|
|
@ -1,265 +0,0 @@
|
|||
package channels
|
||||
|
||||
import (
|
||||
"math/rand"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func testChannel(t *testing.T, name string, ch Channel) {
|
||||
go func() {
|
||||
for i := 0; i < 1000; i++ {
|
||||
ch.In() <- i
|
||||
}
|
||||
ch.Close()
|
||||
}()
|
||||
for i := 0; i < 1000; i++ {
|
||||
val := <-ch.Out()
|
||||
if i != val.(int) {
|
||||
t.Fatal(name, "expected", i, "but got", val.(int))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testChannelPair(t *testing.T, name string, in InChannel, out OutChannel) {
|
||||
go func() {
|
||||
for i := 0; i < 1000; i++ {
|
||||
in.In() <- i
|
||||
}
|
||||
in.Close()
|
||||
}()
|
||||
for i := 0; i < 1000; i++ {
|
||||
val := <-out.Out()
|
||||
if i != val.(int) {
|
||||
t.Fatal("pair", name, "expected", i, "but got", val.(int))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testChannelConcurrentAccessors(t *testing.T, name string, ch Channel) {
|
||||
// no asserts here, this is just for the race detector's benefit
|
||||
go ch.Len()
|
||||
go ch.Cap()
|
||||
|
||||
go func() {
|
||||
ch.In() <- nil
|
||||
}()
|
||||
|
||||
go func() {
|
||||
<-ch.Out()
|
||||
}()
|
||||
}
|
||||
|
||||
func TestPipe(t *testing.T) {
|
||||
a := NewNativeChannel(None)
|
||||
b := NewNativeChannel(None)
|
||||
|
||||
Pipe(a, b)
|
||||
|
||||
testChannelPair(t, "pipe", a, b)
|
||||
}
|
||||
|
||||
func TestWeakPipe(t *testing.T) {
|
||||
a := NewNativeChannel(None)
|
||||
b := NewNativeChannel(None)
|
||||
|
||||
WeakPipe(a, b)
|
||||
|
||||
testChannelPair(t, "pipe", a, b)
|
||||
}
|
||||
|
||||
func testMultiplex(t *testing.T, multi func(output SimpleInChannel, inputs ...SimpleOutChannel)) {
|
||||
a := NewNativeChannel(None)
|
||||
b := NewNativeChannel(None)
|
||||
|
||||
multi(b, a)
|
||||
|
||||
testChannelPair(t, "simple multiplex", a, b)
|
||||
|
||||
a = NewNativeChannel(None)
|
||||
inputs := []Channel{
|
||||
NewNativeChannel(None),
|
||||
NewNativeChannel(None),
|
||||
NewNativeChannel(None),
|
||||
NewNativeChannel(None),
|
||||
}
|
||||
|
||||
multi(a, inputs[0], inputs[1], inputs[2], inputs[3])
|
||||
|
||||
go func() {
|
||||
rand.Seed(time.Now().Unix())
|
||||
for i := 0; i < 1000; i++ {
|
||||
inputs[rand.Intn(len(inputs))].In() <- i
|
||||
}
|
||||
for i := range inputs {
|
||||
inputs[i].Close()
|
||||
}
|
||||
}()
|
||||
for i := 0; i < 1000; i++ {
|
||||
val := <-a.Out()
|
||||
if i != val.(int) {
|
||||
t.Fatal("multiplexing expected", i, "but got", val.(int))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestMultiplex(t *testing.T) {
|
||||
testMultiplex(t, Multiplex)
|
||||
}
|
||||
|
||||
func TestWeakMultiplex(t *testing.T) {
|
||||
testMultiplex(t, WeakMultiplex)
|
||||
}
|
||||
|
||||
func testTee(t *testing.T, tee func(input SimpleOutChannel, outputs ...SimpleInChannel)) {
|
||||
a := NewNativeChannel(None)
|
||||
b := NewNativeChannel(None)
|
||||
|
||||
tee(a, b)
|
||||
|
||||
testChannelPair(t, "simple tee", a, b)
|
||||
|
||||
a = NewNativeChannel(None)
|
||||
outputs := []Channel{
|
||||
NewNativeChannel(None),
|
||||
NewNativeChannel(None),
|
||||
NewNativeChannel(None),
|
||||
NewNativeChannel(None),
|
||||
}
|
||||
|
||||
tee(a, outputs[0], outputs[1], outputs[2], outputs[3])
|
||||
|
||||
go func() {
|
||||
for i := 0; i < 1000; i++ {
|
||||
a.In() <- i
|
||||
}
|
||||
a.Close()
|
||||
}()
|
||||
for i := 0; i < 1000; i++ {
|
||||
for _, output := range outputs {
|
||||
val := <-output.Out()
|
||||
if i != val.(int) {
|
||||
t.Fatal("teeing expected", i, "but got", val.(int))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestTee(t *testing.T) {
|
||||
testTee(t, Tee)
|
||||
}
|
||||
|
||||
func TestWeakTee(t *testing.T) {
|
||||
testTee(t, WeakTee)
|
||||
}
|
||||
|
||||
func testDistribute(t *testing.T, dist func(input SimpleOutChannel, outputs ...SimpleInChannel)) {
|
||||
a := NewNativeChannel(None)
|
||||
b := NewNativeChannel(None)
|
||||
|
||||
dist(a, b)
|
||||
|
||||
testChannelPair(t, "simple distribute", a, b)
|
||||
|
||||
a = NewNativeChannel(None)
|
||||
outputs := []Channel{
|
||||
NewNativeChannel(None),
|
||||
NewNativeChannel(None),
|
||||
NewNativeChannel(None),
|
||||
NewNativeChannel(None),
|
||||
}
|
||||
|
||||
dist(a, outputs[0], outputs[1], outputs[2], outputs[3])
|
||||
|
||||
go func() {
|
||||
for i := 0; i < 1000; i++ {
|
||||
a.In() <- i
|
||||
}
|
||||
a.Close()
|
||||
}()
|
||||
|
||||
received := make([]bool, 1000)
|
||||
for _ = range received {
|
||||
var val interface{}
|
||||
select {
|
||||
case val = <-outputs[0].Out():
|
||||
case val = <-outputs[1].Out():
|
||||
case val = <-outputs[2].Out():
|
||||
case val = <-outputs[3].Out():
|
||||
}
|
||||
if received[val.(int)] {
|
||||
t.Fatal("distribute got value twice", val.(int))
|
||||
}
|
||||
received[val.(int)] = true
|
||||
}
|
||||
for i := range received {
|
||||
if !received[i] {
|
||||
t.Fatal("distribute missed", i)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestDistribute(t *testing.T) {
|
||||
testDistribute(t, Distribute)
|
||||
}
|
||||
|
||||
func TestWeakDistribute(t *testing.T) {
|
||||
testDistribute(t, WeakDistribute)
|
||||
}
|
||||
|
||||
func TestWrap(t *testing.T) {
|
||||
rawChan := make(chan int, 5)
|
||||
ch := Wrap(rawChan)
|
||||
|
||||
for i := 0; i < 5; i++ {
|
||||
rawChan <- i
|
||||
}
|
||||
close(rawChan)
|
||||
|
||||
for i := 0; i < 5; i++ {
|
||||
x := (<-ch.Out()).(int)
|
||||
if x != i {
|
||||
t.Error("Wrapped value", x, "was expecting", i)
|
||||
}
|
||||
}
|
||||
_, ok := <-ch.Out()
|
||||
if ok {
|
||||
t.Error("Wrapped channel didn't close")
|
||||
}
|
||||
}
|
||||
|
||||
func TestUnwrap(t *testing.T) {
|
||||
rawChan := make(chan int)
|
||||
ch := NewNativeChannel(5)
|
||||
Unwrap(ch, rawChan)
|
||||
|
||||
for i := 0; i < 5; i++ {
|
||||
ch.In() <- i
|
||||
}
|
||||
ch.Close()
|
||||
|
||||
for i := 0; i < 5; i++ {
|
||||
x := <-rawChan
|
||||
if x != i {
|
||||
t.Error("Unwrapped value", x, "was expecting", i)
|
||||
}
|
||||
}
|
||||
_, ok := <-rawChan
|
||||
if ok {
|
||||
t.Error("Unwrapped channel didn't close")
|
||||
}
|
||||
}
|
||||
|
||||
func ExampleChannel() {
|
||||
var ch Channel
|
||||
|
||||
ch = NewInfiniteChannel()
|
||||
|
||||
for i := 0; i < 10; i++ {
|
||||
ch.In() <- nil
|
||||
}
|
||||
|
||||
for i := 0; i < 10; i++ {
|
||||
<-ch.Out()
|
||||
}
|
||||
}
|
||||
48
vendor/github.com/eapache/channels/infinite_channel_test.go
generated
vendored
48
vendor/github.com/eapache/channels/infinite_channel_test.go
generated
vendored
|
|
@ -1,48 +0,0 @@
|
|||
package channels
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestInfiniteChannel(t *testing.T) {
|
||||
var ch Channel
|
||||
|
||||
ch = NewInfiniteChannel()
|
||||
testChannel(t, "infinite channel", ch)
|
||||
|
||||
ch = NewInfiniteChannel()
|
||||
testChannelPair(t, "infinite channel", ch, ch)
|
||||
|
||||
ch = NewInfiniteChannel()
|
||||
testChannelConcurrentAccessors(t, "infinite channel", ch)
|
||||
}
|
||||
|
||||
func BenchmarkInfiniteChannelSerial(b *testing.B) {
|
||||
ch := NewInfiniteChannel()
|
||||
for i := 0; i < b.N; i++ {
|
||||
ch.In() <- nil
|
||||
}
|
||||
for i := 0; i < b.N; i++ {
|
||||
<-ch.Out()
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkInfiniteChannelParallel(b *testing.B) {
|
||||
ch := NewInfiniteChannel()
|
||||
go func() {
|
||||
for i := 0; i < b.N; i++ {
|
||||
<-ch.Out()
|
||||
}
|
||||
ch.Close()
|
||||
}()
|
||||
for i := 0; i < b.N; i++ {
|
||||
ch.In() <- nil
|
||||
}
|
||||
<-ch.Out()
|
||||
}
|
||||
|
||||
func BenchmarkInfiniteChannelTickTock(b *testing.B) {
|
||||
ch := NewInfiniteChannel()
|
||||
for i := 0; i < b.N; i++ {
|
||||
ch.In() <- nil
|
||||
<-ch.Out()
|
||||
}
|
||||
}
|
||||
58
vendor/github.com/eapache/channels/native_channel_test.go
generated
vendored
58
vendor/github.com/eapache/channels/native_channel_test.go
generated
vendored
|
|
@ -1,58 +0,0 @@
|
|||
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)
|
||||
}
|
||||
49
vendor/github.com/eapache/channels/overflowing_channel_test.go
generated
vendored
49
vendor/github.com/eapache/channels/overflowing_channel_test.go
generated
vendored
|
|
@ -1,49 +0,0 @@
|
|||
package channels
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestOverflowingChannel(t *testing.T) {
|
||||
var ch Channel
|
||||
|
||||
ch = NewOverflowingChannel(Infinity) // yes this is rather silly, but it should work
|
||||
testChannel(t, "infinite overflowing channel", ch)
|
||||
|
||||
ch = NewOverflowingChannel(None)
|
||||
go func() {
|
||||
for i := 0; i < 1000; i++ {
|
||||
ch.In() <- i
|
||||
}
|
||||
ch.Close()
|
||||
}()
|
||||
prev := -1
|
||||
for i := range ch.Out() {
|
||||
if prev >= i.(int) {
|
||||
t.Fatal("overflowing channel prev", prev, "but got", i.(int))
|
||||
}
|
||||
}
|
||||
|
||||
ch = NewOverflowingChannel(10)
|
||||
for i := 0; i < 1000; i++ {
|
||||
ch.In() <- i
|
||||
}
|
||||
ch.Close()
|
||||
for i := 0; i < 10; i++ {
|
||||
val := <-ch.Out()
|
||||
if i != val.(int) {
|
||||
t.Fatal("overflowing channel expected", i, "but got", val.(int))
|
||||
}
|
||||
}
|
||||
if val, open := <-ch.Out(); open == true {
|
||||
t.Fatal("overflowing channel expected closed but got", val)
|
||||
}
|
||||
|
||||
ch = NewOverflowingChannel(None)
|
||||
ch.In() <- 0
|
||||
ch.Close()
|
||||
if val, open := <-ch.Out(); open == true {
|
||||
t.Fatal("overflowing channel expected closed but got", val)
|
||||
}
|
||||
|
||||
ch = NewOverflowingChannel(2)
|
||||
testChannelConcurrentAccessors(t, "overflowing channel", ch)
|
||||
}
|
||||
61
vendor/github.com/eapache/channels/resizable_channel_test.go
generated
vendored
61
vendor/github.com/eapache/channels/resizable_channel_test.go
generated
vendored
|
|
@ -1,61 +0,0 @@
|
|||
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))
|
||||
}
|
||||
}
|
||||
}
|
||||
49
vendor/github.com/eapache/channels/ring_channel_test.go
generated
vendored
49
vendor/github.com/eapache/channels/ring_channel_test.go
generated
vendored
|
|
@ -1,49 +0,0 @@
|
|||
package channels
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestRingChannel(t *testing.T) {
|
||||
var ch Channel
|
||||
|
||||
ch = NewRingChannel(Infinity) // yes this is rather silly, but it should work
|
||||
testChannel(t, "infinite ring-buffer channel", ch)
|
||||
|
||||
ch = NewRingChannel(None)
|
||||
go func() {
|
||||
for i := 0; i < 1000; i++ {
|
||||
ch.In() <- i
|
||||
}
|
||||
ch.Close()
|
||||
}()
|
||||
prev := -1
|
||||
for i := range ch.Out() {
|
||||
if prev >= i.(int) {
|
||||
t.Fatal("ring channel prev", prev, "but got", i.(int))
|
||||
}
|
||||
}
|
||||
|
||||
ch = NewRingChannel(10)
|
||||
for i := 0; i < 1000; i++ {
|
||||
ch.In() <- i
|
||||
}
|
||||
ch.Close()
|
||||
for i := 990; i < 1000; i++ {
|
||||
val := <-ch.Out()
|
||||
if i != val.(int) {
|
||||
t.Fatal("ring channel expected", i, "but got", val.(int))
|
||||
}
|
||||
}
|
||||
if val, open := <-ch.Out(); open == true {
|
||||
t.Fatal("ring channel expected closed but got", val)
|
||||
}
|
||||
|
||||
ch = NewRingChannel(None)
|
||||
ch.In() <- 0
|
||||
ch.Close()
|
||||
if val, open := <-ch.Out(); open == true {
|
||||
t.Fatal("ring channel expected closed but got", val)
|
||||
}
|
||||
|
||||
ch = NewRingChannel(2)
|
||||
testChannelConcurrentAccessors(t, "ring channel", ch)
|
||||
}
|
||||
127
vendor/github.com/eapache/channels/shared_buffer_test.go
generated
vendored
127
vendor/github.com/eapache/channels/shared_buffer_test.go
generated
vendored
|
|
@ -1,127 +0,0 @@
|
|||
package channels
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestSharedBufferSingleton(t *testing.T) {
|
||||
buf := NewSharedBuffer(3)
|
||||
|
||||
ch := buf.NewChannel()
|
||||
for i := 0; i < 5; i++ {
|
||||
ch.In() <- (*int)(nil)
|
||||
ch.In() <- (*int)(nil)
|
||||
ch.In() <- (*int)(nil)
|
||||
select {
|
||||
case ch.In() <- (*int)(nil):
|
||||
t.Error("Wrote to full shared-buffer")
|
||||
default:
|
||||
}
|
||||
|
||||
<-ch.Out()
|
||||
<-ch.Out()
|
||||
<-ch.Out()
|
||||
select {
|
||||
case <-ch.Out():
|
||||
t.Error("Read from empty shared-buffer")
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
||||
ch.Close()
|
||||
buf.Close()
|
||||
}
|
||||
|
||||
func TestSharedBufferMultiple(t *testing.T) {
|
||||
buf := NewSharedBuffer(3)
|
||||
|
||||
ch1 := buf.NewChannel()
|
||||
ch2 := buf.NewChannel()
|
||||
|
||||
ch1.In() <- (*int)(nil)
|
||||
ch1.In() <- (*int)(nil)
|
||||
ch1.In() <- (*int)(nil)
|
||||
|
||||
select {
|
||||
case ch2.In() <- (*int)(nil):
|
||||
t.Error("Wrote to full shared-buffer")
|
||||
case <-ch2.Out():
|
||||
t.Error("Read from empty channel")
|
||||
default:
|
||||
}
|
||||
|
||||
<-ch1.Out()
|
||||
|
||||
for i := 0; i < 10; i++ {
|
||||
ch2.In() <- (*int)(nil)
|
||||
|
||||
select {
|
||||
case ch1.In() <- (*int)(nil):
|
||||
t.Error("Wrote to full shared-buffer")
|
||||
case ch2.In() <- (*int)(nil):
|
||||
t.Error("Wrote to full shared-buffer")
|
||||
default:
|
||||
}
|
||||
|
||||
<-ch2.Out()
|
||||
}
|
||||
|
||||
<-ch1.Out()
|
||||
<-ch1.Out()
|
||||
|
||||
ch1.Close()
|
||||
ch2.Close()
|
||||
buf.Close()
|
||||
}
|
||||
|
||||
func TestSharedBufferConcurrent(t *testing.T) {
|
||||
const threads = 10
|
||||
const iters = 200
|
||||
|
||||
buf := NewSharedBuffer(3)
|
||||
done := make(chan bool)
|
||||
|
||||
for i := 0; i < threads; i++ {
|
||||
go func() {
|
||||
ch := buf.NewChannel()
|
||||
for i := 0; i < iters; i++ {
|
||||
ch.In() <- i
|
||||
val := <-ch.Out()
|
||||
if val.(int) != i {
|
||||
t.Error("Mismatched value out of channel")
|
||||
}
|
||||
}
|
||||
ch.Close()
|
||||
done <- true
|
||||
}()
|
||||
}
|
||||
|
||||
for i := 0; i < threads; i++ {
|
||||
<-done
|
||||
}
|
||||
close(done)
|
||||
buf.Close()
|
||||
}
|
||||
|
||||
func ExampleSharedBuffer() {
|
||||
// never more than 3 elements in the pipeline at once
|
||||
buf := NewSharedBuffer(3)
|
||||
|
||||
ch1 := buf.NewChannel()
|
||||
ch2 := buf.NewChannel()
|
||||
|
||||
// or, instead of a straight pipe, implement your pipeline step
|
||||
Pipe(ch1, ch2)
|
||||
|
||||
// inputs
|
||||
go func() {
|
||||
for i := 0; i < 20; i++ {
|
||||
ch1.In() <- i
|
||||
}
|
||||
ch1.Close()
|
||||
}()
|
||||
|
||||
for _ = range ch2.Out() {
|
||||
// outputs
|
||||
}
|
||||
|
||||
buf.Close()
|
||||
}
|
||||
178
vendor/github.com/eapache/queue/queue_test.go
generated
vendored
178
vendor/github.com/eapache/queue/queue_test.go
generated
vendored
|
|
@ -1,178 +0,0 @@
|
|||
package queue
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestQueueSimple(t *testing.T) {
|
||||
q := New()
|
||||
|
||||
for i := 0; i < minQueueLen; i++ {
|
||||
q.Add(i)
|
||||
}
|
||||
for i := 0; i < minQueueLen; i++ {
|
||||
if q.Peek().(int) != i {
|
||||
t.Error("peek", i, "had value", q.Peek())
|
||||
}
|
||||
x := q.Remove()
|
||||
if x != i {
|
||||
t.Error("remove", i, "had value", x)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestQueueWrapping(t *testing.T) {
|
||||
q := New()
|
||||
|
||||
for i := 0; i < minQueueLen; i++ {
|
||||
q.Add(i)
|
||||
}
|
||||
for i := 0; i < 3; i++ {
|
||||
q.Remove()
|
||||
q.Add(minQueueLen + i)
|
||||
}
|
||||
|
||||
for i := 0; i < minQueueLen; i++ {
|
||||
if q.Peek().(int) != i+3 {
|
||||
t.Error("peek", i, "had value", q.Peek())
|
||||
}
|
||||
q.Remove()
|
||||
}
|
||||
}
|
||||
|
||||
func TestQueueLength(t *testing.T) {
|
||||
q := New()
|
||||
|
||||
if q.Length() != 0 {
|
||||
t.Error("empty queue length not 0")
|
||||
}
|
||||
|
||||
for i := 0; i < 1000; i++ {
|
||||
q.Add(i)
|
||||
if q.Length() != i+1 {
|
||||
t.Error("adding: queue with", i, "elements has length", q.Length())
|
||||
}
|
||||
}
|
||||
for i := 0; i < 1000; i++ {
|
||||
q.Remove()
|
||||
if q.Length() != 1000-i-1 {
|
||||
t.Error("removing: queue with", 1000-i-i, "elements has length", q.Length())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestQueueGet(t *testing.T) {
|
||||
q := New()
|
||||
|
||||
for i := 0; i < 1000; i++ {
|
||||
q.Add(i)
|
||||
for j := 0; j < q.Length(); j++ {
|
||||
if q.Get(j).(int) != j {
|
||||
t.Errorf("index %d doesn't contain %d", j, j)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestQueueGetNegative(t *testing.T) {
|
||||
q := New()
|
||||
|
||||
for i := 0; i < 1000; i++ {
|
||||
q.Add(i)
|
||||
for j := 1; j <= q.Length(); j++ {
|
||||
if q.Get(-j).(int) != q.Length()-j {
|
||||
t.Errorf("index %d doesn't contain %d", -j, q.Length()-j)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestQueueGetOutOfRangePanics(t *testing.T) {
|
||||
q := New()
|
||||
|
||||
q.Add(1)
|
||||
q.Add(2)
|
||||
q.Add(3)
|
||||
|
||||
assertPanics(t, "should panic when negative index", func() {
|
||||
q.Get(-4)
|
||||
})
|
||||
|
||||
assertPanics(t, "should panic when index greater than length", func() {
|
||||
q.Get(4)
|
||||
})
|
||||
}
|
||||
|
||||
func TestQueuePeekOutOfRangePanics(t *testing.T) {
|
||||
q := New()
|
||||
|
||||
assertPanics(t, "should panic when peeking empty queue", func() {
|
||||
q.Peek()
|
||||
})
|
||||
|
||||
q.Add(1)
|
||||
q.Remove()
|
||||
|
||||
assertPanics(t, "should panic when peeking emptied queue", func() {
|
||||
q.Peek()
|
||||
})
|
||||
}
|
||||
|
||||
func TestQueueRemoveOutOfRangePanics(t *testing.T) {
|
||||
q := New()
|
||||
|
||||
assertPanics(t, "should panic when removing empty queue", func() {
|
||||
q.Remove()
|
||||
})
|
||||
|
||||
q.Add(1)
|
||||
q.Remove()
|
||||
|
||||
assertPanics(t, "should panic when removing emptied queue", func() {
|
||||
q.Remove()
|
||||
})
|
||||
}
|
||||
|
||||
func assertPanics(t *testing.T, name string, f func()) {
|
||||
defer func() {
|
||||
if r := recover(); r == nil {
|
||||
t.Errorf("%s: didn't panic as expected", name)
|
||||
}
|
||||
}()
|
||||
|
||||
f()
|
||||
}
|
||||
|
||||
// General warning: Go's benchmark utility (go test -bench .) increases the number of
|
||||
// iterations until the benchmarks take a reasonable amount of time to run; memory usage
|
||||
// is *NOT* considered. On my machine, these benchmarks hit around ~1GB before they've had
|
||||
// enough, but if you have less than that available and start swapping, then all bets are off.
|
||||
|
||||
func BenchmarkQueueSerial(b *testing.B) {
|
||||
q := New()
|
||||
for i := 0; i < b.N; i++ {
|
||||
q.Add(nil)
|
||||
}
|
||||
for i := 0; i < b.N; i++ {
|
||||
q.Peek()
|
||||
q.Remove()
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkQueueGet(b *testing.B) {
|
||||
q := New()
|
||||
for i := 0; i < b.N; i++ {
|
||||
q.Add(i)
|
||||
}
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
q.Get(i)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkQueueTickTock(b *testing.B) {
|
||||
q := New()
|
||||
for i := 0; i < b.N; i++ {
|
||||
q.Add(nil)
|
||||
q.Peek()
|
||||
q.Remove()
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue