forked from EOSIO/eos
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request EOSIO#186 from enumivo/staging
Staging
- Loading branch information
Showing
6 changed files
with
171 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import testUtils | ||
|
||
import argparse | ||
import random | ||
import subprocess | ||
import time | ||
import os | ||
import signal | ||
|
||
############################################################### | ||
# Test for validating the dirty db flag sticks repeated enunode restart attempts | ||
############################################################### | ||
|
||
|
||
Print=testUtils.Utils.Print | ||
|
||
def errorExit(msg="", errorCode=1): | ||
Print("ERROR:", msg) | ||
exit(errorCode) | ||
|
||
parser = argparse.ArgumentParser() | ||
parser.add_argument("-v", help="verbose logging", action='store_true') | ||
parser.add_argument("--dont-kill", help="Leave cluster running after test finishes", action='store_true') | ||
parser.add_argument("--dump-error-details", | ||
help="Upon error print etc/enumivo/node_*/config.ini and var/lib/node_*/stderr.log to stdout", | ||
action='store_true') | ||
parser.add_argument("--keep-logs", help="Don't delete var/lib/node_* folders upon test completion", | ||
action='store_true') | ||
|
||
args = parser.parse_args() | ||
debug=args.v | ||
pnodes=1 | ||
topo="mesh" | ||
delay=1 | ||
chainSyncStrategyStr=testUtils.Utils.SyncResyncTag | ||
total_nodes = pnodes | ||
killCount=1 | ||
killSignal=testUtils.Utils.SigKillTag | ||
|
||
killEnuInstances= not args.dont_kill | ||
dumpErrorDetails=args.dump_error_details | ||
keepLogs=args.keep_logs | ||
|
||
seed=1 | ||
testUtils.Utils.Debug=debug | ||
testSuccessful=False | ||
|
||
random.seed(seed) # Use a fixed seed for repeatability. | ||
cluster=testUtils.Cluster(enuwalletd=True) | ||
|
||
try: | ||
cluster.setChainStrategy(chainSyncStrategyStr) | ||
|
||
cluster.killall() | ||
cluster.cleanup() | ||
|
||
Print ("producing nodes: %d, topology: %s, delay between nodes launch(seconds): %d, chain sync strategy: %s" % ( | ||
pnodes, topo, delay, chainSyncStrategyStr)) | ||
|
||
Print("Stand up cluster") | ||
if cluster.launch(pnodes, total_nodes, topo=topo, delay=delay, dontBootstrap=True) is False: | ||
errorExit("Failed to stand up enu cluster.") | ||
|
||
node=cluster.getNode(0) | ||
if node is None: | ||
errorExit("Cluster in bad state, received None node") | ||
|
||
Print("Kill cluster nodes.") | ||
cluster.killall() | ||
|
||
def runEnunodeAndGetOutput(nodeId, timeout=3): | ||
"""Startup enunode, wait for timeout (before forced shutdown) and collect output. Stdout, stderr and return code are returned in a dictionary.""" | ||
Print("Launching enunode process id: %d" % (nodeId)) | ||
dataDir="var/lib/node_%02d" % (nodeId) | ||
cmd="programs/enunode/enunode --config-dir etc/enumivo/node_bios --data-dir var/lib/node_bios" | ||
Print("cmd: %s" % (cmd)) | ||
proc=subprocess.Popen(cmd.split(), stdout=subprocess.PIPE, stderr=subprocess.PIPE) | ||
|
||
output={} | ||
try: | ||
outs,errs = proc.communicate(timeout=timeout) | ||
output["stdout"] = outs.decode("utf-8") | ||
output["stderr"] = errs.decode("utf-8") | ||
output["returncode"] = proc.returncode | ||
except (subprocess.TimeoutExpired) as _: | ||
Print("ERROR: Enunode is running beyond the defined wait time. Hard killing enunode instance.") | ||
proc.send_signal(signal.SIGKILL) | ||
return (False, None) | ||
|
||
return (True, output) | ||
|
||
Print("Restart enunode repeatedly to ensure dirty database flag sticks.") | ||
nodeId=0 | ||
timeout=3 | ||
|
||
for i in range(0,3): | ||
Print("Attempt %d." % (i)) | ||
ret = runEnunodeAndGetOutput(nodeId, timeout) | ||
if not ret or not ret[0]: | ||
exit(1) | ||
|
||
#Print(ret) | ||
|
||
stderr=ret[1]["stderr"] | ||
retCode=ret[1]["returncode"] | ||
assert(retCode == 2) | ||
assert("database dirty flag set" in stderr) | ||
|
||
testSuccessful=True | ||
finally: | ||
if testSuccessful: | ||
Print("Test succeeded.") | ||
else: | ||
Print("Test failed.") | ||
|
||
if not testSuccessful and dumpErrorDetails: | ||
cluster.dumpErrorDetails() | ||
Print("== Errors see above ==") | ||
|
||
if killEnuInstances: | ||
Print("Shut down the cluster.") | ||
cluster.killall() | ||
if testSuccessful and not keepLogs: | ||
Print("Cleanup cluster data.") | ||
cluster.cleanup() | ||
|
||
exit(0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters