mirror of
https://github.com/ipfs/kubo.git
synced 2025-07-01 19:24:14 +08:00
add test for double getting a block
License: MIT Signed-off-by: Jeromy <why@ipfs.io>
This commit is contained in:
@ -308,3 +308,55 @@ func TestBasicBitswap(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestDoubleGet(t *testing.T) {
|
||||||
|
net := tn.VirtualNetwork(mockrouting.NewServer(), delay.Fixed(kNetworkDelay))
|
||||||
|
sg := NewTestSessionGenerator(net)
|
||||||
|
defer sg.Close()
|
||||||
|
bg := blocksutil.NewBlockGenerator()
|
||||||
|
|
||||||
|
t.Log("Test a one node trying to get one block from another")
|
||||||
|
|
||||||
|
instances := sg.Instances(2)
|
||||||
|
blocks := bg.Blocks(1)
|
||||||
|
|
||||||
|
ctx1, cancel1 := context.WithCancel(context.Background())
|
||||||
|
|
||||||
|
blkch1, err := instances[1].Exchange.GetBlocks(ctx1, []key.Key{blocks[0].Key()})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx2, cancel2 := context.WithCancel(context.Background())
|
||||||
|
defer cancel2()
|
||||||
|
|
||||||
|
blkch2, err := instances[1].Exchange.GetBlocks(ctx2, []key.Key{blocks[0].Key()})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
cancel1()
|
||||||
|
|
||||||
|
_, ok := <-blkch1
|
||||||
|
if ok {
|
||||||
|
t.Fatal("expected channel to be closed")
|
||||||
|
}
|
||||||
|
|
||||||
|
err = instances[0].Exchange.HasBlock(blocks[0])
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
blk, ok := <-blkch2
|
||||||
|
if !ok {
|
||||||
|
t.Fatal("expected to get the block here")
|
||||||
|
}
|
||||||
|
t.Log(blk)
|
||||||
|
|
||||||
|
for _, inst := range instances {
|
||||||
|
err := inst.Exchange.Close()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user