Commit 1c24fdaa authored by Brian Tiger Chow's avatar Brian Tiger Chow

refactor(mockrouting) misc

License: MIT
Signed-off-by: default avatarBrian Tiger Chow <brian@perfmode.com>
parent 1c9c90ae
......@@ -10,18 +10,20 @@ import (
blocks "github.com/jbenet/go-ipfs/blocks"
blocksutil "github.com/jbenet/go-ipfs/blocks/blocksutil"
tn "github.com/jbenet/go-ipfs/exchange/bitswap/testnet"
mock "github.com/jbenet/go-ipfs/routing/mock"
mockrouting "github.com/jbenet/go-ipfs/routing/mock"
delay "github.com/jbenet/go-ipfs/util/delay"
testutil "github.com/jbenet/go-ipfs/util/testutil"
)
// FIXME the tests are really sensitive to the network delay. fix them to work
// well under varying conditions
const kNetworkDelay = 0 * time.Millisecond
func TestClose(t *testing.T) {
// TODO
t.Skip("TODO Bitswap's Close implementation is a WIP")
vnet := tn.VirtualNetwork(delay.Fixed(kNetworkDelay))
rout := mock.VirtualRoutingServer()
rout := mockrouting.NewServer()
sesgen := NewSessionGenerator(vnet, rout)
bgen := blocksutil.NewBlockGenerator()
......@@ -35,7 +37,7 @@ func TestClose(t *testing.T) {
func TestGetBlockTimeout(t *testing.T) {
net := tn.VirtualNetwork(delay.Fixed(kNetworkDelay))
rs := mock.VirtualRoutingServer()
rs := mockrouting.NewServer()
g := NewSessionGenerator(net, rs)
self := g.Next()
......@@ -52,11 +54,11 @@ func TestGetBlockTimeout(t *testing.T) {
func TestProviderForKeyButNetworkCannotFind(t *testing.T) {
net := tn.VirtualNetwork(delay.Fixed(kNetworkDelay))
rs := mock.VirtualRoutingServer()
rs := mockrouting.NewServer()
g := NewSessionGenerator(net, rs)
block := blocks.NewBlock([]byte("block"))
rs.Announce(testutil.NewPeerWithIDString("testing"), block.Key()) // but not on network
rs.Client(testutil.NewPeerWithIDString("testing")).Provide(context.Background(), block.Key()) // but not on network
solo := g.Next()
......@@ -73,7 +75,7 @@ func TestProviderForKeyButNetworkCannotFind(t *testing.T) {
func TestGetBlockFromPeerAfterPeerAnnounces(t *testing.T) {
net := tn.VirtualNetwork(delay.Fixed(kNetworkDelay))
rs := mock.VirtualRoutingServer()
rs := mockrouting.NewServer()
block := blocks.NewBlock([]byte("block"))
g := NewSessionGenerator(net, rs)
......@@ -125,7 +127,7 @@ func PerformDistributionTest(t *testing.T, numInstances, numBlocks int) {
t.SkipNow()
}
net := tn.VirtualNetwork(delay.Fixed(kNetworkDelay))
rs := mock.VirtualRoutingServer()
rs := mockrouting.NewServer()
sg := NewSessionGenerator(net, rs)
bg := blocksutil.NewBlockGenerator()
......@@ -140,7 +142,7 @@ func PerformDistributionTest(t *testing.T, numInstances, numBlocks int) {
for _, b := range blocks {
first.Blockstore().Put(b)
first.Exchange.HasBlock(context.Background(), b)
rs.Announce(first.Peer, b.Key())
rs.Client(first.Peer).Provide(context.Background(), b.Key())
}
t.Log("Distribute!")
......@@ -185,7 +187,7 @@ func TestSendToWantingPeer(t *testing.T) {
}
net := tn.VirtualNetwork(delay.Fixed(kNetworkDelay))
rs := mock.VirtualRoutingServer()
rs := mockrouting.NewServer()
sg := NewSessionGenerator(net, rs)
bg := blocksutil.NewBlockGenerator()
......
......@@ -10,13 +10,13 @@ import (
exchange "github.com/jbenet/go-ipfs/exchange"
tn "github.com/jbenet/go-ipfs/exchange/bitswap/testnet"
peer "github.com/jbenet/go-ipfs/peer"
mock "github.com/jbenet/go-ipfs/routing/mock"
mockrouting "github.com/jbenet/go-ipfs/routing/mock"
datastore2 "github.com/jbenet/go-ipfs/util/datastore2"
delay "github.com/jbenet/go-ipfs/util/delay"
)
func NewSessionGenerator(
net tn.Network, rs mock.RoutingServer) SessionGenerator {
net tn.Network, rs mockrouting.Server) SessionGenerator {
return SessionGenerator{
net: net,
rs: rs,
......@@ -28,7 +28,7 @@ func NewSessionGenerator(
type SessionGenerator struct {
seq int
net tn.Network
rs mock.RoutingServer
rs mockrouting.Server
ps peer.Peerstore
}
......@@ -67,7 +67,7 @@ func (i *Instance) SetBlockstoreLatency(t time.Duration) time.Duration {
// NB: It's easy make mistakes by providing the same peer ID to two different
// sessions. To safeguard, use the SessionGenerator to generate sessions. It's
// just a much better idea.
func session(net tn.Network, rs mock.RoutingServer, ps peer.Peerstore, id peer.ID) Instance {
func session(net tn.Network, rs mockrouting.Server, ps peer.Peerstore, id peer.ID) Instance {
p := ps.WithID(id)
adapter := net.Adapter(p)
......
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