Commit 0e0bc545 authored by yukang's avatar yukang Committed by vipwzw

Tiny adjustment for comment

parent 607dab97
...@@ -32,10 +32,10 @@ const ( ...@@ -32,10 +32,10 @@ const (
) )
var ( var (
//positiveMsgReply 设置queue返回的Message是正例还是反例 //testLoopCountAtom 设置queue返回的Message是正例还是反例
testLoopCountAtom int32 testLoopCountAtom int32
//actionReturnIndex 对应getNextAction的每一步返回顺序 //actionReturnIndexAtom 对应getNextAction的每一步返回顺序
actionReturnIndex int32 actionReturnIndexAtom 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(&actionReturnIndexAtom)
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(&actionReturnIndexAtom, 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(&actionReturnIndexAtom, 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(&actionReturnIndexAtom, 0)
atomic.StoreInt32(&testLoopCountAtom, testLoopCount) atomic.StoreInt32(&testLoopCountAtom, testLoopCount)
testCreateGenesisBlock(t, para, testLoopCount) testCreateGenesisBlock(t, para, testLoopCount)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment