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
c211b061
Commit
c211b061
authored
Dec 12, 2014
by
Brian Tiger Chow
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor(mdag, bserv, bs) mocks, etc.
License: MIT Signed-off-by:
Brian Tiger Chow
<
brian@perfmode.com
>
parent
aa10757f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
17 deletions
+34
-17
bitswap_test.go
bitswap_test.go
+7
-7
testutils.go
testutils.go
+27
-10
No files found.
bitswap_test.go
View file @
c211b061
...
...
@@ -76,7 +76,7 @@ func TestGetBlockFromPeerAfterPeerAnnounces(t *testing.T) {
hasBlock
:=
g
.
Next
()
if
err
:=
hasBlock
.
Blockstore
.
Put
(
block
);
err
!=
nil
{
if
err
:=
hasBlock
.
Blockstore
()
.
Put
(
block
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
err
:=
hasBlock
.
Exchange
.
HasBlock
(
context
.
Background
(),
block
);
err
!=
nil
{
...
...
@@ -135,7 +135,7 @@ func PerformDistributionTest(t *testing.T, numInstances, numBlocks int) {
first
:=
instances
[
0
]
for
_
,
b
:=
range
blocks
{
first
.
Blockstore
.
Put
(
b
)
first
.
Blockstore
()
.
Put
(
b
)
first
.
Exchange
.
HasBlock
(
context
.
Background
(),
b
)
rs
.
Announce
(
first
.
Peer
,
b
.
Key
())
}
...
...
@@ -158,7 +158,7 @@ func PerformDistributionTest(t *testing.T, numInstances, numBlocks int) {
for
_
,
inst
:=
range
instances
{
for
_
,
b
:=
range
blocks
{
if
_
,
err
:=
inst
.
Blockstore
.
Get
(
b
.
Key
());
err
!=
nil
{
if
_
,
err
:=
inst
.
Blockstore
()
.
Get
(
b
.
Key
());
err
!=
nil
{
t
.
Fatal
(
err
)
}
}
...
...
@@ -166,7 +166,7 @@ func PerformDistributionTest(t *testing.T, numInstances, numBlocks int) {
}
func
getOrFail
(
bitswap
Instance
,
b
*
blocks
.
Block
,
t
*
testing
.
T
,
wg
*
sync
.
WaitGroup
)
{
if
_
,
err
:=
bitswap
.
Blockstore
.
Get
(
b
.
Key
());
err
!=
nil
{
if
_
,
err
:=
bitswap
.
Blockstore
()
.
Get
(
b
.
Key
());
err
!=
nil
{
_
,
err
:=
bitswap
.
Exchange
.
GetBlock
(
context
.
Background
(),
b
.
Key
())
if
err
!=
nil
{
t
.
Fatal
(
err
)
...
...
@@ -208,7 +208,7 @@ func TestSendToWantingPeer(t *testing.T) {
beta
:=
bg
.
Next
()
t
.
Logf
(
"Peer %v announes availability of %v
\n
"
,
w
.
Peer
,
beta
.
Key
())
ctx
,
_
=
context
.
WithTimeout
(
context
.
Background
(),
timeout
)
if
err
:=
w
.
Blockstore
.
Put
(
beta
);
err
!=
nil
{
if
err
:=
w
.
Blockstore
()
.
Put
(
beta
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
w
.
Exchange
.
HasBlock
(
ctx
,
beta
)
...
...
@@ -221,7 +221,7 @@ func TestSendToWantingPeer(t *testing.T) {
t
.
Logf
(
"%v announces availability of %v
\n
"
,
o
.
Peer
,
alpha
.
Key
())
ctx
,
_
=
context
.
WithTimeout
(
context
.
Background
(),
timeout
)
if
err
:=
o
.
Blockstore
.
Put
(
alpha
);
err
!=
nil
{
if
err
:=
o
.
Blockstore
()
.
Put
(
alpha
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
o
.
Exchange
.
HasBlock
(
ctx
,
alpha
)
...
...
@@ -233,7 +233,7 @@ func TestSendToWantingPeer(t *testing.T) {
}
t
.
Logf
(
"%v should now have %v
\n
"
,
w
.
Peer
,
alpha
.
Key
())
block
,
err
:=
w
.
Blockstore
.
Get
(
alpha
.
Key
())
block
,
err
:=
w
.
Blockstore
()
.
Get
(
alpha
.
Key
())
if
err
!=
nil
{
t
.
Fatalf
(
"Should not have received an error: %s"
,
err
)
}
...
...
testutils.go
View file @
c211b061
package
bitswap
import
(
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
"time"
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"
ds_sync
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore/sync"
"github.com/jbenet/go-ipfs/blocks/blockstore"
"github.com/jbenet/go-ipfs/exchange"
blockstore
"github.com/jbenet/go-ipfs/blocks/blockstore"
exchange
"github.com/jbenet/go-ipfs/exchange"
tn
"github.com/jbenet/go-ipfs/exchange/bitswap/testnet"
"github.com/jbenet/go-ipfs/peer"
"github.com/jbenet/go-ipfs/routing/mock"
peer
"github.com/jbenet/go-ipfs/peer"
mock
"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
(
...
...
@@ -45,7 +49,17 @@ func (g *SessionGenerator) Instances(n int) []Instance {
type
Instance
struct
{
Peer
peer
.
Peer
Exchange
exchange
.
Interface
Blockstore
blockstore
.
Blockstore
blockstore
blockstore
.
Blockstore
blockstoreDelay
delay
.
D
}
func
(
i
*
Instance
)
Blockstore
()
blockstore
.
Blockstore
{
return
i
.
blockstore
}
func
(
i
*
Instance
)
SetBlockstoreLatency
(
t
time
.
Duration
)
time
.
Duration
{
return
i
.
blockstoreDelay
.
Set
(
t
)
}
// session creates a test bitswap session.
...
...
@@ -58,7 +72,9 @@ func session(net tn.Network, rs mock.RoutingServer, ps peer.Peerstore, id peer.I
adapter
:=
net
.
Adapter
(
p
)
htc
:=
rs
.
Client
(
p
)
bstore
:=
blockstore
.
NewBlockstore
(
ds_sync
.
MutexWrap
(
ds
.
NewMapDatastore
()))
bsdelay
:=
delay
.
Fixed
(
0
)
bstore
:=
blockstore
.
NewBlockstore
(
ds_sync
.
MutexWrap
(
datastore2
.
WithDelay
(
ds
.
NewMapDatastore
(),
bsdelay
)))
const
alwaysSendToPeer
=
true
ctx
:=
context
.
TODO
()
...
...
@@ -66,8 +82,9 @@ func session(net tn.Network, rs mock.RoutingServer, ps peer.Peerstore, id peer.I
bs
:=
New
(
ctx
,
p
,
adapter
,
htc
,
bstore
,
alwaysSendToPeer
)
return
Instance
{
Peer
:
p
,
Exchange
:
bs
,
Blockstore
:
bstore
,
Peer
:
p
,
Exchange
:
bs
,
blockstore
:
bstore
,
blockstoreDelay
:
bsdelay
,
}
}
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