Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
core/mock: make sure node has a ctx and proc
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Juan Batiz-Benet <juan@benet.ai>
jbenet committed Jul 29, 2015
1 parent c64f743 commit 0578b62
Showing 2 changed files with 12 additions and 4 deletions.
11 changes: 9 additions & 2 deletions core/core.go
Original file line number Diff line number Diff line change
@@ -130,8 +130,12 @@ func NewIPFSNode(ctx context.Context, option ConfigOption) (*IpfsNode, error) {
return nil, err
}

node.proc = goprocessctx.WithContextAndTeardown(ctx, node.teardown)
node.ctx = ctx
if node.ctx == nil {
node.ctx = ctx
}
if node.proc == nil {
node.proc = goprocessctx.WithContextAndTeardown(node.ctx, node.teardown)
}

success := false // flip to true after all sub-system inits succeed
defer func() {
@@ -217,6 +221,9 @@ func standardWithRouting(r repo.Repo, online bool, routingOption RoutingOption,
Repo: r,
}

n.ctx = ctx
n.proc = goprocessctx.WithContextAndTeardown(ctx, n.teardown)

// setup Peerstore
n.Peerstore = peer.NewPeerstore()

5 changes: 3 additions & 2 deletions core/mock/mock.go
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@ import (
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore"
syncds "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore/sync"
context "github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"

"github.com/ipfs/go-ipfs/blocks/blockstore"
blockservice "github.com/ipfs/go-ipfs/blockservice"
core "github.com/ipfs/go-ipfs/core"
@@ -23,7 +24,7 @@ import (

// TODO this is super sketch. Deprecate and initialize one that shares code
// with the actual core constructor. Lots of fields aren't initialized.
// Additionally, the context group isn't wired up. This is as good as broken.
// "This is as good as broken." --- is it?

// NewMockNode constructs an IpfsNode for use in tests.
func NewMockNode() (*core.IpfsNode, error) {
@@ -56,7 +57,7 @@ func NewMockNode() (*core.IpfsNode, error) {
nd.Peerstore.AddPubKey(p, ident.PublicKey())
nd.Identity = p

nd.PeerHost, err = mocknet.New(ctx).AddPeer(ident.PrivateKey(), ident.Address()) // effectively offline
nd.PeerHost, err = mocknet.New(nd.Context()).AddPeer(ident.PrivateKey(), ident.Address()) // effectively offline
if err != nil {
return nil, err
}

0 comments on commit 0578b62

Please sign in to comment.