提交 fc820a81 作者: Brian Tiger Chow 提交者: Jeromy

tests(forward)

License: MIT
Signed-off-by: 's avatarBrian Tiger Chow <brian@perfmode.com>
上级 be267852
......@@ -7,23 +7,26 @@ import (
"github.com/jbenet/go-ipfs/blocks"
)
func TestForwardTwo(t *testing.T) {
func TestForwardNThenClose(t *testing.T) {
const n = 2
in := make(chan *blocks.Block, n)
const buf = 2 * n
in := make(chan *blocks.Block, buf)
ctx := context.Background()
out := ForwardN(ctx, in, n)
in <- blocks.NewBlock([]byte("one"))
in <- blocks.NewBlock([]byte("two"))
for i := 0; i < buf; i++ {
in <- blocks.NewBlock([]byte(""))
}
_ = <-out // 1
_ = <-out // 2
for i := 0; i < n; i++ {
_ = <-out
}
_, ok := <-out // closed
if !ok {
return
}
t.Fail()
t.Fatal("channel still open after receiving n blocks")
}
func TestCloseInput(t *testing.T) {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论