Commit 0c7694cb authored by Brian Tiger Chow's avatar Brian Tiger Chow

refactor(mdag, bserv, bs) mocks, etc.

License: MIT
Signed-off-by: default avatarBrian Tiger Chow <brian@perfmode.com>
parent de8b2c68
......@@ -11,10 +11,7 @@ import (
blocks "github.com/jbenet/go-ipfs/blocks"
blockstore "github.com/jbenet/go-ipfs/blocks/blockstore"
blocksutil "github.com/jbenet/go-ipfs/blocks/blocksutil"
bitswap "github.com/jbenet/go-ipfs/exchange/bitswap"
tn "github.com/jbenet/go-ipfs/exchange/bitswap/testnet"
offline "github.com/jbenet/go-ipfs/exchange/offline"
"github.com/jbenet/go-ipfs/routing/mock"
u "github.com/jbenet/go-ipfs/util"
)
......@@ -63,23 +60,9 @@ func TestBlocks(t *testing.T) {
}
func TestGetBlocksSequential(t *testing.T) {
net := tn.VirtualNetwork()
rs := mock.VirtualRoutingServer()
sg := bitswap.NewSessionGenerator(net, rs)
var servs = Mocks(t, 4)
bg := blocksutil.NewBlockGenerator()
instances := sg.Instances(4)
blks := bg.Blocks(50)
// TODO: verify no duplicates
var servs []*BlockService
for _, i := range instances {
bserv, err := New(i.Blockstore, i.Exchange)
if err != nil {
t.Fatal(err)
}
servs = append(servs, bserv)
}
var keys []u.Key
for _, blk := range blks {
......@@ -89,7 +72,7 @@ func TestGetBlocksSequential(t *testing.T) {
t.Log("one instance at a time, get blocks concurrently")
for i := 1; i < len(instances); i++ {
for i := 1; i < len(servs); i++ {
ctx, _ := context.WithTimeout(context.TODO(), time.Second*5)
out := servs[i].GetBlocks(ctx, keys)
gotten := make(map[u.Key]*blocks.Block)
......
package blockservice
import (
"testing"
bitswap "github.com/jbenet/go-ipfs/exchange/bitswap"
tn "github.com/jbenet/go-ipfs/exchange/bitswap/testnet"
"github.com/jbenet/go-ipfs/routing/mock"
)
// Mocks returns |n| connected mock Blockservices
func Mocks(t *testing.T, n int) []*BlockService {
net := tn.VirtualNetwork()
rs := mock.VirtualRoutingServer()
sg := bitswap.NewSessionGenerator(net, rs)
instances := sg.Instances(n)
var servs []*BlockService
for _, i := range instances {
bserv, err := New(i.Blockstore(), i.Exchange)
if err != nil {
t.Fatal(err)
}
servs = append(servs, bserv)
}
return servs
}
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