Juan Batiz-Benet 2015-01-28 23:58:28 -08:00
parent 958cc61647
commit 14eceee35e
2 changed files with 46 additions and 6 deletions

View File

@ -85,6 +85,9 @@ func Bootstrap(n *IpfsNode, cfg BootstrapConfig) (io.Closer, error) {
return ioutil.NopCloser(nil), nil
}
// make a signal to wait for one bootstrap round to complete.
doneWithRound := make(chan struct{})
// the periodic bootstrap function -- the connection supervisor
periodic := func(worker goprocess.Process) {
ctx := procctx.WithProcessClosing(context.Background(), worker)
@ -94,6 +97,8 @@ func Bootstrap(n *IpfsNode, cfg BootstrapConfig) (io.Closer, error) {
log.Event(ctx, "bootstrapError", n.Identity, lgbl.Error(err))
log.Debugf("%s bootstrap error: %s", n.Identity, err)
}
<-doneWithRound
}
// kick off the node's periodic bootstrapping
@ -109,6 +114,8 @@ func Bootstrap(n *IpfsNode, cfg BootstrapConfig) (io.Closer, error) {
// add dht bootstrap proc as a child, so it is closed automatically when we are.
proc.AddChild(dbproc)
doneWithRound <- struct{}{}
close(doneWithRound) // it no longer blocks periodic
return proc, nil
}

View File

@ -5,6 +5,7 @@ import (
"io"
"math"
"testing"
"time"
context "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
core "github.com/jbenet/go-ipfs/core"
@ -16,7 +17,7 @@ import (
testutil "github.com/jbenet/go-ipfs/util/testutil"
)
func TestThreeLeggedCat(t *testing.T) {
func TestThreeLeggedCat1KBInstantaneous(t *testing.T) {
conf := testutil.LatencyConfig{
NetworkLatency: 0,
RoutingLatency: 0,
@ -27,6 +28,38 @@ func TestThreeLeggedCat(t *testing.T) {
}
}
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(1*unit.KB), conf); err != nil {
t.Fatal(err)
}
}
func RunThreeLeggedCat(data []byte, conf testutil.LatencyConfig) error {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
@ -47,6 +80,11 @@ func RunThreeLeggedCat(data []byte, conf testutil.LatencyConfig) error {
if len(peers) < numPeers {
return errors.New("test initialization error")
}
bootstrap, err := core.NewIPFSNode(ctx, core.ConfigOption(MocknetTestRepo(peers[2], mn.Host(peers[2]), conf)))
if err != nil {
return err
}
defer bootstrap.Close()
adder, err := core.NewIPFSNode(ctx, core.ConfigOption(MocknetTestRepo(peers[0], mn.Host(peers[0]), conf)))
if err != nil {
return err
@ -57,11 +95,6 @@ func RunThreeLeggedCat(data []byte, conf testutil.LatencyConfig) error {
return err
}
defer catter.Close()
bootstrap, err := core.NewIPFSNode(ctx, core.ConfigOption(MocknetTestRepo(peers[2], mn.Host(peers[2]), conf)))
if err != nil {
return err
}
defer bootstrap.Close()
bis := bootstrap.Peerstore.PeerInfo(bootstrap.PeerHost.ID())
bcfg := core.BootstrapConfigWithPeers([]peer.PeerInfo{bis})