From 14eceee35e8cf02fab55c24441d6698c79467dcd Mon Sep 17 00:00:00 2001 From: Juan Batiz-Benet Date: Wed, 28 Jan 2015 23:58:28 -0800 Subject: [PATCH] epictest: fix three-legged-cat http://gateway.ipfs.io/ipfs/QmfUFkQuqjfQzLNhMLwiibiAxnAaZEJAbYkey9orXJ4aQe/3lcat.jpg --- core/bootstrap.go | 7 ++++ test/epictest/three_legged_cat_test.go | 45 ++++++++++++++++++++++---- 2 files changed, 46 insertions(+), 6 deletions(-) diff --git a/core/bootstrap.go b/core/bootstrap.go index 159e683dc..16e5be40d 100644 --- a/core/bootstrap.go +++ b/core/bootstrap.go @@ -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 } diff --git a/test/epictest/three_legged_cat_test.go b/test/epictest/three_legged_cat_test.go index ff3f036a3..49fc1b127 100644 --- a/test/epictest/three_legged_cat_test.go +++ b/test/epictest/three_legged_cat_test.go @@ -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})