mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-23 19:37:46 +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
126 lines
3.4 KiB
Go
126 lines
3.4 KiB
Go
package integrationtest
|
|
|
|
import (
|
|
"bytes"
|
|
"io"
|
|
"math"
|
|
"testing"
|
|
"time"
|
|
|
|
context "github.com/jbenet/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
|
|
core "github.com/jbenet/go-ipfs/core"
|
|
coreunix "github.com/jbenet/go-ipfs/core/coreunix"
|
|
mocknet "github.com/jbenet/go-ipfs/p2p/net/mock"
|
|
"github.com/jbenet/go-ipfs/p2p/peer"
|
|
"github.com/jbenet/go-ipfs/thirdparty/unit"
|
|
errors "github.com/jbenet/go-ipfs/util/debugerror"
|
|
testutil "github.com/jbenet/go-ipfs/util/testutil"
|
|
)
|
|
|
|
func TestThreeLeggedCatTransfer(t *testing.T) {
|
|
conf := testutil.LatencyConfig{
|
|
NetworkLatency: 0,
|
|
RoutingLatency: 0,
|
|
BlockstoreLatency: 0,
|
|
}
|
|
if err := RunThreeLeggedCat(RandomBytes(100*unit.MB), conf); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
func TestThreeLeggedCatDegenerateSlowBlockstore(t *testing.T) {
|
|
SkipUnlessEpic(t)
|
|
conf := testutil.LatencyConfig{BlockstoreLatency: 50 * time.Millisecond}
|
|
if err := RunThreeLeggedCat(RandomBytes(1*unit.KB), conf); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
func TestThreeLeggedCatDegenerateSlowNetwork(t *testing.T) {
|
|
SkipUnlessEpic(t)
|
|
conf := testutil.LatencyConfig{NetworkLatency: 400 * time.Millisecond}
|
|
if err := RunThreeLeggedCat(RandomBytes(1*unit.KB), conf); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
func TestThreeLeggedCatDegenerateSlowRouting(t *testing.T) {
|
|
SkipUnlessEpic(t)
|
|
conf := testutil.LatencyConfig{RoutingLatency: 400 * time.Millisecond}
|
|
if err := RunThreeLeggedCat(RandomBytes(1*unit.KB), conf); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
func TestThreeLeggedCat100MBMacbookCoastToCoast(t *testing.T) {
|
|
SkipUnlessEpic(t)
|
|
conf := testutil.LatencyConfig{}.Network_NYtoSF().Blockstore_SlowSSD2014().Routing_Slow()
|
|
if err := RunThreeLeggedCat(RandomBytes(100*unit.MB), conf); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
func RunThreeLeggedCat(data []byte, conf testutil.LatencyConfig) error {
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
defer cancel()
|
|
const numPeers = 3
|
|
|
|
// create network
|
|
mn, err := mocknet.FullMeshLinked(ctx, numPeers)
|
|
if err != nil {
|
|
return errors.Wrap(err)
|
|
}
|
|
mn.SetLinkDefaults(mocknet.LinkOptions{
|
|
Latency: conf.NetworkLatency,
|
|
// TODO add to conf. This is tricky because we want 0 values to be functional.
|
|
Bandwidth: math.MaxInt32,
|
|
})
|
|
|
|
peers := mn.Peers()
|
|
if len(peers) < numPeers {
|
|
return errors.New("test initialization error")
|
|
}
|
|
bootstrap, err := core.NewIPFSNode(ctx, MocknetTestRepo(peers[2], mn.Host(peers[2]), conf, core.DHTOption))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer bootstrap.Close()
|
|
adder, err := core.NewIPFSNode(ctx, MocknetTestRepo(peers[0], mn.Host(peers[0]), conf, core.DHTOption))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer adder.Close()
|
|
catter, err := core.NewIPFSNode(ctx, MocknetTestRepo(peers[1], mn.Host(peers[1]), conf, core.DHTOption))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer catter.Close()
|
|
|
|
bis := bootstrap.Peerstore.PeerInfo(bootstrap.PeerHost.ID())
|
|
bcfg := core.BootstrapConfigWithPeers([]peer.PeerInfo{bis})
|
|
if err := adder.Bootstrap(bcfg); err != nil {
|
|
return err
|
|
}
|
|
if err := catter.Bootstrap(bcfg); err != nil {
|
|
return err
|
|
}
|
|
|
|
added, err := coreunix.Add(adder, bytes.NewReader(data))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
readerCatted, err := coreunix.Cat(catter, added)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
// verify
|
|
var bufout bytes.Buffer
|
|
io.Copy(&bufout, readerCatted)
|
|
if 0 != bytes.Compare(bufout.Bytes(), data) {
|
|
return errors.New("catted data does not match added data")
|
|
}
|
|
return nil
|
|
}
|