提交 6379a9fb 编写于 作者: C Ciju John

Add sanity test for ensuring basic setup. Small test refactoring for...

Add sanity test for ensuring basic setup. Small test refactoring for initializing producer accounts. Add port availability check.
上级 b8f17f2e
......@@ -42,6 +42,7 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/validate-dirty-db.py ${CMAKE_CURRENT_
#To run plugin_test with all log from blockchain displayed, put --verbose after --, i.e. plugin_test -- --verbose
add_test(NAME plugin_test COMMAND plugin_test --report_level=detailed --color_output)
add_test(NAME nodeos_sanity_test COMMAND tests/nodeos_run_test.py -v --sanity-test --clean-run --dump-error-detail WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
add_test(NAME nodeos_run_test COMMAND tests/nodeos_run_test.py -v --clean-run --dump-error-detail WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
add_test(NAME p2p_dawn515_test COMMAND tests/p2p_tests/dawn_515/test.sh WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
......
......@@ -12,6 +12,7 @@ import datetime
import sys
import random
import json
import socket
from core_symbol import CORE_SYMBOL
from testUtils import Utils
......@@ -70,9 +71,11 @@ class Cluster(object):
self.mongoEndpointArgs += "--host %s --port %d %s" % (mongoHost, mongoPort, mongoDb)
self.staging=staging
# init accounts
self.defproduceraAccount=Account("defproducera")
self.defproducerbAccount=Account("defproducerb")
self.eosioAccount=Account("eosio")
self.defProducerAccounts={}
self.defproduceraAccount=self.defProducerAccounts["defproducera"]= Account("defproducera")
self.defproducerbAccount=self.defProducerAccounts["defproducerb"]= Account("defproducerb")
self.eosioAccount=self.defProducerAccounts["eosio"]= Account("eosio")
self.defproduceraAccount.ownerPrivateKey=defproduceraPrvtKey
self.defproduceraAccount.activePrivateKey=defproduceraPrvtKey
self.defproducerbAccount.ownerPrivateKey=defproducerbPrvtKey
......@@ -109,10 +112,15 @@ class Cluster(object):
if len(self.nodes) > 0:
raise RuntimeError("Cluster already running.")
if totalProducers!=None:
producerFlag=""
if totalProducers:
assert(isinstance(totalProducers, str))
producerFlag="--producers %s" % (totalProducers)
else:
producerFlag=""
if not Cluster.arePortsAvailable(set(range(self.port, self.port+totalNodes+1))):
Utils.Print("ERROR: Another process is listening on nodeos default port.")
return False
cmd="%s -p %s -n %s -s %s -d %s -i %s -f --p2p-plugin %s %s" % (
Utils.EosLauncherPath, pnodes, totalNodes, topo, delay, datetime.datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%S.%f")[:-3],
p2pPlugin, producerFlag)
......@@ -183,19 +191,52 @@ class Cluster(object):
account.activePrivateKey=keys["private"]
account.activePublicKey=keys["public"]
initAccountKeys(self.eosioAccount, producerKeys["eosio"])
initAccountKeys(self.defproduceraAccount, producerKeys["defproducera"])
initAccountKeys(self.defproducerbAccount, producerKeys["defproducerb"])
for name,initKeys in producerKeys.items():
account=Account(name)
initAccountKeys(account, producerKeys[name])
self.defProducerAccounts[name] = account
self.eosioAccount=self.defProducerAccounts["eosio"]
self.defproduceraAccount=self.defProducerAccounts["defproducera"]
self.defproducerbAccount=self.defProducerAccounts["defproducerb"]
return True
@staticmethod
def arePortsAvailable(ports):
"""Check if specified ports are available for listening on."""
assert(ports)
assert(isinstance(ports, set))
for port in ports:
if Utils.Debug: Utils.Print("Checking if port %d is available." % (port))
assert(isinstance(port, int))
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
try:
s.bind(("127.0.0.1", port))
except socket.error as e:
if e.errno == errno.EADDRINUSE:
Utils.Print("ERROR: Port %d is already in use" % (port))
else:
# something else raised the socket.error exception
Utils.Print("ERROR: Unknown exception while trying to listen on port %d" % (port))
Utils.Print(e)
return False
finally:
s.close()
return True
# Initialize the default nodes (at present just the root node)
def initializeNodes(self, defproduceraPrvtKey=None, defproducerbPrvtKey=None, onlyBios=False):
port=Cluster.__BiosPort if onlyBios else self.port
host=Cluster.__BiosHost if onlyBios else self.host
node=Node(host, port, enableMongo=self.enableMongo, mongoHost=self.mongoHost, mongoPort=self.mongoPort, mongoDb=self.mongoDb)
node.setWalletEndpointArgs(self.walletEndpointArgs)
if Utils.Debug: Utils.Print("Node:", node)
if Utils.Debug: Utils.Print("Node: %s", str(node))
node.checkPulse()
self.nodes=[node]
......
......@@ -77,6 +77,8 @@ class TestHelper(object):
parser.add_argument("--only-bios", help="Limit testing to bios node.", action='store_true')
if "--clean-run" in includeArgs:
parser.add_argument("--clean-run", help="Kill all nodeos and kleos instances", action='store_true')
if "--sanity-test" in includeArgs:
parser.add_argument("--sanity-test", help="Validates nodeos and kleos are in path and can be started up.", action='store_true')
args = parser.parse_args()
return args
......
......@@ -181,7 +181,7 @@ class WalletMgr(object):
def killall(self, allInstances=False):
"""Kill keos instances. allInstances will kill all keos instances running on the system."""
if self.__walletPid:
Utils.Print("Killing wallet manager process %d:" % (self.__walletPid))
Utils.Print("Killing wallet manager process %d" % (self.__walletPid))
os.kill(self.__walletPid, signal.SIGKILL)
if allInstances:
......
......@@ -28,7 +28,8 @@ def cmdError(name, cmdCode=0, exitNow=False):
Print(msg)
args = TestHelper.parse_args({"--host","--port","--prod-count","--defproducera_prvt_key","--defproducerb_prvt_key","--mongodb"
,"--dump-error-details","--dont-launch","--keep-logs","-v","--leave-running","--only-bios","--clean-run"})
,"--dump-error-details","--dont-launch","--keep-logs","-v","--leave-running","--only-bios","--clean-run"
,"--sanity-test"})
server=args.host
port=args.port
debug=args.v
......@@ -42,6 +43,7 @@ dontKill=args.leave_running
prodCount=args.prod_count
onlyBios=args.only_bios
killAll=args.clean_run
sanityTest=args.sanity_test
Utils.Debug=debug
localTest=True if server == TestHelper.LOCAL_HOST else False
......@@ -50,6 +52,7 @@ walletMgr=WalletMgr(True)
testSuccessful=False
killEosInstances=not dontKill
killWallet=not dontKill
dontBootstrap=sanityTest
WalletdName="keosd"
ClientName="cleos"
......@@ -70,13 +73,17 @@ try:
cluster.killall(allInstances=killAll)
cluster.cleanup()
Print("Stand up cluster")
if cluster.launch(prodCount=prodCount, onlyBios=onlyBios, dontKill=dontKill) is False:
if cluster.launch(prodCount=prodCount, onlyBios=onlyBios, dontKill=dontKill, dontBootstrap=dontBootstrap) is False:
cmdError("launcher")
errorExit("Failed to stand up eos cluster.")
else:
cluster.initializeNodes(defproduceraPrvtKey=defproduceraPrvtKey, defproducerbPrvtKey=defproducerbPrvtKey)
killEosInstances=False
if sanityTest:
testSuccessful=True
exit(0)
Print("Validating system accounts after bootstrap")
cluster.validateAccounts(None)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册