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 ( ...@@ -7,7 +7,6 @@ import (
"time" "time"
context "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context" 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" blocks "github.com/jbenet/go-ipfs/blocks"
blockstore "github.com/jbenet/go-ipfs/blockstore" blockstore "github.com/jbenet/go-ipfs/blockstore"
...@@ -27,9 +26,8 @@ var log = eventlog.Logger("bitswap") ...@@ -27,9 +26,8 @@ var log = eventlog.Logger("bitswap")
// provided BitSwapNetwork. This function registers the returned instance as // provided BitSwapNetwork. This function registers the returned instance as
// the network delegate. // the network delegate.
// Runs until context is cancelled // Runs until context is cancelled
func New(ctx context.Context, p peer.Peer, func New(ctx context.Context, p peer.Peer, network bsnet.BitSwapNetwork, routing bsnet.Routing,
network bsnet.BitSwapNetwork, routing bsnet.Routing, bstore blockstore.Blockstore, nice bool) exchange.Interface {
d ds.ThreadSafeDatastore, nice bool) exchange.Interface {
notif := notifications.New() notif := notifications.New()
go func() { go func() {
...@@ -38,7 +36,7 @@ func New(ctx context.Context, p peer.Peer, ...@@ -38,7 +36,7 @@ func New(ctx context.Context, p peer.Peer,
}() }()
bs := &bitswap{ bs := &bitswap{
blockstore: blockstore.NewBlockstore(d), blockstore: bstore,
notifications: notif, notifications: notif,
strategy: strategy.New(nice), strategy: strategy.New(nice),
routing: routing, routing: routing,
......
...@@ -11,14 +11,12 @@ import ( ...@@ -11,14 +11,12 @@ import (
ds "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore" 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" ds_sync "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore/sync"
blocks "github.com/jbenet/go-ipfs/blocks" blocks "github.com/jbenet/go-ipfs/blocks"
blockstore "github.com/jbenet/go-ipfs/blockstore"
bstore "github.com/jbenet/go-ipfs/blockstore" bstore "github.com/jbenet/go-ipfs/blockstore"
exchange "github.com/jbenet/go-ipfs/exchange" 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" tn "github.com/jbenet/go-ipfs/exchange/bitswap/testnet"
peer "github.com/jbenet/go-ipfs/peer" peer "github.com/jbenet/go-ipfs/peer"
mock "github.com/jbenet/go-ipfs/routing/mock" mock "github.com/jbenet/go-ipfs/routing/mock"
util "github.com/jbenet/go-ipfs/util"
) )
func TestGetBlockTimeout(t *testing.T) { func TestGetBlockTimeout(t *testing.T) {
...@@ -335,23 +333,16 @@ func session(net tn.Network, rs mock.RoutingServer, id peer.ID) instance { ...@@ -335,23 +333,16 @@ func session(net tn.Network, rs mock.RoutingServer, id peer.ID) instance {
adapter := net.Adapter(p) adapter := net.Adapter(p)
htc := rs.Client(p) htc := rs.Client(p)
bstore := blockstore.NewBlockstore(ds_sync.MutexWrap(ds.NewMapDatastore()))
blockstore := bstore.NewBlockstore(ds_sync.MutexWrap(ds.NewMapDatastore()))
const alwaysSendToPeer = true const alwaysSendToPeer = true
bs := &bitswap{ ctx := context.TODO()
blockstore: blockstore,
notifications: notifications.New(), bs := New(ctx, p, adapter, htc, bstore, alwaysSendToPeer)
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())
return instance{ return instance{
peer: p, peer: p,
exchange: bs, 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