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-dms3
Commits
2ea8d171
Unverified
Commit
2ea8d171
authored
Dec 16, 2017
by
Whyrusleeping
Committed by
GitHub
Dec 16, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #4499 from ipfs/fix/better-bitswap-test
improve bitswap tests
parents
34ade520
a5e9d0a2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
12 deletions
+38
-12
exchange/bitswap/bitswap_test.go
exchange/bitswap/bitswap_test.go
+17
-10
exchange/bitswap/testnet/virtual.go
exchange/bitswap/testnet/virtual.go
+21
-2
No files found.
exchange/bitswap/bitswap_test.go
View file @
2ea8d171
...
...
@@ -108,7 +108,7 @@ func TestLargeSwarm(t *testing.T) {
if
detectrace
.
WithRace
()
{
// when running with the race detector, 500 instances launches
// well over 8k goroutines. This hits a race detector limit.
numInstances
=
100
numInstances
=
75
}
else
if
travis
.
IsRunning
()
{
numInstances
=
200
}
else
{
...
...
@@ -292,23 +292,22 @@ func TestEmptyKey(t *testing.T) {
}
}
func
assertStat
(
st
*
Stat
,
sblks
,
rblks
,
sdata
,
rdata
uint64
)
error
{
func
assertStat
(
t
*
testing
.
T
,
st
*
Stat
,
sblks
,
rblks
,
sdata
,
rdata
uint64
)
{
if
sblks
!=
st
.
BlocksSent
{
return
fm
t
.
Errorf
(
"mismatch in blocks sent: %d vs %d"
,
sblks
,
st
.
BlocksSent
)
t
.
Errorf
(
"mismatch in blocks sent: %d vs %d"
,
sblks
,
st
.
BlocksSent
)
}
if
rblks
!=
st
.
BlocksReceived
{
return
fm
t
.
Errorf
(
"mismatch in blocks recvd: %d vs %d"
,
rblks
,
st
.
BlocksReceived
)
t
.
Errorf
(
"mismatch in blocks recvd: %d vs %d"
,
rblks
,
st
.
BlocksReceived
)
}
if
sdata
!=
st
.
DataSent
{
return
fm
t
.
Errorf
(
"mismatch in data sent: %d vs %d"
,
sdata
,
st
.
DataSent
)
t
.
Errorf
(
"mismatch in data sent: %d vs %d"
,
sdata
,
st
.
DataSent
)
}
if
rdata
!=
st
.
DataReceived
{
return
fm
t
.
Errorf
(
"mismatch in data recvd: %d vs %d"
,
rdata
,
st
.
DataReceived
)
t
.
Errorf
(
"mismatch in data recvd: %d vs %d"
,
rdata
,
st
.
DataReceived
)
}
return
nil
}
func
TestBasicBitswap
(
t
*
testing
.
T
)
{
...
...
@@ -355,12 +354,20 @@ func TestBasicBitswap(t *testing.T) {
t
.
Fatal
(
err
)
}
if
err
:=
assertStat
(
st0
,
1
,
0
,
1
,
0
);
err
!=
nil
{
st2
,
err
:=
instances
[
2
]
.
Exchange
.
Stat
()
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
err
:=
assertStat
(
st1
,
0
,
1
,
0
,
1
);
err
!=
nil
{
t
.
Fatal
(
err
)
t
.
Log
(
"stat node 0"
)
assertStat
(
t
,
st0
,
1
,
0
,
uint64
(
len
(
blk
.
RawData
())),
0
)
t
.
Log
(
"stat node 1"
)
assertStat
(
t
,
st1
,
0
,
1
,
0
,
uint64
(
len
(
blk
.
RawData
())))
t
.
Log
(
"stat node 2"
)
assertStat
(
t
,
st2
,
0
,
0
,
0
,
0
)
if
!
bytes
.
Equal
(
blk
.
RawData
(),
blocks
[
0
]
.
RawData
())
{
t
.
Errorf
(
"blocks aren't equal: expected %v, actual %v"
,
blocks
[
0
]
.
RawData
(),
blk
.
RawData
())
}
t
.
Log
(
blk
)
...
...
exchange/bitswap/testnet/virtual.go
View file @
2ea8d171
...
...
@@ -3,6 +3,7 @@ package bitswap
import
(
"context"
"errors"
"sync"
bsmsg
"github.com/ipfs/go-ipfs/exchange/bitswap/message"
bsnet
"github.com/ipfs/go-ipfs/exchange/bitswap/network"
...
...
@@ -29,6 +30,7 @@ func VirtualNetwork(rs mockrouting.Server, d delay.D) Network {
}
type
network
struct
{
mu
sync
.
Mutex
clients
map
[
peer
.
ID
]
bsnet
.
Receiver
routingserver
mockrouting
.
Server
delay
delay
.
D
...
...
@@ -36,6 +38,9 @@ type network struct {
}
func
(
n
*
network
)
Adapter
(
p
testutil
.
Identity
)
bsnet
.
BitSwapNetwork
{
n
.
mu
.
Lock
()
defer
n
.
mu
.
Unlock
()
client
:=
&
networkClient
{
local
:
p
.
ID
(),
network
:
n
,
...
...
@@ -46,6 +51,9 @@ func (n *network) Adapter(p testutil.Identity) bsnet.BitSwapNetwork {
}
func
(
n
*
network
)
HasPeer
(
p
peer
.
ID
)
bool
{
n
.
mu
.
Lock
()
defer
n
.
mu
.
Unlock
()
_
,
found
:=
n
.
clients
[
p
]
return
found
}
...
...
@@ -58,6 +66,9 @@ func (n *network) SendMessage(
to
peer
.
ID
,
message
bsmsg
.
BitSwapMessage
)
error
{
n
.
mu
.
Lock
()
defer
n
.
mu
.
Unlock
()
receiver
,
ok
:=
n
.
clients
[
to
]
if
!
ok
{
return
errors
.
New
(
"Cannot locate peer on network"
)
...
...
@@ -161,18 +172,26 @@ func (nc *networkClient) SetDelegate(r bsnet.Receiver) {
}
func
(
nc
*
networkClient
)
ConnectTo
(
_
context
.
Context
,
p
peer
.
ID
)
error
{
if
!
nc
.
network
.
HasPeer
(
p
)
{
nc
.
network
.
mu
.
Lock
()
otherClient
,
ok
:=
nc
.
network
.
clients
[
p
]
if
!
ok
{
nc
.
network
.
mu
.
Unlock
()
return
errors
.
New
(
"no such peer in network"
)
}
tag
:=
tagForPeers
(
nc
.
local
,
p
)
if
_
,
ok
:=
nc
.
network
.
conns
[
tag
];
ok
{
nc
.
network
.
mu
.
Unlock
()
log
.
Warning
(
"ALREADY CONNECTED TO PEER (is this a reconnect? test lib needs fixing)"
)
return
nil
}
nc
.
network
.
conns
[
tag
]
=
struct
{}{}
nc
.
network
.
mu
.
Unlock
()
// TODO: add handling for disconnects
nc
.
network
.
c
lient
s
[
p
]
.
PeerConnected
(
nc
.
local
)
otherC
lient
.
PeerConnected
(
nc
.
local
)
nc
.
Receiver
.
PeerConnected
(
p
)
return
nil
}
...
...
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