Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
plugin
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
link33
plugin
Commits
0e0bc545
Commit
0e0bc545
authored
Aug 03, 2019
by
yukang
Committed by
vipwzw
Aug 17, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Tiny adjustment for comment
parent
607dab97
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
24 deletions
+25
-24
parasync_test.go
plugin/consensus/para/parasync_test.go
+25
-24
No files found.
plugin/consensus/para/parasync_test.go
View file @
0e0bc545
...
@@ -32,10 +32,10 @@ const (
...
@@ -32,10 +32,10 @@ const (
)
)
var
(
var
(
//
positiveMsgReply
设置queue返回的Message是正例还是反例
//
testLoopCountAtom
设置queue返回的Message是正例还是反例
testLoopCountAtom
int32
testLoopCountAtom
int32
//actionReturnIndex 对应getNextAction的每一步返回顺序
//actionReturnIndex
Atom
对应getNextAction的每一步返回顺序
actionReturnIndex
int32
actionReturnIndex
Atom
int32
)
)
//测试初始化
//测试初始化
...
@@ -99,9 +99,9 @@ func makeGenesisBlockReplyTestData(testLoopCount int32) interface{} {
...
@@ -99,9 +99,9 @@ func makeGenesisBlockReplyTestData(testLoopCount int32) interface{} {
}
}
}
}
//生成
不同action
情况下的同步测试数据
//生成
getNextAction不同返回
情况下的同步测试数据
//index 对应getNextAction的每一步返回顺序,按return的先后顺序索引
//index 对应getNextAction的每一步返回顺序,按return的先后顺序索引
//
isPositive 生成正常数据还是异常数据
//
testLoopCount 测试轮数
func
makeSyncReplyTestData
(
index
int32
,
testLoopCount
int32
)
(
func
makeSyncReplyTestData
(
index
int32
,
testLoopCount
int32
)
(
interface
{},
//*types.Block, //GetLastBlock reply
interface
{},
//*types.Block, //GetLastBlock reply
interface
{},
//*types.LocalReplyValue, //GetLastLocalHeight reply
interface
{},
//*types.LocalReplyValue, //GetLastLocalHeight reply
...
@@ -175,7 +175,7 @@ func makeSyncReplyTestData(index int32, testLoopCount int32) (
...
@@ -175,7 +175,7 @@ func makeSyncReplyTestData(index int32, testLoopCount int32) (
}
}
}
}
//生成清理功能GetReply测试数据
//生成清理功能Get
Reply测试数据
func
makeCleanDataGetReplyTestData
(
clearLocalDBCallCount
int32
,
testLoopCount
int32
)
interface
{}
{
func
makeCleanDataGetReplyTestData
(
clearLocalDBCallCount
int32
,
testLoopCount
int32
)
interface
{}
{
switch
clearLocalDBCallCount
{
switch
clearLocalDBCallCount
{
case
1
:
//testinitFirstLocalHeightIfNeed会调用到
case
1
:
//testinitFirstLocalHeightIfNeed会调用到
...
@@ -222,8 +222,8 @@ func mockMessageReply(q queue.Queue) {
...
@@ -222,8 +222,8 @@ func mockMessageReply(q queue.Queue) {
cli
:=
q
.
Client
()
cli
:=
q
.
Client
()
cli
.
Sub
(
blockChainKey
)
cli
.
Sub
(
blockChainKey
)
//记录消息Call次数,用于loop退出;quitEndCount通过事先统计得出
//记录消息Call次数,用于loop退出;quitEndCount通过事先统计得出
quitCount
:=
int32
(
0
)
//
quitCount := int32(0)
quitEndCount
:=
int32
(
111
)
//TODO: Need a nice loop quit way
//
quitEndCount := int32(111) //TODO: Need a nice loop quit way
//用于处理数据同步情况下EventGetValueByKey消息的多重返回
//用于处理数据同步情况下EventGetValueByKey消息的多重返回
useLocalReply
:=
false
useLocalReply
:=
false
usrLocalReplyStart
:=
true
usrLocalReplyStart
:=
true
...
@@ -233,7 +233,7 @@ func mockMessageReply(q queue.Queue) {
...
@@ -233,7 +233,7 @@ func mockMessageReply(q queue.Queue) {
for
msg
:=
range
cli
.
Recv
()
{
for
msg
:=
range
cli
.
Recv
()
{
testLoopCount
:=
atomic
.
LoadInt32
(
&
testLoopCountAtom
)
testLoopCount
:=
atomic
.
LoadInt32
(
&
testLoopCountAtom
)
getActionReturnIndex
:=
atomic
.
LoadInt32
(
&
actionReturnIndex
)
getActionReturnIndex
:=
atomic
.
LoadInt32
(
&
actionReturnIndex
Atom
)
switch
{
switch
{
case
getActionReturnIndex
>
0
:
case
getActionReturnIndex
>
0
:
...
@@ -247,22 +247,22 @@ func mockMessageReply(q queue.Queue) {
...
@@ -247,22 +247,22 @@ func mockMessageReply(q queue.Queue) {
switch
msg
.
Ty
{
switch
msg
.
Ty
{
case
types
.
EventGetLastBlock
:
case
types
.
EventGetLastBlock
:
quitCount
++
//
quitCount++
msg
.
Reply
(
cli
.
NewMessage
(
blockChainKey
,
types
.
EventBlock
,
lastBlockReply
))
msg
.
Reply
(
cli
.
NewMessage
(
blockChainKey
,
types
.
EventBlock
,
lastBlockReply
))
case
types
.
EventAddParaChainBlockDetail
:
case
types
.
EventAddParaChainBlockDetail
:
quitCount
++
//
quitCount++
msg
.
Reply
(
cli
.
NewMessage
(
blockChainKey
,
types
.
EventReply
,
writeBlockReply
))
msg
.
Reply
(
cli
.
NewMessage
(
blockChainKey
,
types
.
EventReply
,
writeBlockReply
))
case
types
.
EventDelParaChainBlockDetail
:
case
types
.
EventDelParaChainBlockDetail
:
quitCount
++
//
quitCount++
msg
.
Reply
(
cli
.
NewMessage
(
blockChainKey
,
types
.
EventReply
,
rollBlockReply
))
msg
.
Reply
(
cli
.
NewMessage
(
blockChainKey
,
types
.
EventReply
,
rollBlockReply
))
case
types
.
EventGetValueByKey
:
case
types
.
EventGetValueByKey
:
quitCount
++
//
quitCount++
switch
{
switch
{
case
getActionReturnIndex
>
4
:
case
getActionReturnIndex
>
4
:
...
@@ -285,7 +285,7 @@ func mockMessageReply(q queue.Queue) {
...
@@ -285,7 +285,7 @@ func mockMessageReply(q queue.Queue) {
}
}
case
types
.
EventGetBlocks
:
case
types
.
EventGetBlocks
:
quitCount
++
//
quitCount++
msg
.
Reply
(
cli
.
NewMessage
(
blockChainKey
,
types
.
EventBlocks
,
getBlocksReply
))
msg
.
Reply
(
cli
.
NewMessage
(
blockChainKey
,
types
.
EventBlocks
,
getBlocksReply
))
default
:
default
:
...
@@ -294,13 +294,13 @@ func mockMessageReply(q queue.Queue) {
...
@@ -294,13 +294,13 @@ func mockMessageReply(q queue.Queue) {
default
:
default
:
switch
msg
.
Ty
{
switch
msg
.
Ty
{
case
types
.
EventAddParaChainBlockDetail
:
//mock创世区块创建消息返回,testCreateGenesisBlock
case
types
.
EventAddParaChainBlockDetail
:
//mock创世区块创建消息返回,testCreateGenesisBlock
quitCount
++
//
quitCount++
reply
:=
makeGenesisBlockReplyTestData
(
testLoopCount
)
reply
:=
makeGenesisBlockReplyTestData
(
testLoopCount
)
msg
.
Reply
(
cli
.
NewMessage
(
blockChainKey
,
types
.
EventReply
,
reply
))
msg
.
Reply
(
cli
.
NewMessage
(
blockChainKey
,
types
.
EventReply
,
reply
))
case
types
.
EventGetValueByKey
:
//mock数据清理消息返回
case
types
.
EventGetValueByKey
:
//mock数据清理消息返回
quitCount
++
//
quitCount++
clearLocalDBCallCount
++
clearLocalDBCallCount
++
reply
:=
makeCleanDataGetReplyTestData
(
clearLocalDBCallCount
,
testLoopCount
)
reply
:=
makeCleanDataGetReplyTestData
(
clearLocalDBCallCount
,
testLoopCount
)
...
@@ -311,7 +311,7 @@ func mockMessageReply(q queue.Queue) {
...
@@ -311,7 +311,7 @@ func mockMessageReply(q queue.Queue) {
}
}
case
types
.
EventSetValueByKey
:
//mock数据清理消息返回,testclearLocalOldBlocks会调用到
case
types
.
EventSetValueByKey
:
//mock数据清理消息返回,testclearLocalOldBlocks会调用到
quitCount
++
//
quitCount++
reply
:=
makeCleanDataSetReplyTestData
(
testLoopCount
)
reply
:=
makeCleanDataSetReplyTestData
(
testLoopCount
)
...
@@ -321,10 +321,10 @@ func mockMessageReply(q queue.Queue) {
...
@@ -321,10 +321,10 @@ func mockMessageReply(q queue.Queue) {
}
}
}
}
println
(
quitCount
)
//
println(quitCount)
if
quitCount
==
quitEndCount
{
//
if quitCount == quitEndCount {
//
break
//
break
}
//
}
}
}
}
}
...
@@ -372,7 +372,7 @@ func testInitFirstLocalHeightIfNeed(t *testing.T, para *client, testLoopCount in
...
@@ -372,7 +372,7 @@ func testInitFirstLocalHeightIfNeed(t *testing.T, para *client, testLoopCount in
func
testSyncBlocksIfNeed
(
t
*
testing
.
T
,
para
*
client
,
testLoopCount
int32
)
{
func
testSyncBlocksIfNeed
(
t
*
testing
.
T
,
para
*
client
,
testLoopCount
int32
)
{
errorCount
:=
int32
(
0
)
errorCount
:=
int32
(
0
)
for
i
:=
int32
(
1
);
i
<=
10
;
i
++
{
for
i
:=
int32
(
1
);
i
<=
10
;
i
++
{
atomic
.
StoreInt32
(
&
actionReturnIndex
,
i
)
atomic
.
StoreInt32
(
&
actionReturnIndex
Atom
,
i
)
isSynced
,
err
:=
para
.
blockSyncClient
.
syncBlocksIfNeed
()
isSynced
,
err
:=
para
.
blockSyncClient
.
syncBlocksIfNeed
()
if
err
!=
nil
{
if
err
!=
nil
{
errorCount
++
errorCount
++
...
@@ -387,7 +387,7 @@ func testSyncBlocksIfNeed(t *testing.T, para *client, testLoopCount int32) {
...
@@ -387,7 +387,7 @@ func testSyncBlocksIfNeed(t *testing.T, para *client, testLoopCount int32) {
assert
.
Equal
(
t
,
true
,
errorCount
==
7
)
assert
.
Equal
(
t
,
true
,
errorCount
==
7
)
}
}
atomic
.
StoreInt32
(
&
actionReturnIndex
,
0
)
atomic
.
StoreInt32
(
&
actionReturnIndex
Atom
,
0
)
}
}
//测试SyncHasCaughtUp
//测试SyncHasCaughtUp
...
@@ -400,6 +400,7 @@ func testSyncHasCaughtUp(t *testing.T, para *client, testLoopCount int32) {
...
@@ -400,6 +400,7 @@ func testSyncHasCaughtUp(t *testing.T, para *client, testLoopCount int32) {
assert
.
Equal
(
t
,
true
,
isSyncHasCaughtUp
)
assert
.
Equal
(
t
,
true
,
isSyncHasCaughtUp
)
}
}
//测试getBlockSyncState
func
testGetBlockSyncState
(
t
*
testing
.
T
,
para
*
client
,
testLoopCount
int32
)
{
func
testGetBlockSyncState
(
t
*
testing
.
T
,
para
*
client
,
testLoopCount
int32
)
{
oldValue
:=
para
.
blockSyncClient
.
getBlockSyncState
()
oldValue
:=
para
.
blockSyncClient
.
getBlockSyncState
()
para
.
blockSyncClient
.
setBlockSyncState
(
BlockSyncStateFinished
)
para
.
blockSyncClient
.
setBlockSyncState
(
BlockSyncStateFinished
)
...
@@ -411,7 +412,7 @@ func testGetBlockSyncState(t *testing.T, para *client, testLoopCount int32) {
...
@@ -411,7 +412,7 @@ func testGetBlockSyncState(t *testing.T, para *client, testLoopCount int32) {
//执行所有函数测试
//执行所有函数测试
func
execTest
(
t
*
testing
.
T
,
para
*
client
,
testLoopCount
int32
)
{
func
execTest
(
t
*
testing
.
T
,
para
*
client
,
testLoopCount
int32
)
{
atomic
.
StoreInt32
(
&
actionReturnIndex
,
0
)
atomic
.
StoreInt32
(
&
actionReturnIndex
Atom
,
0
)
atomic
.
StoreInt32
(
&
testLoopCountAtom
,
testLoopCount
)
atomic
.
StoreInt32
(
&
testLoopCountAtom
,
testLoopCount
)
testCreateGenesisBlock
(
t
,
para
,
testLoopCount
)
testCreateGenesisBlock
(
t
,
para
,
testLoopCount
)
...
...
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