Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
3c44ad1f
提交
3c44ad1f
authored
12月 12, 2014
作者:
Brian Tiger Chow
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(bs/testnet) use delay in virtual network
License: MIT Signed-off-by:
Brian Tiger Chow
<
brian@perfmode.com
>
上级
8e0c8a7a
显示空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
20 行增加
和
12 行删除
+20
-12
mock.go
blockservice/mock.go
+3
-2
bitswap_test.go
exchange/bitswap/bitswap_test.go
+7
-6
network.go
exchange/bitswap/testnet/network.go
+7
-2
network_test.go
exchange/bitswap/testnet/network_test.go
+3
-2
没有找到文件。
blockservice/mock.go
浏览文件 @
3c44ad1f
...
...
@@ -5,12 +5,13 @@ import (
bitswap
"github.com/jbenet/go-ipfs/exchange/bitswap"
tn
"github.com/jbenet/go-ipfs/exchange/bitswap/testnet"
"github.com/jbenet/go-ipfs/routing/mock"
mock
"github.com/jbenet/go-ipfs/routing/mock"
delay
"github.com/jbenet/go-ipfs/util/delay"
)
// Mocks returns |n| connected mock Blockservices
func
Mocks
(
t
*
testing
.
T
,
n
int
)
[]
*
BlockService
{
net
:=
tn
.
VirtualNetwork
()
net
:=
tn
.
VirtualNetwork
(
delay
.
Fixed
(
0
)
)
rs
:=
mock
.
VirtualRoutingServer
()
sg
:=
bitswap
.
NewSessionGenerator
(
net
,
rs
)
...
...
exchange/bitswap/bitswap_test.go
浏览文件 @
3c44ad1f
...
...
@@ -11,13 +11,14 @@ import (
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"
delay
"github.com/jbenet/go-ipfs/util/delay"
testutil
"github.com/jbenet/go-ipfs/util/testutil"
)
func
TestClose
(
t
*
testing
.
T
)
{
// TODO
t
.
Skip
(
"TODO Bitswap's Close implementation is a WIP"
)
vnet
:=
tn
.
VirtualNetwork
()
vnet
:=
tn
.
VirtualNetwork
(
delay
.
Fixed
(
0
)
)
rout
:=
mock
.
VirtualRoutingServer
()
sesgen
:=
NewSessionGenerator
(
vnet
,
rout
)
bgen
:=
blocksutil
.
NewBlockGenerator
()
...
...
@@ -31,7 +32,7 @@ func TestClose(t *testing.T) {
func
TestGetBlockTimeout
(
t
*
testing
.
T
)
{
net
:=
tn
.
VirtualNetwork
()
net
:=
tn
.
VirtualNetwork
(
delay
.
Fixed
(
0
)
)
rs
:=
mock
.
VirtualRoutingServer
()
g
:=
NewSessionGenerator
(
net
,
rs
)
...
...
@@ -48,7 +49,7 @@ func TestGetBlockTimeout(t *testing.T) {
func
TestProviderForKeyButNetworkCannotFind
(
t
*
testing
.
T
)
{
net
:=
tn
.
VirtualNetwork
()
net
:=
tn
.
VirtualNetwork
(
delay
.
Fixed
(
0
)
)
rs
:=
mock
.
VirtualRoutingServer
()
g
:=
NewSessionGenerator
(
net
,
rs
)
...
...
@@ -69,7 +70,7 @@ func TestProviderForKeyButNetworkCannotFind(t *testing.T) {
func
TestGetBlockFromPeerAfterPeerAnnounces
(
t
*
testing
.
T
)
{
net
:=
tn
.
VirtualNetwork
()
net
:=
tn
.
VirtualNetwork
(
delay
.
Fixed
(
0
)
)
rs
:=
mock
.
VirtualRoutingServer
()
block
:=
blocks
.
NewBlock
([]
byte
(
"block"
))
g
:=
NewSessionGenerator
(
net
,
rs
)
...
...
@@ -121,7 +122,7 @@ func PerformDistributionTest(t *testing.T, numInstances, numBlocks int) {
if
testing
.
Short
()
{
t
.
SkipNow
()
}
net
:=
tn
.
VirtualNetwork
()
net
:=
tn
.
VirtualNetwork
(
delay
.
Fixed
(
0
)
)
rs
:=
mock
.
VirtualRoutingServer
()
sg
:=
NewSessionGenerator
(
net
,
rs
)
bg
:=
blocksutil
.
NewBlockGenerator
()
...
...
@@ -181,7 +182,7 @@ func TestSendToWantingPeer(t *testing.T) {
t
.
SkipNow
()
}
net
:=
tn
.
VirtualNetwork
()
net
:=
tn
.
VirtualNetwork
(
delay
.
Fixed
(
0
)
)
rs
:=
mock
.
VirtualRoutingServer
()
sg
:=
NewSessionGenerator
(
net
,
rs
)
bg
:=
blocksutil
.
NewBlockGenerator
()
...
...
exchange/bitswap/testnet/network.go
浏览文件 @
3c44ad1f
...
...
@@ -10,6 +10,7 @@ import (
bsnet
"github.com/jbenet/go-ipfs/exchange/bitswap/network"
peer
"github.com/jbenet/go-ipfs/peer"
"github.com/jbenet/go-ipfs/util"
delay
"github.com/jbenet/go-ipfs/util/delay"
)
type
Network
interface
{
...
...
@@ -33,14 +34,16 @@ type Network interface {
// network impl
func
VirtualNetwork
()
Network
{
func
VirtualNetwork
(
d
delay
.
D
)
Network
{
return
&
network
{
clients
:
make
(
map
[
util
.
Key
]
bsnet
.
Receiver
),
delay
:
d
,
}
}
type
network
struct
{
clients
map
[
util
.
Key
]
bsnet
.
Receiver
delay
delay
.
D
}
func
(
n
*
network
)
Adapter
(
p
peer
.
Peer
)
bsnet
.
BitSwapNetwork
{
...
...
@@ -84,13 +87,15 @@ func (n *network) deliver(
return
errors
.
New
(
"Invalid input"
)
}
n
.
delay
.
Wait
()
nextPeer
,
nextMsg
:=
r
.
ReceiveMessage
(
context
.
TODO
(),
from
,
message
)
if
(
nextPeer
==
nil
&&
nextMsg
!=
nil
)
||
(
nextMsg
==
nil
&&
nextPeer
!=
nil
)
{
return
errors
.
New
(
"Malformed client request"
)
}
if
nextPeer
==
nil
&&
nextMsg
==
nil
{
if
nextPeer
==
nil
&&
nextMsg
==
nil
{
// no response to send
return
nil
}
...
...
exchange/bitswap/testnet/network_test.go
浏览文件 @
3c44ad1f
...
...
@@ -9,11 +9,12 @@ import (
bsmsg
"github.com/jbenet/go-ipfs/exchange/bitswap/message"
bsnet
"github.com/jbenet/go-ipfs/exchange/bitswap/network"
peer
"github.com/jbenet/go-ipfs/peer"
delay
"github.com/jbenet/go-ipfs/util/delay"
testutil
"github.com/jbenet/go-ipfs/util/testutil"
)
func
TestSendRequestToCooperativePeer
(
t
*
testing
.
T
)
{
net
:=
VirtualNetwork
()
net
:=
VirtualNetwork
(
delay
.
Fixed
(
0
)
)
idOfRecipient
:=
[]
byte
(
"recipient"
)
...
...
@@ -60,7 +61,7 @@ func TestSendRequestToCooperativePeer(t *testing.T) {
}
func
TestSendMessageAsyncButWaitForResponse
(
t
*
testing
.
T
)
{
net
:=
VirtualNetwork
()
net
:=
VirtualNetwork
(
delay
.
Fixed
(
0
)
)
idOfResponder
:=
[]
byte
(
"responder"
)
waiter
:=
net
.
Adapter
(
testutil
.
NewPeerWithIDString
(
"waiter"
))
responder
:=
net
.
Adapter
(
testutil
.
NewPeerWithID
(
idOfResponder
))
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论