core/mock: make sure node has a ctx and proc
License: MIT Signed-off-by: Juan Batiz-Benet <juan@benet.ai>
Juan Batiz-Benet committed
Jul 28, 2015 at 23:26 UTC
5513aabf783d8614aa2c06f7e3d87d535975b7d2
2 files changed
+12
-4
core/core.go
+9
-2
@@ -130,8 +130,12 @@ func NewIPFSNode(ctx context.Context, option ConfigOption) (*IpfsNode, error) {
130
return nil, err
131
}
132
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
+ }
139
140
success := false // flip to true after all sub-system inits succeed
141
defer func() {
@@ -217,6 +221,9 @@ func standardWithRouting(r repo.Repo, online bool, routingOption RoutingOption,
221
Repo: r,
222
}
223
224
+ n.ctx = ctx
225
+ n.proc = goprocessctx.WithContextAndTeardown(ctx, n.teardown)
226
+
227
// setup Peerstore
228
n.Peerstore = peer.NewPeerstore()
229
core/mock/mock.go
+3
-2
@@ -4,6 +4,7 @@ import (
4
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore"
5
syncds "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore/sync"
6
context "github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
7
+
8
"github.com/ipfs/go-ipfs/blocks/blockstore"
9
blockservice "github.com/ipfs/go-ipfs/blockservice"
10
commands "github.com/ipfs/go-ipfs/commands"
@@ -24,7 +25,7 @@ import (
25
26
// TODO this is super sketch. Deprecate and initialize one that shares code
27
// 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?
29
30
// NewMockNode constructs an IpfsNode for use in tests.
31
func NewMockNode() (*core.IpfsNode, error) {
@@ -57,7 +58,7 @@ func NewMockNode() (*core.IpfsNode, error) {
58
nd.Peerstore.AddPubKey(p, ident.PublicKey())
59
nd.Identity = p
60
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
62
if err != nil {
63
return nil, err
64
}