-
Notifications
You must be signed in to change notification settings - Fork 0
/
shimqueue_test.go
60 lines (51 loc) · 1.33 KB
/
shimqueue_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package eventbus_test
import (
"github.com/bmizerany/assert"
"github.com/jamesharr/eventbus"
"math/rand"
"testing"
)
func ShimFillAndDrain(t *testing.T, items []interface{}, input chan eventbus.Message, output chan eventbus.Message) {
// Send all
for _, item := range items {
t.Logf("sending %#v", item)
input <- item
}
close(input)
// Receive all
items_received := make([]interface{}, len(items))[0:0]
for {
item, ok := <-output
if ok {
t.Logf("received %#v", item)
items_received = append(items_received, item)
} else {
break
}
}
assert.Equal(t, items, items_received, "Item equivalency & Ordering test")
}
func createShim() (chan eventbus.Message, chan eventbus.Message) {
input := make(chan eventbus.Message)
output := make(chan eventbus.Message)
eventbus.CreateShimQueue(input, output)
return input, output
}
func TestShimEmpty(t *testing.T) {
input, output := createShim()
items := []interface{}{}
ShimFillAndDrain(t, items, input, output)
}
func TestShimSmall(t *testing.T) {
input, output := createShim()
items := []interface{}{5, 6, 7, 8, 9}
ShimFillAndDrain(t, items, input, output)
}
func TestShimLarge(t *testing.T) {
input, output := createShim()
items := make([]interface{}, 1000)
for i := 0; i < len(items); i++ {
items[i] = rand.Int63()
}
ShimFillAndDrain(t, items, input, output)
}