mirror of
https://github.com/ipfs/kubo.git
synced 2026-03-06 16:58:11 +08:00
- updated go-ctxgroup and goprocess ctxgroup: AddChildGroup was changed to AddChild. Used in two files: - p2p/net/mock/mock_net.go - routing/dht/dht.go - updated context from hg repo to git prev. commit in hg was ad01a6fcc8a19d3a4478c836895ffe883bd2ceab. (context: make parentCancelCtx iterative) represents commit 84f8955a887232b6308d79c68b8db44f64df455c in git repo - updated context to master (b6fdb7d8a4ccefede406f8fe0f017fb58265054c) Aaron Jacobs (2): net/context: Don't accept a context in the DoSomethingSlow example. context: Be clear that users must cancel the result of WithCancel. Andrew Gerrand (1): go.net: use golang.org/x/... import paths Bryan C. Mills (1): net/context: Don't leak goroutines in Done example. Damien Neil (1): context: fix removal of cancelled timer contexts from parent David Symonds (2): context: Fix WithValue example code. net: add import comments. Sameer Ajmani (1): context: fix TestAllocs to account for ints in interfaces
105 lines
2.4 KiB
Go
105 lines
2.4 KiB
Go
package integrationtest
|
|
|
|
import (
|
|
"bytes"
|
|
"testing"
|
|
"time"
|
|
|
|
context "github.com/jbenet/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
|
|
"github.com/jbenet/go-ipfs/blocks"
|
|
"github.com/jbenet/go-ipfs/core"
|
|
mocknet "github.com/jbenet/go-ipfs/p2p/net/mock"
|
|
errors "github.com/jbenet/go-ipfs/util/debugerror"
|
|
testutil "github.com/jbenet/go-ipfs/util/testutil"
|
|
)
|
|
|
|
func TestBitswapWithoutRouting(t *testing.T) {
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
defer cancel()
|
|
const numPeers = 4
|
|
|
|
// create network
|
|
mn, err := mocknet.FullMeshLinked(ctx, numPeers)
|
|
if err != nil {
|
|
t.Fatal(errors.Wrap(err))
|
|
}
|
|
|
|
peers := mn.Peers()
|
|
if len(peers) < numPeers {
|
|
t.Fatal(errors.New("test initialization error"))
|
|
}
|
|
|
|
// set the routing latency to infinity.
|
|
conf := testutil.LatencyConfig{RoutingLatency: (525600 * time.Minute)}
|
|
|
|
var nodes []*core.IpfsNode
|
|
for _, p := range peers {
|
|
n, err := core.NewIPFSNode(ctx, core.ConfigOption(MocknetTestRepo(p, mn.Host(p), conf, core.DHTOption)))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer n.Close()
|
|
nodes = append(nodes, n)
|
|
}
|
|
|
|
// connect them
|
|
for _, n1 := range nodes {
|
|
for _, n2 := range nodes {
|
|
if n1 == n2 {
|
|
continue
|
|
}
|
|
|
|
log.Debug("connecting to other hosts")
|
|
p2 := n2.PeerHost.Peerstore().PeerInfo(n2.PeerHost.ID())
|
|
if err := n1.PeerHost.Connect(ctx, p2); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
}
|
|
|
|
// add blocks to each before
|
|
log.Debug("adding block.")
|
|
block0 := blocks.NewBlock([]byte("block0"))
|
|
block1 := blocks.NewBlock([]byte("block1"))
|
|
|
|
// put 1 before
|
|
if err := nodes[0].Blockstore.Put(block0); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
// get it out.
|
|
for i, n := range nodes {
|
|
// skip first because block not in its exchange. will hang.
|
|
if i == 0 {
|
|
continue
|
|
}
|
|
|
|
log.Debugf("%d %s get block.", i, n.Identity)
|
|
b, err := n.Exchange.GetBlock(ctx, block0.Key())
|
|
if err != nil {
|
|
t.Error(err)
|
|
} else if !bytes.Equal(b.Data, block0.Data) {
|
|
t.Error("byte comparison fail")
|
|
} else {
|
|
log.Debug("got block: %s", b.Key())
|
|
}
|
|
}
|
|
|
|
// put 1 after
|
|
if err := nodes[1].Blockstore.Put(block1); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
// get it out.
|
|
for _, n := range nodes {
|
|
b, err := n.Exchange.GetBlock(ctx, block1.Key())
|
|
if err != nil {
|
|
t.Error(err)
|
|
} else if !bytes.Equal(b.Data, block1.Data) {
|
|
t.Error("byte comparison fail")
|
|
} else {
|
|
log.Debug("got block: %s", b.Key())
|
|
}
|
|
}
|
|
}
|