Last active
January 25, 2018 01:24
-
-
Save androm3da/2003a360849cad55e59d1cafbab11e46 to your computer and use it in GitHub Desktop.
Raiblocks startup/shutdown test
This file contains hidden or 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
#!/usr/bin/env python | |
# requires a 'restart_test_reference.json' | |
# requires `requests` module, e.g. | |
# requires a sample database to start with | |
# 'touch data.ldb' should probably work if none is avail | |
# | |
# virtualenv xrb_test | |
# source xrb_test/bin/activate | |
# pip install requests | |
# ./cycle_test.py | |
import random | |
import logging | |
import requests | |
import os | |
import time | |
import json | |
import subprocess | |
import shlex | |
import tempfile | |
import shutil | |
from glob import glob | |
from subprocess import PIPE | |
from collections import namedtuple | |
STOP_CMD = { "action": "stop", } | |
STOP_TIMEOUT_SEC = 60. | |
def waitfor(p, timeout_sec): | |
# NB: this will have false indications if the | |
# wall clock moves during the test | |
shutdown_start = time.time() | |
shutdown_end = None | |
deadline_sec = shutdown_start + timeout_sec | |
while time.time() < deadline_sec: | |
time.sleep(0.5) | |
if not p.poll() is None: | |
shutdown_end = time.time() | |
shutdown_dur = shutdown_end - shutdown_start | |
break | |
return shutdown_dur if shutdown_end else None | |
TestResult = namedtuple('TestResult', 'stdout stderr log shutdown_dur_sec response'.split()) | |
def run_test(test_duration_sec, port_num, data_ldb): | |
node_dir = tempfile.mkdtemp() | |
try: | |
with open('restart_test_reference.json', 'rt') as f: | |
ref_config = json.load(f) | |
ref_config['rpc']['port'] = str(port_num) | |
cfg_path = os.path.join(node_dir, 'config.json') | |
with open(cfg_path, 'wt') as f: | |
json.dump(ref_config, f) | |
db_path = os.path.join(node_dir, 'data.ldb') | |
os.link(data_ldb, db_path) | |
cmd = shlex.split('./rai_node --daemon --data_path={}'.format(node_dir)) | |
p = subprocess.Popen(cmd, stdout=PIPE, stderr=PIPE) | |
logging.info('Sleeping for {}'.format(test_duration_sec)) | |
time.sleep(test_duration_sec) | |
url = 'http://[::1]:{}'.format(port_num) | |
try: | |
response = requests.post(url, json=STOP_CMD) | |
except requests.exceptions.ConnectionError as e: | |
logging.error('unable to connect to RPC') | |
shutdown_dur_sec = waitfor(p, STOP_TIMEOUT_SEC) | |
if shutdown_dur_sec is None: | |
logging.info('timed out waiting for shutdown') | |
p.terminate() | |
out = p.stdout.read() | |
err = p.stderr.read() | |
log_path = glob(os.path.join(node_dir, 'log') + '/*')[0] | |
log = open(log_path, 'rt').read() | |
finally: | |
shutil.rmtree(node_dir) | |
return TestResult(out, err, log, shutdown_dur_sec, response) | |
if __name__ == '__main__': | |
dur_sec = 90 + 800*random.random() | |
res = run_test(dur_sec, 7099, 'data.ldb') | |
print(res.stdout) | |
print('----') | |
print(res.stderr) | |
print('----') | |
print(res.log) | |
print('----') | |
print(res.response.text) | |
print('----') | |
print(res.shutdown_dur_sec) |
This file contains hidden or 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
{ | |
"version": "2", | |
"rpc_enable": "true", | |
"rpc": { | |
"address": "::1", | |
"port": "7076", | |
"enable_control": "true", | |
"frontier_request_limit": "16384", | |
"chain_request_limit": "16384" | |
}, | |
"node": { | |
"version": "8", | |
"peering_port": "7075", | |
"bootstrap_fraction_numerator": "1", | |
"receive_minimum": "1000000000000000000000000", | |
"logging": { | |
"version": "2", | |
"ledger": "false", | |
"ledger_duplicate": "false", | |
"vote": "false", | |
"network": "true", | |
"network_message": "false", | |
"network_publish": "false", | |
"network_packet": "false", | |
"network_keepalive": "false", | |
"node_lifetime_tracing": "false", | |
"insufficient_work": "true", | |
"log_rpc": "true", | |
"bulk_pull": "false", | |
"work_generation_time": "true", | |
"log_to_cerr": "false", | |
"max_size": "16777216" | |
}, | |
"work_peers": "", | |
"preconfigured_peers": [ | |
"rai.raiblocks.net" | |
], | |
"preconfigured_representatives": [ | |
"xrb_3arg3asgtigae3xckabaaewkx3bzsh7nwz7jkmjos79ihyaxwphhm6qgjps4", | |
"xrb_1stofnrxuz3cai7ze75o174bpm7scwj9jn3nxsn8ntzg784jf1gzn1jjdkou", | |
"xrb_1q3hqecaw15cjt7thbtxu3pbzr1eihtzzpzxguoc37bj1wc5ffoh7w74gi6p", | |
"xrb_3dmtrrws3pocycmbqwawk6xs7446qxa36fcncush4s1pejk16ksbmakis78m", | |
"xrb_3hd4ezdgsp15iemx7h81in7xz5tpxi43b6b41zn3qmwiuypankocw3awes5k", | |
"xrb_1awsn43we17c1oshdru4azeqjz9wii41dy8npubm4rg11so7dx3jtqgoeahy", | |
"xrb_1anrzcuwe64rwxzcco8dkhpyxpi8kd7zsjc1oeimpc3ppca4mrjtwnqposrs", | |
"xrb_1hza3f7wiiqa7ig3jczyxj5yo86yegcmqk3criaz838j91sxcckpfhbhhra1" | |
], | |
"inactive_supply": "0", | |
"password_fanout": "1024", | |
"io_threads": "4", | |
"work_threads": "4", | |
"enable_voting": "true", | |
"bootstrap_connections": "4", | |
"callback_address": "", | |
"callback_port": "0", | |
"callback_target": "", | |
"lmdb_max_dbs": "128" | |
}, | |
"opencl_enable": "false", | |
"opencl": { | |
"platform": "0", | |
"device": "0", | |
"threads": "1048576" | |
} | |
} |
This file contains hidden or 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
{ | |
"version": "2", | |
"rpc_enable": "true", | |
"rpc": { | |
"address": "::1", | |
"port": "7076", | |
"enable_control": "true", | |
"frontier_request_limit": "16384", | |
"chain_request_limit": "16384" | |
}, | |
"node": { | |
"version": "8", | |
"peering_port": "7075", | |
"bootstrap_fraction_numerator": "1", | |
"receive_minimum": "1000000000000000000000000", | |
"logging": { | |
"version": "2", | |
"ledger": "false", | |
"ledger_duplicate": "false", | |
"vote": "false", | |
"network": "true", | |
"network_message": "false", | |
"network_publish": "false", | |
"network_packet": "false", | |
"network_keepalive": "false", | |
"node_lifetime_tracing": "false", | |
"insufficient_work": "true", | |
"log_rpc": "true", | |
"bulk_pull": "false", | |
"work_generation_time": "true", | |
"log_to_cerr": "false", | |
"max_size": "16777216" | |
}, | |
"work_peers": "", | |
"preconfigured_peers": [ | |
"rai.raiblocks.net" | |
], | |
"preconfigured_representatives": [ | |
"xrb_3arg3asgtigae3xckabaaewkx3bzsh7nwz7jkmjos79ihyaxwphhm6qgjps4", | |
"xrb_1stofnrxuz3cai7ze75o174bpm7scwj9jn3nxsn8ntzg784jf1gzn1jjdkou", | |
"xrb_1q3hqecaw15cjt7thbtxu3pbzr1eihtzzpzxguoc37bj1wc5ffoh7w74gi6p", | |
"xrb_3dmtrrws3pocycmbqwawk6xs7446qxa36fcncush4s1pejk16ksbmakis78m", | |
"xrb_3hd4ezdgsp15iemx7h81in7xz5tpxi43b6b41zn3qmwiuypankocw3awes5k", | |
"xrb_1awsn43we17c1oshdru4azeqjz9wii41dy8npubm4rg11so7dx3jtqgoeahy", | |
"xrb_1anrzcuwe64rwxzcco8dkhpyxpi8kd7zsjc1oeimpc3ppca4mrjtwnqposrs", | |
"xrb_1hza3f7wiiqa7ig3jczyxj5yo86yegcmqk3criaz838j91sxcckpfhbhhra1" | |
], | |
"inactive_supply": "0", | |
"password_fanout": "1024", | |
"io_threads": "4", | |
"work_threads": "4", | |
"enable_voting": "true", | |
"bootstrap_connections": "4", | |
"callback_address": "", | |
"callback_port": "0", | |
"callback_target": "", | |
"lmdb_max_dbs": "128" | |
}, | |
"opencl_enable": "false", | |
"opencl": { | |
"platform": "0", | |
"device": "0", | |
"threads": "1048576" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment