Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 0578b62

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 c64f743 commit 0578b62

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
core "github.com/ipfs/go-ipfs/core"
@@ -23,7 +24,7 @@ import (
2324

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

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

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

0 commit comments

Comments
 (0)
Please sign in to comment.