Commit 12b83ff8 authored by Brian Tiger Chow's avatar Brian Tiger Chow Committed by Jeromy

tests(bitswap) share constructor between tests

@whyrusleeping i hope this makes it a bit easier to work with tests

License: MIT
Signed-off-by: default avatarBrian Tiger Chow <brian@perfmode.com>
parent 8a87b709
......@@ -7,7 +7,6 @@ import (
"time"
context "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
ds "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore"
blocks "github.com/jbenet/go-ipfs/blocks"
blockstore "github.com/jbenet/go-ipfs/blockstore"
......@@ -27,9 +26,8 @@ var log = eventlog.Logger("bitswap")
// provided BitSwapNetwork. This function registers the returned instance as
// the network delegate.
// Runs until context is cancelled
func New(ctx context.Context, p peer.Peer,
network bsnet.BitSwapNetwork, routing bsnet.Routing,
d ds.ThreadSafeDatastore, nice bool) exchange.Interface {
func New(ctx context.Context, p peer.Peer, network bsnet.BitSwapNetwork, routing bsnet.Routing,
bstore blockstore.Blockstore, nice bool) exchange.Interface {
notif := notifications.New()
go func() {
......@@ -38,7 +36,7 @@ func New(ctx context.Context, p peer.Peer,
}()
bs := &bitswap{
blockstore: blockstore.NewBlockstore(d),
blockstore: bstore,
notifications: notif,
strategy: strategy.New(nice),
routing: routing,
......
......@@ -11,14 +11,12 @@ import (
ds "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore"
ds_sync "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore/sync"
blocks "github.com/jbenet/go-ipfs/blocks"
blockstore "github.com/jbenet/go-ipfs/blockstore"
bstore "github.com/jbenet/go-ipfs/blockstore"
exchange "github.com/jbenet/go-ipfs/exchange"
notifications "github.com/jbenet/go-ipfs/exchange/bitswap/notifications"
strategy "github.com/jbenet/go-ipfs/exchange/bitswap/strategy"
tn "github.com/jbenet/go-ipfs/exchange/bitswap/testnet"
peer "github.com/jbenet/go-ipfs/peer"
mock "github.com/jbenet/go-ipfs/routing/mock"
util "github.com/jbenet/go-ipfs/util"
)
func TestGetBlockTimeout(t *testing.T) {
......@@ -335,23 +333,16 @@ func session(net tn.Network, rs mock.RoutingServer, id peer.ID) instance {
adapter := net.Adapter(p)
htc := rs.Client(p)
bstore := blockstore.NewBlockstore(ds_sync.MutexWrap(ds.NewMapDatastore()))
blockstore := bstore.NewBlockstore(ds_sync.MutexWrap(ds.NewMapDatastore()))
const alwaysSendToPeer = true
bs := &bitswap{
blockstore: blockstore,
notifications: notifications.New(),
strategy: strategy.New(alwaysSendToPeer),
routing: htc,
sender: adapter,
wantlist: util.NewKeySet(),
batchRequests: make(chan []util.Key, 32),
}
adapter.SetDelegate(bs)
go bs.run(context.TODO())
ctx := context.TODO()
bs := New(ctx, p, adapter, htc, bstore, alwaysSendToPeer)
return instance{
peer: p,
exchange: bs,
blockstore: blockstore,
blockstore: bstore,
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment