Skip to content

Commit 5513aab

Browse files
committedJul 29, 2015
core/mock: make sure node has a ctx and proc
License: MIT Signed-off-by: Juan Batiz-Benet <juan@benet.ai>
1 parent 3f6cca8 commit 5513aab

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed
 

‎core/core.go

+9-2
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,12 @@ func NewIPFSNode(ctx context.Context, option ConfigOption) (*IpfsNode, error) {
130130
return nil, err
131131
}
132132

133-
node.proc = goprocessctx.WithContextAndTeardown(ctx, node.teardown)
134-
node.ctx = ctx
133+
if node.ctx == nil {
134+
node.ctx = ctx
135+
}
136+
if node.proc == nil {
137+
node.proc = goprocessctx.WithContextAndTeardown(node.ctx, node.teardown)
138+
}
135139

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

224+
n.ctx = ctx
225+
n.proc = goprocessctx.WithContextAndTeardown(ctx, n.teardown)
226+
220227
// setup Peerstore
221228
n.Peerstore = peer.NewPeerstore()
222229

‎core/mock/mock.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore"
55
syncds "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore/sync"
66
context "github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
7+
78
"github.com/ipfs/go-ipfs/blocks/blockstore"
89
blockservice "github.com/ipfs/go-ipfs/blockservice"
910
commands "github.com/ipfs/go-ipfs/commands"
@@ -24,7 +25,7 @@ import (
2425

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

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

60-
nd.PeerHost, err = mocknet.New(ctx).AddPeer(ident.PrivateKey(), ident.Address()) // effectively offline
61+
nd.PeerHost, err = mocknet.New(nd.Context()).AddPeer(ident.PrivateKey(), ident.Address()) // effectively offline
6162
if err != nil {
6263
return nil, err
6364
}

0 commit comments

Comments
 (0)
Please sign in to comment.