Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
whqwjb
go-ethereum
提交
a8e4cb6d
G
go-ethereum
项目概览
whqwjb
/
go-ethereum
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
go-ethereum
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
a8e4cb6d
编写于
6月 10, 2015
作者:
F
Felix Lange
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
p2p/discover: use separate rand.Source instances in tests
rand.Source isn't safe for concurrent use.
上级
261a8077
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
19 addition
and
15 deletion
+19
-15
p2p/discover/node_test.go
p2p/discover/node_test.go
+14
-11
p2p/discover/table_test.go
p2p/discover/table_test.go
+5
-4
未找到文件。
p2p/discover/node_test.go
浏览文件 @
a8e4cb6d
...
...
@@ -13,11 +13,6 @@ import (
"github.com/ethereum/go-ethereum/crypto"
)
var
(
quickrand
=
rand
.
New
(
rand
.
NewSource
(
time
.
Now
()
.
Unix
()))
quickcfg
=
&
quick
.
Config
{
MaxCount
:
5000
,
Rand
:
quickrand
}
)
var
parseNodeTests
=
[]
struct
{
rawurl
string
wantError
string
...
...
@@ -176,7 +171,7 @@ func TestNodeID_distcmp(t *testing.T) {
bbig
:=
new
(
big
.
Int
)
.
SetBytes
(
b
[
:
])
return
new
(
big
.
Int
)
.
Xor
(
tbig
,
abig
)
.
Cmp
(
new
(
big
.
Int
)
.
Xor
(
tbig
,
bbig
))
}
if
err
:=
quick
.
CheckEqual
(
distcmp
,
distcmpBig
,
quickcfg
);
err
!=
nil
{
if
err
:=
quick
.
CheckEqual
(
distcmp
,
distcmpBig
,
quickcfg
()
);
err
!=
nil
{
t
.
Error
(
err
)
}
}
...
...
@@ -195,7 +190,7 @@ func TestNodeID_logdist(t *testing.T) {
abig
,
bbig
:=
new
(
big
.
Int
)
.
SetBytes
(
a
[
:
]),
new
(
big
.
Int
)
.
SetBytes
(
b
[
:
])
return
new
(
big
.
Int
)
.
Xor
(
abig
,
bbig
)
.
BitLen
()
}
if
err
:=
quick
.
CheckEqual
(
logdist
,
logdistBig
,
quickcfg
);
err
!=
nil
{
if
err
:=
quick
.
CheckEqual
(
logdist
,
logdistBig
,
quickcfg
()
);
err
!=
nil
{
t
.
Error
(
err
)
}
}
...
...
@@ -211,9 +206,10 @@ func TestNodeID_logdistEqual(t *testing.T) {
func
TestNodeID_hashAtDistance
(
t
*
testing
.
T
)
{
// we don't use quick.Check here because its output isn't
// very helpful when the test fails.
for
i
:=
0
;
i
<
quickcfg
.
MaxCount
;
i
++
{
a
:=
gen
(
common
.
Hash
{},
quickrand
)
.
(
common
.
Hash
)
dist
:=
quickrand
.
Intn
(
len
(
common
.
Hash
{})
*
8
)
cfg
:=
quickcfg
()
for
i
:=
0
;
i
<
cfg
.
MaxCount
;
i
++
{
a
:=
gen
(
common
.
Hash
{},
cfg
.
Rand
)
.
(
common
.
Hash
)
dist
:=
cfg
.
Rand
.
Intn
(
len
(
common
.
Hash
{})
*
8
)
result
:=
hashAtDistance
(
a
,
dist
)
actualdist
:=
logdist
(
result
,
a
)
...
...
@@ -225,7 +221,14 @@ func TestNodeID_hashAtDistance(t *testing.T) {
}
}
// TODO: this can be dropped when we require Go >= 1.5
func
quickcfg
()
*
quick
.
Config
{
return
&
quick
.
Config
{
MaxCount
:
5000
,
Rand
:
rand
.
New
(
rand
.
NewSource
(
time
.
Now
()
.
Unix
())),
}
}
// TODO: The Generate method can be dropped when we require Go >= 1.5
// because testing/quick learned to generate arrays in 1.5.
func
(
NodeID
)
Generate
(
rand
*
rand
.
Rand
,
size
int
)
reflect
.
Value
{
...
...
p2p/discover/table_test.go
浏览文件 @
a8e4cb6d
...
...
@@ -9,6 +9,7 @@ import (
"reflect"
"testing"
"testing/quick"
"time"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
...
...
@@ -74,7 +75,7 @@ func TestBucket_bumpNoDuplicates(t *testing.T) {
t
.
Parallel
()
cfg
:=
&
quick
.
Config
{
MaxCount
:
1000
,
Rand
:
quickrand
,
Rand
:
rand
.
New
(
rand
.
NewSource
(
time
.
Now
()
.
Unix
()))
,
Values
:
func
(
args
[]
reflect
.
Value
,
rand
*
rand
.
Rand
)
{
// generate a random list of nodes. this will be the content of the bucket.
n
:=
rand
.
Intn
(
bucketSize
-
1
)
+
1
...
...
@@ -205,7 +206,7 @@ func TestTable_closest(t *testing.T) {
}
return
true
}
if
err
:=
quick
.
Check
(
test
,
quickcfg
);
err
!=
nil
{
if
err
:=
quick
.
Check
(
test
,
quickcfg
()
);
err
!=
nil
{
t
.
Error
(
err
)
}
}
...
...
@@ -213,7 +214,7 @@ func TestTable_closest(t *testing.T) {
func
TestTable_ReadRandomNodesGetAll
(
t
*
testing
.
T
)
{
cfg
:=
&
quick
.
Config
{
MaxCount
:
200
,
Rand
:
quickrand
,
Rand
:
rand
.
New
(
rand
.
NewSource
(
time
.
Now
()
.
Unix
()))
,
Values
:
func
(
args
[]
reflect
.
Value
,
rand
*
rand
.
Rand
)
{
args
[
0
]
=
reflect
.
ValueOf
(
make
([]
*
Node
,
rand
.
Intn
(
1000
)))
},
...
...
@@ -221,7 +222,7 @@ func TestTable_ReadRandomNodesGetAll(t *testing.T) {
test
:=
func
(
buf
[]
*
Node
)
bool
{
tab
:=
newTable
(
nil
,
NodeID
{},
&
net
.
UDPAddr
{},
""
)
for
i
:=
0
;
i
<
len
(
buf
);
i
++
{
ld
:=
quickr
and
.
Intn
(
len
(
tab
.
buckets
))
ld
:=
cfg
.
R
and
.
Intn
(
len
(
tab
.
buckets
))
tab
.
add
([]
*
Node
{
nodeAtDistance
(
tab
.
self
.
sha
,
ld
)})
}
gotN
:=
tab
.
ReadRandomNodes
(
buf
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录