Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
48bf4461
提交
48bf4461
authored
12月 16, 2014
作者:
Juan Batiz-Benet
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #455 from jbenet/test/improve-accuracy-of-mock
fix: routing mock accuracy
上级
5b56a67d
19e8eb51
隐藏空白字符变更
内嵌
并排
正在显示
7 个修改的文件
包含
106 行增加
和
23 行删除
+106
-23
addcat_test.go
epictest/addcat_test.go
+4
-1
bench_test.go
epictest/bench_test.go
+22
-6
client.go
routing/mock/client.go
+2
-0
interface.go
routing/mock/interface.go
+16
-4
mockrouting_test.go
routing/mock/mockrouting_test.go
+36
-1
server.go
routing/mock/server.go
+19
-11
delay.go
util/delay/delay.go
+7
-0
没有找到文件。
epictest/addcat_test.go
浏览文件 @
48bf4461
...
...
@@ -104,7 +104,10 @@ func AddCatBytes(data []byte, conf Config) error {
sessionGenerator
:=
bitswap
.
NewSessionGenerator
(
tn
.
VirtualNetwork
(
delay
.
Fixed
(
conf
.
NetworkLatency
)),
// TODO rename VirtualNetwork
mockrouting
.
NewServerWithDelay
(
delay
.
Fixed
(
conf
.
RoutingLatency
)),
mockrouting
.
NewServerWithDelay
(
mockrouting
.
DelayConfig
{
Query
:
delay
.
Fixed
(
conf
.
RoutingLatency
),
ValueVisibility
:
delay
.
Fixed
(
conf
.
RoutingLatency
),
}),
)
defer
sessionGenerator
.
Close
()
...
...
epictest/bench_test.go
浏览文件 @
48bf4461
...
...
@@ -30,12 +30,16 @@ func BenchmarkInstantaneousAddCat256MB(b *testing.B) { benchmarkAddCat(256*MB, i
var
routing
=
Config
{}
.
Routing_Slow
()
func
BenchmarkRoutingSlowAddCat1MB
(
b
*
testing
.
B
)
{
benchmarkAddCat
(
1
*
MB
,
routing
,
b
)
}
func
BenchmarkRoutingSlowAddCat2MB
(
b
*
testing
.
B
)
{
benchmarkAddCat
(
2
*
MB
,
routing
,
b
)
}
func
BenchmarkRoutingSlowAddCat4MB
(
b
*
testing
.
B
)
{
benchmarkAddCat
(
4
*
MB
,
routing
,
b
)
}
func
BenchmarkRoutingSlowAddCat8MB
(
b
*
testing
.
B
)
{
benchmarkAddCat
(
8
*
MB
,
routing
,
b
)
}
func
BenchmarkRoutingSlowAddCat16MB
(
b
*
testing
.
B
)
{
benchmarkAddCat
(
16
*
MB
,
routing
,
b
)
}
func
BenchmarkRoutingSlowAddCat32MB
(
b
*
testing
.
B
)
{
benchmarkAddCat
(
32
*
MB
,
routing
,
b
)
}
func
BenchmarkRoutingSlowAddCat1MB
(
b
*
testing
.
B
)
{
benchmarkAddCat
(
1
*
MB
,
routing
,
b
)
}
func
BenchmarkRoutingSlowAddCat2MB
(
b
*
testing
.
B
)
{
benchmarkAddCat
(
2
*
MB
,
routing
,
b
)
}
func
BenchmarkRoutingSlowAddCat4MB
(
b
*
testing
.
B
)
{
benchmarkAddCat
(
4
*
MB
,
routing
,
b
)
}
func
BenchmarkRoutingSlowAddCat8MB
(
b
*
testing
.
B
)
{
benchmarkAddCat
(
8
*
MB
,
routing
,
b
)
}
func
BenchmarkRoutingSlowAddCat16MB
(
b
*
testing
.
B
)
{
benchmarkAddCat
(
16
*
MB
,
routing
,
b
)
}
func
BenchmarkRoutingSlowAddCat32MB
(
b
*
testing
.
B
)
{
benchmarkAddCat
(
32
*
MB
,
routing
,
b
)
}
func
BenchmarkRoutingSlowAddCat64MB
(
b
*
testing
.
B
)
{
benchmarkAddCat
(
64
*
MB
,
routing
,
b
)
}
func
BenchmarkRoutingSlowAddCat128MB
(
b
*
testing
.
B
)
{
benchmarkAddCat
(
128
*
MB
,
routing
,
b
)
}
func
BenchmarkRoutingSlowAddCat256MB
(
b
*
testing
.
B
)
{
benchmarkAddCat
(
256
*
MB
,
routing
,
b
)
}
func
BenchmarkRoutingSlowAddCat512MB
(
b
*
testing
.
B
)
{
benchmarkAddCat
(
512
*
MB
,
routing
,
b
)
}
var
network
=
Config
{}
.
Network_NYtoSF
()
...
...
@@ -60,3 +64,15 @@ func BenchmarkBlockstoreSlowAddCat32MB(b *testing.B) { benchmarkAddCat(32*MB, b
func
BenchmarkBlockstoreSlowAddCat64MB
(
b
*
testing
.
B
)
{
benchmarkAddCat
(
64
*
MB
,
blockstore
,
b
)
}
func
BenchmarkBlockstoreSlowAddCat128MB
(
b
*
testing
.
B
)
{
benchmarkAddCat
(
128
*
MB
,
blockstore
,
b
)
}
func
BenchmarkBlockstoreSlowAddCat256MB
(
b
*
testing
.
B
)
{
benchmarkAddCat
(
256
*
MB
,
blockstore
,
b
)
}
var
mixed
=
Config
{}
.
Network_NYtoSF
()
.
Blockstore_SlowSSD2014
()
.
Routing_Slow
()
func
BenchmarkMixedAddCat1MBXX
(
b
*
testing
.
B
)
{
benchmarkAddCat
(
1
*
MB
,
mixed
,
b
)
}
func
BenchmarkMixedAddCat2MBXX
(
b
*
testing
.
B
)
{
benchmarkAddCat
(
2
*
MB
,
mixed
,
b
)
}
func
BenchmarkMixedAddCat4MBXX
(
b
*
testing
.
B
)
{
benchmarkAddCat
(
4
*
MB
,
mixed
,
b
)
}
func
BenchmarkMixedAddCat8MBXX
(
b
*
testing
.
B
)
{
benchmarkAddCat
(
8
*
MB
,
mixed
,
b
)
}
func
BenchmarkMixedAddCat16MBX
(
b
*
testing
.
B
)
{
benchmarkAddCat
(
16
*
MB
,
mixed
,
b
)
}
func
BenchmarkMixedAddCat32MBX
(
b
*
testing
.
B
)
{
benchmarkAddCat
(
32
*
MB
,
mixed
,
b
)
}
func
BenchmarkMixedAddCat64MBX
(
b
*
testing
.
B
)
{
benchmarkAddCat
(
64
*
MB
,
mixed
,
b
)
}
func
BenchmarkMixedAddCat128MB
(
b
*
testing
.
B
)
{
benchmarkAddCat
(
128
*
MB
,
mixed
,
b
)
}
func
BenchmarkMixedAddCat256MB
(
b
*
testing
.
B
)
{
benchmarkAddCat
(
256
*
MB
,
mixed
,
b
)
}
routing/mock/client.go
浏览文件 @
48bf4461
...
...
@@ -67,6 +67,8 @@ func (c *client) FindProvidersAsync(ctx context.Context, k u.Key, max int) <-cha
return
out
}
// Provide returns once the message is on the network. Value is not necessarily
// visible yet.
func
(
c
*
client
)
Provide
(
_
context
.
Context
,
key
u
.
Key
)
error
{
return
c
.
server
.
Announce
(
c
.
peer
,
key
)
}
...
...
routing/mock/interface.go
浏览文件 @
48bf4461
...
...
@@ -28,13 +28,25 @@ type Client interface {
// NewServer returns a mockrouting Server
func
NewServer
()
Server
{
return
NewServerWithDelay
(
delay
.
Fixed
(
0
))
return
NewServerWithDelay
(
DelayConfig
{
ValueVisibility
:
delay
.
Fixed
(
0
),
Query
:
delay
.
Fixed
(
0
),
})
}
// NewServerWithDelay returns a mockrouting Server with a delay!
func
NewServerWithDelay
(
d
delay
.
D
)
Server
{
func
NewServerWithDelay
(
conf
DelayConfig
)
Server
{
return
&
s
{
providers
:
make
(
map
[
u
.
Key
]
peer
.
Map
),
delay
:
d
,
providers
:
make
(
map
[
u
.
Key
]
map
[
u
.
Key
]
providerRecord
),
delay
Conf
:
conf
,
}
}
type
DelayConfig
struct
{
// ValueVisibility is the time it takes for a value to be visible in the network
// FIXME there _must_ be a better term for this
ValueVisibility
delay
.
D
// Query is the time it takes to receive a response from a routing query
Query
delay
.
D
}
routing/mock/mockrouting_test.go
浏览文件 @
48bf4461
...
...
@@ -3,10 +3,12 @@ package mockrouting
import
(
"bytes"
"testing"
"time"
context
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
"github.com/jbenet/go-ipfs/peer"
peer
"github.com/jbenet/go-ipfs/peer"
u
"github.com/jbenet/go-ipfs/util"
delay
"github.com/jbenet/go-ipfs/util/delay"
testutil
"github.com/jbenet/go-ipfs/util/testutil"
)
...
...
@@ -129,3 +131,36 @@ func TestCanceledContext(t *testing.T) {
t
.
Fatal
(
"Context cancel had no effect"
)
}
}
func
TestValidAfter
(
t
*
testing
.
T
)
{
var
p
=
testutil
.
NewPeerWithID
(
peer
.
ID
([]
byte
(
"the peer id"
)))
var
key
=
u
.
Key
(
"mock key"
)
var
ctx
=
context
.
Background
()
conf
:=
DelayConfig
{
ValueVisibility
:
delay
.
Fixed
(
1
*
time
.
Hour
),
Query
:
delay
.
Fixed
(
0
),
}
rs
:=
NewServerWithDelay
(
conf
)
rs
.
Client
(
p
)
.
Provide
(
ctx
,
key
)
var
providers
[]
peer
.
Peer
providers
,
err
:=
rs
.
Client
(
p
)
.
FindProviders
(
ctx
,
key
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
len
(
providers
)
>
0
{
t
.
Fail
()
}
conf
.
ValueVisibility
.
Set
(
0
)
providers
,
err
=
rs
.
Client
(
p
)
.
FindProviders
(
ctx
,
key
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
len
(
providers
)
!=
1
{
t
.
Fail
()
}
}
routing/mock/server.go
浏览文件 @
48bf4461
...
...
@@ -3,11 +3,11 @@ package mockrouting
import
(
"math/rand"
"sync"
"time"
ds
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore"
peer
"github.com/jbenet/go-ipfs/peer"
u
"github.com/jbenet/go-ipfs/util"
delay
"github.com/jbenet/go-ipfs/util/delay"
)
// server is the mockrouting.Client's private interface to the routing server
...
...
@@ -20,39 +20,47 @@ type server interface {
// s is an implementation of the private server interface
type
s
struct
{
delay
delay
.
D
delay
Conf
DelayConfig
lock
sync
.
RWMutex
providers
map
[
u
.
Key
]
peer
.
Map
providers
map
[
u
.
Key
]
map
[
u
.
Key
]
providerRecord
}
func
(
rs
*
s
)
Announce
(
p
peer
.
Peer
,
k
u
.
Key
)
error
{
rs
.
delay
.
Wait
()
// before locking
type
providerRecord
struct
{
Peer
peer
.
Peer
Created
time
.
Time
}
func
(
rs
*
s
)
Announce
(
p
peer
.
Peer
,
k
u
.
Key
)
error
{
rs
.
lock
.
Lock
()
defer
rs
.
lock
.
Unlock
()
_
,
ok
:=
rs
.
providers
[
k
]
if
!
ok
{
rs
.
providers
[
k
]
=
make
(
peer
.
Map
)
rs
.
providers
[
k
]
=
make
(
map
[
u
.
Key
]
providerRecord
)
}
rs
.
providers
[
k
][
p
.
Key
()]
=
providerRecord
{
Created
:
time
.
Now
(),
Peer
:
p
,
}
rs
.
providers
[
k
][
p
.
Key
()]
=
p
return
nil
}
func
(
rs
*
s
)
Providers
(
k
u
.
Key
)
[]
peer
.
Peer
{
rs
.
delay
.
Wait
()
// before locking
rs
.
delay
Conf
.
Query
.
Wait
()
// before locking
rs
.
lock
.
RLock
()
defer
rs
.
lock
.
RUnlock
()
var
ret
[]
peer
.
Peer
peerset
,
ok
:=
rs
.
providers
[
k
]
records
,
ok
:=
rs
.
providers
[
k
]
if
!
ok
{
return
ret
}
for
_
,
peer
:=
range
peerset
{
ret
=
append
(
ret
,
peer
)
for
_
,
r
:=
range
records
{
if
time
.
Now
()
.
Sub
(
r
.
Created
)
>
rs
.
delayConf
.
ValueVisibility
.
Get
()
{
ret
=
append
(
ret
,
r
.
Peer
)
}
}
for
i
:=
range
ret
{
...
...
util/delay/delay.go
浏览文件 @
48bf4461
...
...
@@ -10,6 +10,7 @@ import (
type
D
interface
{
Set
(
time
.
Duration
)
time
.
Duration
Wait
()
Get
()
time
.
Duration
}
// Fixed returns a delay with fixed latency
...
...
@@ -37,3 +38,9 @@ func (d *delay) Wait() {
defer
d
.
l
.
RUnlock
()
time
.
Sleep
(
d
.
t
)
}
func
(
d
*
delay
)
Get
()
time
.
Duration
{
d
.
l
.
Lock
()
defer
d
.
l
.
Unlock
()
return
d
.
t
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论