Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-bitswap
Commits
1c24fdaa
Commit
1c24fdaa
authored
Dec 12, 2014
by
Brian Tiger Chow
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor(mockrouting) misc
License: MIT Signed-off-by:
Brian Tiger Chow
<
brian@perfmode.com
>
parent
1c9c90ae
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
13 deletions
+15
-13
bitswap_test.go
bitswap_test.go
+11
-9
testutils.go
testutils.go
+4
-4
No files found.
bitswap_test.go
View file @
1c24fdaa
...
...
@@ -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"
mock
routing
"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
.
VirtualR
outingServer
()
rout
:=
mock
r
outing
.
New
Server
()
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
.
VirtualR
outingServer
()
rs
:=
mock
r
outing
.
New
Server
()
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
.
VirtualR
outingServer
()
rs
:=
mock
r
outing
.
New
Server
()
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
.
VirtualR
outingServer
()
rs
:=
mock
r
outing
.
New
Server
()
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
.
VirtualR
outingServer
()
rs
:=
mock
r
outing
.
New
Server
()
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
.
VirtualR
outingServer
()
rs
:=
mock
r
outing
.
New
Server
()
sg
:=
NewSessionGenerator
(
net
,
rs
)
bg
:=
blocksutil
.
NewBlockGenerator
()
...
...
testutils.go
View file @
1c24fdaa
...
...
@@ -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"
mock
routing
"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
.
R
outingServer
)
SessionGenerator
{
net
tn
.
Network
,
rs
mock
r
outing
.
Server
)
SessionGenerator
{
return
SessionGenerator
{
net
:
net
,
rs
:
rs
,
...
...
@@ -28,7 +28,7 @@ func NewSessionGenerator(
type
SessionGenerator
struct
{
seq
int
net
tn
.
Network
rs
mock
.
R
outingServer
rs
mock
r
outing
.
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
.
R
outingServer
,
ps
peer
.
Peerstore
,
id
peer
.
ID
)
Instance
{
func
session
(
net
tn
.
Network
,
rs
mock
r
outing
.
Server
,
ps
peer
.
Peerstore
,
id
peer
.
ID
)
Instance
{
p
:=
ps
.
WithID
(
id
)
adapter
:=
net
.
Adapter
(
p
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment