提交 07734944 编写于 作者: C Ciju John

Add test for hard replay.

上级 4938c6d0
...@@ -56,6 +56,7 @@ add_test(NAME distributed-transactions-test COMMAND tests/distributed-transactio ...@@ -56,6 +56,7 @@ add_test(NAME distributed-transactions-test COMMAND tests/distributed-transactio
add_test(NAME distributed-transactions-remote-test COMMAND tests/distributed-transactions-remote-test.py -v --dump-error-detail WORKING_DIRECTORY ${CMAKE_BINARY_DIR}) add_test(NAME distributed-transactions-remote-test COMMAND tests/distributed-transactions-remote-test.py -v --dump-error-detail WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
# TODO removed on slim: add_test(NAME restart-scenarios-test_resync COMMAND tests/restart-scenarios-test.py -c resync -p4 -v --dump-error-details WORKING_DIRECTORY ${CMAKE_BINARY_DIR}) # TODO removed on slim: add_test(NAME restart-scenarios-test_resync COMMAND tests/restart-scenarios-test.py -c resync -p4 -v --dump-error-details WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
# add_test(NAME restart-scenarios-test_replay COMMAND tests/restart-scenarios-test.py -c replay -p4 -v --dump-error-details WORKING_DIRECTORY ${CMAKE_BINARY_DIR}) # add_test(NAME restart-scenarios-test_replay COMMAND tests/restart-scenarios-test.py -c replay -p4 -v --dump-error-details WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
add_test(NAME restart-scenarios-test_hard_replay COMMAND tests/restart-scenarios-test.py -c hardReplay -p4 -v --dump-error-details WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
# TODO: add_test(NAME consensus-validation-malicious-producers COMMAND tests/consensus-validation-malicious-producers.py -w 80 --dump-error-details WORKING_DIRECTORY ${CMAKE_BINARY_DIR}) # TODO: add_test(NAME consensus-validation-malicious-producers COMMAND tests/consensus-validation-malicious-producers.py -w 80 --dump-error-details WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
if(ENABLE_COVERAGE_TESTING) if(ENABLE_COVERAGE_TESTING)
......
...@@ -65,8 +65,8 @@ testSuccessful=False ...@@ -65,8 +65,8 @@ testSuccessful=False
random.seed(seed) # Use a fixed seed for repeatability. random.seed(seed) # Use a fixed seed for repeatability.
cluster=testUtils.Cluster() cluster=testUtils.Cluster(walletd=True)
walletMgr=testUtils.WalletMgr(False) walletMgr=testUtils.WalletMgr(True)
try: try:
cluster.setChainStrategy(chainSyncStrategyStr) cluster.setChainStrategy(chainSyncStrategyStr)
...@@ -87,6 +87,12 @@ try: ...@@ -87,6 +87,12 @@ try:
if not cluster.waitOnClusterBlockNumSync(3): if not cluster.waitOnClusterBlockNumSync(3):
errorExit("Cluster never stabilized") errorExit("Cluster never stabilized")
Print("Stand up EOS wallet keosd")
walletMgr.killall()
walletMgr.cleanup()
if walletMgr.launch() is False:
errorExit("Failed to stand up keosd.")
accountsCount=total_nodes accountsCount=total_nodes
walletName="MyWallet" walletName="MyWallet"
Print("Creating wallet %s if one doesn't already exist." % walletName) Print("Creating wallet %s if one doesn't already exist." % walletName)
...@@ -115,9 +121,9 @@ try: ...@@ -115,9 +121,9 @@ try:
# TBD: Known issue (Issue 2043) that 'get currency0000 balance' doesn't return balance. # TBD: Known issue (Issue 2043) that 'get currency0000 balance' doesn't return balance.
# Uncomment when functional # Uncomment when functional
# Print("Spread funds and validate") Print("Spread funds and validate")
# if not cluster.spreadFundsAndValidate(10): if not cluster.spreadFundsAndValidate(10):
# errorExit("Failed to spread and validate funds.") errorExit("Failed to spread and validate funds.")
Print("Wait on cluster sync.") Print("Wait on cluster sync.")
if not cluster.waitOnClusterSync(): if not cluster.waitOnClusterSync():
...@@ -130,9 +136,9 @@ try: ...@@ -130,9 +136,9 @@ try:
# TBD: Known issue (Issue 2043) that 'get currency0000 balance' doesn't return balance. # TBD: Known issue (Issue 2043) that 'get currency0000 balance' doesn't return balance.
# Uncomment when functional # Uncomment when functional
# Print("Spread funds and validate") Print("Spread funds and validate")
# if not cluster.spreadFundsAndValidate(10): if not cluster.spreadFundsAndValidate(10):
# errorExit("Failed to spread and validate funds.") errorExit("Failed to spread and validate funds.")
Print("Wait on cluster sync.") Print("Wait on cluster sync.")
if not cluster.waitOnClusterSync(): if not cluster.waitOnClusterSync():
...@@ -150,9 +156,9 @@ try: ...@@ -150,9 +156,9 @@ try:
# TBD: Known issue (Issue 2043) that 'get currency0000 balance' doesn't return balance. # TBD: Known issue (Issue 2043) that 'get currency0000 balance' doesn't return balance.
# Uncomment when functional # Uncomment when functional
# Print("Spread funds and validate") Print("Spread funds and validate")
# if not cluster.spreadFundsAndValidate(10): if not cluster.spreadFundsAndValidate(10):
# errorExit("Failed to spread and validate funds.") errorExit("Failed to spread and validate funds.")
Print("Wait on cluster sync.") Print("Wait on cluster sync.")
if not cluster.waitOnClusterSync(): if not cluster.waitOnClusterSync():
......
...@@ -16,6 +16,7 @@ import sys ...@@ -16,6 +16,7 @@ import sys
import random import random
import json import json
import shlex import shlex
from sys import stdout
from core_symbol import CORE_SYMBOL from core_symbol import CORE_SYMBOL
...@@ -39,7 +40,7 @@ class Utils: ...@@ -39,7 +40,7 @@ class Utils:
def Print(*args, **kwargs): def Print(*args, **kwargs):
stackDepth=len(inspect.stack())-2 stackDepth=len(inspect.stack())-2
s=' '*stackDepth s=' '*stackDepth
sys.stdout.write(s) stdout.write(s)
print(*args, **kwargs) print(*args, **kwargs)
SyncStrategy=namedtuple("ChainSyncStrategy", "name id arg") SyncStrategy=namedtuple("ChainSyncStrategy", "name id arg")
...@@ -47,6 +48,7 @@ class Utils: ...@@ -47,6 +48,7 @@ class Utils:
SyncNoneTag="none" SyncNoneTag="none"
SyncReplayTag="replay" SyncReplayTag="replay"
SyncResyncTag="resync" SyncResyncTag="resync"
SyncHardReplayTag="hardReplay"
SigKillTag="kill" SigKillTag="kill"
SigTermTag="term" SigTermTag="term"
...@@ -78,6 +80,9 @@ class Utils: ...@@ -78,6 +80,9 @@ class Utils:
chainSyncStrategy=Utils.SyncStrategy(Utils.SyncResyncTag, 2, "--delete-all-blocks") chainSyncStrategy=Utils.SyncStrategy(Utils.SyncResyncTag, 2, "--delete-all-blocks")
chainSyncStrategies[chainSyncStrategy.name]=chainSyncStrategy chainSyncStrategies[chainSyncStrategy.name]=chainSyncStrategy
chainSyncStrategy=Utils.SyncStrategy(Utils.SyncHardReplayTag, 3, "--hard-replay-blockchain")
chainSyncStrategies[chainSyncStrategy.name]=chainSyncStrategy
return chainSyncStrategies return chainSyncStrategies
@staticmethod @staticmethod
...@@ -98,14 +103,24 @@ class Utils: ...@@ -98,14 +103,24 @@ class Utils:
timeout=60 timeout=60
endTime=time.time()+timeout endTime=time.time()+timeout
while endTime > time.time(): needsNewLine=False
ret=lam() try:
if ret is not None: while endTime > time.time():
return ret ret=lam()
sleepTime=3 if ret is not None:
Utils.Print("cmd: sleep %d seconds, remaining time: %d seconds" % return ret
(sleepTime, endTime - time.time())) sleepTime=3
time.sleep(sleepTime) if Utils.Debug:
Utils.Print("cmd: sleep %d seconds, remaining time: %d seconds" %
(sleepTime, endTime - time.time()))
else:
stdout.write('.')
stdout.flush()
needsNewLine=True
time.sleep(sleepTime)
finally:
if needsNewLine:
Utils.Print()
return None return None
...@@ -170,16 +185,17 @@ class Node(object): ...@@ -170,16 +185,17 @@ class Node(object):
assert trans["processed"]["receipt"]["status"] == "executed", printTrans(trans) assert trans["processed"]["receipt"]["status"] == "executed", printTrans(trans)
@staticmethod @staticmethod
def runCmdReturnJson(cmd, trace=False): def runCmdReturnJson(cmd, trace=False, silentErrors=False):
cmdArr=shlex.split(cmd) cmdArr=shlex.split(cmd)
retStr=Utils.checkOutput(cmdArr) retStr=Utils.checkOutput(cmdArr)
jStr=Node.filterJsonObject(retStr) jStr=Node.filterJsonObject(retStr)
if trace: Utils.Print ("RAW > %s"% (retStr)) if trace: Utils.Print ("RAW > %s"% (retStr))
if trace: Utils.Print ("JSON> %s"% (jStr)) if trace: Utils.Print ("JSON> %s"% (jStr))
if not jStr: if not jStr:
msg="Expected JSON response" msg="Received empty JSON response"
Utils.Print ("ERROR: "+ msg) if not silentErrors:
Utils.Print ("RAW > %s"% retStr) Utils.Print ("ERROR: "+ msg)
Utils.Print ("RAW > %s"% retStr)
raise TypeError(msg) raise TypeError(msg)
try: try:
...@@ -448,7 +464,7 @@ class Node(object): ...@@ -448,7 +464,7 @@ class Node(object):
Utils.Print("transaction parsing failed. Transaction: %s" % (trans)) Utils.Print("transaction parsing failed. Transaction: %s" % (trans))
raise raise
headBlockNum=self.getIrreversibleBlockNum() headBlockNum=self.getHeadBlockNum()
assert(headBlockNum) assert(headBlockNum)
try: try:
headBlockNum=int(headBlockNum) headBlockNum=int(headBlockNum)
...@@ -1000,7 +1016,7 @@ class Node(object): ...@@ -1000,7 +1016,7 @@ class Node(object):
cmd="%s %s get info" % (Utils.EosClientPath, self.endpointArgs) cmd="%s %s get info" % (Utils.EosClientPath, self.endpointArgs)
if Utils.Debug: Utils.Print("cmd: %s" % (cmd)) if Utils.Debug: Utils.Print("cmd: %s" % (cmd))
try: try:
trans=Node.runCmdReturnJson(cmd) trans=Node.runCmdReturnJson(cmd, silentErrors=silentErrors)
return trans return trans
except subprocess.CalledProcessError as ex: except subprocess.CalledProcessError as ex:
if not silentErrors: if not silentErrors:
...@@ -1077,34 +1093,44 @@ class Node(object): ...@@ -1077,34 +1093,44 @@ class Node(object):
return True return True
# TBD: make nodeId an internal property # TBD: make nodeId an internal property
def relaunch(self, nodeId, chainArg): def relaunch(self, nodeId, chainArg, timeout=Utils.systemWaitTimeout):
assert(self.pid is None)
assert(self.killed)
if Utils.Debug: Utils.Print("Launching node process, Id: %d" % (nodeId))
dataDir="var/lib/node_%02d" % (nodeId)
dt = datetime.datetime.now()
dateStr="%d_%02d_%02d_%02d_%02d_%02d" % (
dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second)
stdoutFile="%s/stdout.%s.txt" % (dataDir, dateStr)
stderrFile="%s/stderr.%s.txt" % (dataDir, dateStr)
with open(stdoutFile, 'w') as sout, open(stderrFile, 'w') as serr:
cmd=self.cmd + ("" if chainArg is None else (" " + chainArg))
Utils.Print("cmd: %s" % (cmd))
popen=subprocess.Popen(cmd.split(), stdout=sout, stderr=serr)
self.pid=popen.pid
running=True def isNodeAlive():
try: """wait for node to be responsive."""
os.kill(self.pid, 0) #check if process with pid is running try:
except OSError as _: return True if self.checkPulse() else False
running=False except (TypeError) as _:
pass
return False
if running: isAlive=Utils.waitForBool(isNodeAlive, timeout)
Utils.Print("WARNING: A process with pid (%d) is already running." % (self.pid)) if isAlive:
Utils.Print("Node relaunch was successfull.")
else: else:
if Utils.Debug: Utils.Print("Launching node process, Id: %d" % (nodeId)) Utils.Print("ERROR: Node relaunch Failed.")
dataDir="var/lib/node_%02d" % (nodeId) self.pid=None
dt = datetime.datetime.now() return False
dateStr="%d_%02d_%02d_%02d_%02d_%02d" % (
dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second)
stdoutFile="%s/stdout.%s.txt" % (dataDir, dateStr)
stderrFile="%s/stderr.%s.txt" % (dataDir, dateStr)
with open(stdoutFile, 'w') as sout, open(stderrFile, 'w') as serr:
cmd=self.cmd + ("" if chainArg is None else (" " + chainArg))
Utils.Print("cmd: %s" % (cmd))
popen=subprocess.Popen(cmd.split(), stdout=sout, stderr=serr)
self.pid=popen.pid
self.killed=False self.killed=False
return True return True
########################################################################################### ###########################################################################################
Wallet=namedtuple("Wallet", "name password host port") Wallet=namedtuple("Wallet", "name password host port")
...@@ -1724,7 +1750,7 @@ class Cluster(object): ...@@ -1724,7 +1750,7 @@ class Cluster(object):
Utils.Print("ERROR: Failed to spread funds across nodes.") Utils.Print("ERROR: Failed to spread funds across nodes.")
return False return False
Utils.Print("Funds spread across all accounts. Noew validate funds") Utils.Print("Funds spread across all accounts. Now validate funds")
if False == self.validateSpreadFunds(initialBalances, transferAmount, self.defproduceraAccount, self.accounts): if False == self.validateSpreadFunds(initialBalances, transferAmount, self.defproduceraAccount, self.accounts):
Utils.Print("ERROR: Failed to validate funds transfer across nodes.") Utils.Print("ERROR: Failed to validate funds transfer across nodes.")
...@@ -2155,7 +2181,7 @@ class Cluster(object): ...@@ -2155,7 +2181,7 @@ class Cluster(object):
for i in range(0, len(self.nodes)): for i in range(0, len(self.nodes)):
node=self.nodes[i] node=self.nodes[i]
if not node.relaunch(i, chainArg): if node.killed and not node.relaunch(i, chainArg):
return False return False
return True return True
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册