Commit 4edd768c authored by Brian Tiger Chow's avatar Brian Tiger Chow

pass peer into testnet adapter method

parent 20acf8b7
...@@ -12,10 +12,11 @@ import ( ...@@ -12,10 +12,11 @@ import (
mockrouting "github.com/jbenet/go-ipfs/routing/mock" mockrouting "github.com/jbenet/go-ipfs/routing/mock"
util "github.com/jbenet/go-ipfs/util" util "github.com/jbenet/go-ipfs/util"
delay "github.com/jbenet/go-ipfs/util/delay" delay "github.com/jbenet/go-ipfs/util/delay"
testutil "github.com/jbenet/go-ipfs/util/testutil"
) )
type Network interface { type Network interface {
Adapter(peer.ID) bsnet.BitSwapNetwork Adapter(testutil.Peer) bsnet.BitSwapNetwork
HasPeer(peer.ID) bool HasPeer(peer.ID) bool
} }
...@@ -36,13 +37,13 @@ type network struct { ...@@ -36,13 +37,13 @@ type network struct {
delay delay.D delay delay.D
} }
func (n *network) Adapter(p peer.ID) bsnet.BitSwapNetwork { func (n *network) Adapter(p testutil.Peer) bsnet.BitSwapNetwork {
client := &networkClient{ client := &networkClient{
local: p, local: p.ID(),
network: n, network: n,
routing: n.routingserver.Client(peer.PeerInfo{ID: p}), routing: n.routingserver.Client(peer.PeerInfo{ID: p.ID()}),
} }
n.clients[p] = client n.clients[p.ID()] = client
return client return client
} }
......
...@@ -5,24 +5,24 @@ import ( ...@@ -5,24 +5,24 @@ import (
"testing" "testing"
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"
blocks "github.com/jbenet/go-ipfs/blocks" blocks "github.com/jbenet/go-ipfs/blocks"
bsmsg "github.com/jbenet/go-ipfs/exchange/bitswap/message" bsmsg "github.com/jbenet/go-ipfs/exchange/bitswap/message"
bsnet "github.com/jbenet/go-ipfs/exchange/bitswap/network" bsnet "github.com/jbenet/go-ipfs/exchange/bitswap/network"
peer "github.com/jbenet/go-ipfs/peer" peer "github.com/jbenet/go-ipfs/peer"
mockrouting "github.com/jbenet/go-ipfs/routing/mock" mockrouting "github.com/jbenet/go-ipfs/routing/mock"
delay "github.com/jbenet/go-ipfs/util/delay" delay "github.com/jbenet/go-ipfs/util/delay"
testutil "github.com/jbenet/go-ipfs/util/testutil"
) )
func TestSendRequestToCooperativePeer(t *testing.T) { func TestSendRequestToCooperativePeer(t *testing.T) {
net := VirtualNetwork(mockrouting.NewServer(), delay.Fixed(0)) net := VirtualNetwork(mockrouting.NewServer(), delay.Fixed(0))
idOfRecipient := peer.ID("recipient") recipientPeer := testutil.RandPeerOrFatal(t)
t.Log("Get two network adapters") t.Log("Get two network adapters")
initiator := net.Adapter(peer.ID("initiator")) initiator := net.Adapter(testutil.RandPeerOrFatal(t))
recipient := net.Adapter(idOfRecipient) recipient := net.Adapter(recipientPeer)
expectedStr := "response from recipient" expectedStr := "response from recipient"
recipient.SetDelegate(lambda(func( recipient.SetDelegate(lambda(func(
...@@ -46,7 +46,7 @@ func TestSendRequestToCooperativePeer(t *testing.T) { ...@@ -46,7 +46,7 @@ func TestSendRequestToCooperativePeer(t *testing.T) {
message := bsmsg.New() message := bsmsg.New()
message.AddBlock(blocks.NewBlock([]byte("data"))) message.AddBlock(blocks.NewBlock([]byte("data")))
response, err := initiator.SendRequest( response, err := initiator.SendRequest(
context.Background(), idOfRecipient, message) context.Background(), recipientPeer.ID(), message)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
...@@ -67,9 +67,9 @@ func TestSendRequestToCooperativePeer(t *testing.T) { ...@@ -67,9 +67,9 @@ func TestSendRequestToCooperativePeer(t *testing.T) {
func TestSendMessageAsyncButWaitForResponse(t *testing.T) { func TestSendMessageAsyncButWaitForResponse(t *testing.T) {
net := VirtualNetwork(mockrouting.NewServer(), delay.Fixed(0)) net := VirtualNetwork(mockrouting.NewServer(), delay.Fixed(0))
idOfResponder := peer.ID("responder") responderPeer := testutil.RandPeerOrFatal(t)
waiter := net.Adapter(peer.ID("waiter")) waiter := net.Adapter(testutil.RandPeerOrFatal(t))
responder := net.Adapter(idOfResponder) responder := net.Adapter(responderPeer)
var wg sync.WaitGroup var wg sync.WaitGroup
...@@ -114,7 +114,7 @@ func TestSendMessageAsyncButWaitForResponse(t *testing.T) { ...@@ -114,7 +114,7 @@ func TestSendMessageAsyncButWaitForResponse(t *testing.T) {
messageSentAsync := bsmsg.New() messageSentAsync := bsmsg.New()
messageSentAsync.AddBlock(blocks.NewBlock([]byte("data"))) messageSentAsync.AddBlock(blocks.NewBlock([]byte("data")))
errSending := waiter.SendMessage( errSending := waiter.SendMessage(
context.Background(), idOfResponder, messageSentAsync) context.Background(), responderPeer.ID(), messageSentAsync)
if errSending != nil { if errSending != nil {
t.Fatal(errSending) t.Fatal(errSending)
} }
......
...@@ -80,7 +80,7 @@ func (i *Instance) SetBlockstoreLatency(t time.Duration) time.Duration { ...@@ -80,7 +80,7 @@ func (i *Instance) SetBlockstoreLatency(t time.Duration) time.Duration {
// just a much better idea. // just a much better idea.
func session(ctx context.Context, net tn.Network, p testutil.Peer) Instance { func session(ctx context.Context, net tn.Network, p testutil.Peer) Instance {
adapter := net.Adapter(p.ID()) adapter := net.Adapter(p)
bsdelay := delay.Fixed(0) bsdelay := delay.Fixed(0)
const kWriteCacheElems = 100 const kWriteCacheElems = 100
......
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