diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index b34ec277940b7ec01e3a30de87ffb68be906bffa..e580228aecd5511ec6a20c6e7d71bc080c241422 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -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}) diff --git a/tests/Cluster.py b/tests/Cluster.py index 58186219b37b37830cc775e191928de351dba151..463823156798aa0e9084c9718adcc8fa4e3ac458 100644 --- a/tests/Cluster.py +++ b/tests/Cluster.py @@ -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] diff --git a/tests/TestHelper.py b/tests/TestHelper.py index 92eaa0fcf79ee6d3230da253a525d6a0feab6909..543091ee94dc7700ea97055b0a44c9c63079332e 100644 --- a/tests/TestHelper.py +++ b/tests/TestHelper.py @@ -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 diff --git a/tests/WalletMgr.py b/tests/WalletMgr.py index 0f47942eaddc2c6ba8cf199922e9267b972ea37b..6a7009b59f51062d1b54fc71e011cd751a5291e2 100644 --- a/tests/WalletMgr.py +++ b/tests/WalletMgr.py @@ -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: diff --git a/tests/nodeos_run_test.py b/tests/nodeos_run_test.py index 90434246998a63668043a034b4b5733ef919cca5..ab0a5102fd34ba9e0371ce73fbe669cbcf469ee4 100755 --- a/tests/nodeos_run_test.py +++ b/tests/nodeos_run_test.py @@ -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)