tests(forward)
License: MIT Signed-off-by: Brian Tiger Chow <brian@perfmode.com>
Brian Tiger Chow committed
Nov 21, 2014 at 13:15 UTC
fc820a8110324653ac846de6af47ada8aff5e332
1 file changed
+10
-7
util/async/forward_test.go
+10
-7
@@ -7,23 +7,26 @@ import (
7
"github.com/jbenet/go-ipfs/blocks"
8
)
9
10
-func TestForwardTwo(t *testing.T) {
10
+func TestForwardNThenClose(t *testing.T) {
11
const n = 2
12
- in := make(chan *blocks.Block, n)
12
+ const buf = 2 * n
13
+ in := make(chan *blocks.Block, buf)
14
ctx := context.Background()
15
out := ForwardN(ctx, in, n)
16
16
- in <- blocks.NewBlock([]byte("one"))
17
- in <- blocks.NewBlock([]byte("two"))
17
+ for i := 0; i < buf; i++ {
18
+ in <- blocks.NewBlock([]byte(""))
19
+ }
20
19
- _ = <-out // 1
20
- _ = <-out // 2
21
+ for i := 0; i < n; i++ {
22
+ _ = <-out
23
+ }
24
25
_, ok := <-out // closed
26
if !ok {
27
return
28
}
26
- t.Fail()
29
+ t.Fatal("channel still open after receiving n blocks")
30
}
31
32
func TestCloseInput(t *testing.T) {