@cryptotaxi247 / kubo / commits / 14eceee35

epictest: fix three-legged-cat

http://gateway.ipfs.io/ipfs/QmfUFkQuqjfQzLNhMLwiibiAxnAaZEJAbYkey9orXJ4aQe/3lcat.jpg

Juan Batiz-Benet committed Jan 28, 2015 at 23:58 UTC 14eceee35e8cf02fab55c24441d6698c79467dcd
2 files changed +46 -6
core/bootstrap.go
+7
@@ -85,6 +85,9 @@ func Bootstrap(n *IpfsNode, cfg BootstrapConfig) (io.Closer, error) {
85 return ioutil.NopCloser(nil), nil
86 }
87
88 + // make a signal to wait for one bootstrap round to complete.
89 + doneWithRound := make(chan struct{})
90 +
91 // the periodic bootstrap function -- the connection supervisor
92 periodic := func(worker goprocess.Process) {
93 ctx := procctx.WithProcessClosing(context.Background(), worker)
@@ -94,6 +97,8 @@ func Bootstrap(n *IpfsNode, cfg BootstrapConfig) (io.Closer, error) {
97 log.Event(ctx, "bootstrapError", n.Identity, lgbl.Error(err))
98 log.Debugf("%s bootstrap error: %s", n.Identity, err)
99 }
100 +
101 + <-doneWithRound
102 }
103
104 // kick off the node's periodic bootstrapping
@@ -109,6 +114,8 @@ func Bootstrap(n *IpfsNode, cfg BootstrapConfig) (io.Closer, error) {
114
115 // add dht bootstrap proc as a child, so it is closed automatically when we are.
116 proc.AddChild(dbproc)
117 + doneWithRound <- struct{}{}
118 + close(doneWithRound) // it no longer blocks periodic
119 return proc, nil
120 }
121
test/epictest/three_legged_cat_test.go
+39 -6
@@ -5,6 +5,7 @@ import (
5 "io"
6 "math"
7 "testing"
8 + "time"
9
10 context "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
11 core "github.com/jbenet/go-ipfs/core"
@@ -16,7 +17,7 @@ import (
17 testutil "github.com/jbenet/go-ipfs/util/testutil"
18 )
19
19 -func TestThreeLeggedCat(t *testing.T) {
20 +func TestThreeLeggedCat1KBInstantaneous(t *testing.T) {
21 conf := testutil.LatencyConfig{
22 NetworkLatency: 0,
23 RoutingLatency: 0,
@@ -27,6 +28,38 @@ func TestThreeLeggedCat(t *testing.T) {
28 }
29 }
30
31 +func TestThreeLeggedCatDegenerateSlowBlockstore(t *testing.T) {
32 + SkipUnlessEpic(t)
33 + conf := testutil.LatencyConfig{BlockstoreLatency: 50 * time.Millisecond}
34 + if err := RunThreeLeggedCat(RandomBytes(1*unit.KB), conf); err != nil {
35 + t.Fatal(err)
36 + }
37 +}
38 +
39 +func TestThreeLeggedCatDegenerateSlowNetwork(t *testing.T) {
40 + SkipUnlessEpic(t)
41 + conf := testutil.LatencyConfig{NetworkLatency: 400 * time.Millisecond}
42 + if err := RunThreeLeggedCat(RandomBytes(1*unit.KB), conf); err != nil {
43 + t.Fatal(err)
44 + }
45 +}
46 +
47 +func TestThreeLeggedCatDegenerateSlowRouting(t *testing.T) {
48 + SkipUnlessEpic(t)
49 + conf := testutil.LatencyConfig{RoutingLatency: 400 * time.Millisecond}
50 + if err := RunThreeLeggedCat(RandomBytes(1*unit.KB), conf); err != nil {
51 + t.Fatal(err)
52 + }
53 +}
54 +
55 +func TestThreeLeggedCat100MBMacbookCoastToCoast(t *testing.T) {
56 + SkipUnlessEpic(t)
57 + conf := testutil.LatencyConfig{}.Network_NYtoSF().Blockstore_SlowSSD2014().Routing_Slow()
58 + if err := RunThreeLeggedCat(RandomBytes(1*unit.KB), conf); err != nil {
59 + t.Fatal(err)
60 + }
61 +}
62 +
63 func RunThreeLeggedCat(data []byte, conf testutil.LatencyConfig) error {
64 ctx, cancel := context.WithCancel(context.Background())
65 defer cancel()
@@ -47,6 +80,11 @@ func RunThreeLeggedCat(data []byte, conf testutil.LatencyConfig) error {
80 if len(peers) < numPeers {
81 return errors.New("test initialization error")
82 }
83 + bootstrap, err := core.NewIPFSNode(ctx, core.ConfigOption(MocknetTestRepo(peers[2], mn.Host(peers[2]), conf)))
84 + if err != nil {
85 + return err
86 + }
87 + defer bootstrap.Close()
88 adder, err := core.NewIPFSNode(ctx, core.ConfigOption(MocknetTestRepo(peers[0], mn.Host(peers[0]), conf)))
89 if err != nil {
90 return err
@@ -57,11 +95,6 @@ func RunThreeLeggedCat(data []byte, conf testutil.LatencyConfig) error {
95 return err
96 }
97 defer catter.Close()
60 - bootstrap, err := core.NewIPFSNode(ctx, core.ConfigOption(MocknetTestRepo(peers[2], mn.Host(peers[2]), conf)))
61 - if err != nil {
62 - return err
63 - }
64 - defer bootstrap.Close()
98
99 bis := bootstrap.Peerstore.PeerInfo(bootstrap.PeerHost.ID())
100 bcfg := core.BootstrapConfigWithPeers([]peer.PeerInfo{bis})