Skip to content

Commit

Permalink
smoketest scripts fixes (previous commit not completed) steemit#2365
Browse files Browse the repository at this point in the history
  • Loading branch information
mkochanowicz committed Apr 19, 2018
1 parent b418c83 commit 1c28a60
Show file tree
Hide file tree
Showing 28 changed files with 433 additions and 152 deletions.
1 change: 1 addition & 0 deletions tests/.dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ undo_data
generate_empty_blocks
*.cpp
*.hpp
__pycache__
Empty file modified tests/api_tests/jsonsocket.py
100755 → 100644
Empty file.
9 changes: 4 additions & 5 deletions tests/api_tests/list_account.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def list_accounts(url):
accounts_count = 0
accounts = []

while end == False:
while True:
request = bytes( json.dumps( {
"jsonrpc": "2.0",
"id": 0,
Expand All @@ -38,15 +38,14 @@ def list_accounts(url):
del account_list[0]

if len( account_list ) == 0:
end = True
continue
break

last_account = account_list[-1]["name"]
accounts_count += len( accounts )
for account in account_list:
accounts.append( account["name"] )

# while end == False
# while True
return accounts


Expand Down Expand Up @@ -75,4 +74,4 @@ def main():


if __name__ == "__main__":
main()
main()
10 changes: 6 additions & 4 deletions tests/api_tests/list_comment.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def list_comments(url):
end = False
comments = []

while end == False:
while True:
request = bytes( json.dumps( {
"jsonrpc": "2.0",
"id": 0,
Expand All @@ -32,18 +32,20 @@ def list_comments(url):

comment_list = response["result"]["comments"]

if len(comment_list) == 0:
break

actual_cashout_time = comment_list[-1]["cashout_time"]

if actual_cashout_time == last_cashout_time:
end = True
continue
break

last_cashout_time = actual_cashout_time

for comment in comment_list:
comments.append( comment["permlink"]+";"+comment["author"] +";"+comment["last_update"] )

# while end == False
# while True
return comments


Expand Down
44 changes: 26 additions & 18 deletions tests/api_tests/test_ah_get_account_history.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@
errors = 0


def future_end_cb(future):
global errors
if future.result() == False:
errors += 1


def main():
if len( sys.argv ) < 4 or len( sys.argv ) > 6:
print( "Usage: __name__ jobs url1 url2 [working_dir [accounts_file]]" )
Expand Down Expand Up @@ -78,17 +84,19 @@ def main():

if jobs > 1:
first = 0
last = length - 1
last = length
accounts_per_job = length // jobs

with ProcessPoolExecutor(max_workers=jobs) as executor:
for i in range(jobs-1):
executor.submit(compare_results, url1, url2, accounts[first : first+accounts_per_job-1])
future = executor.submit(compare_results, url1, url2, accounts[first : first+accounts_per_job])
future.add_done_callback(future_end_cb)
first = first + accounts_per_job
executor.submit(compare_results, url1, url2, accounts[first : last])
future = executor.submit(compare_results, url1, url2, accounts[first : last])
future.add_done_callback(future_end_cb)
else:
compare_results(url1, url2, accounts)
errors = (compare_results(url1, url2, accounts) == False)

exit( errors )


Expand All @@ -112,11 +120,11 @@ def compare_results(url1, url2, accounts, max_tries=10, timeout=0.1):
success = False; break

print("Compare accounts: [{}..{}] {}".format(accounts[0], accounts[-1], "finished" if success else "break with error" ))
return success


def get_account_history(url1, url2, account, max_tries=10, timeout=0.1):
global wdir
global errors
START = -1
HARD_LIMIT = 10000
LIMIT = HARD_LIMIT
Expand All @@ -140,20 +148,20 @@ def get_account_history(url1, url2, account, max_tries=10, timeout=0.1):

if status1 == False or status2 == False or json1 != json2:
print("Comparison failed for account: {}; start: {}; limit: {}".format(account, START, LIMIT))
errors += 1

filename = wdir / account
try: file = filename.open("w")
except: print("Cannot open file:", filename); return False
filename1 = wdir / (account + "_ref")
filename2 = wdir / (account + "_tested")
try: file1 = filename1.open("w")
except: print("Cannot open file:", filename1); return False
try: file2 = filename2.open("w")
except: print("Cannot open file:", filename2); return False

file.write("Comparison failed:\n")
file.write("{} response:\n".format(url1))
json.dump(json1, file, indent=2, sort_keys=True)
file.write("\n")
file.write("{} response:\n".format(url2))
json.dump(json2, file, indent=2, sort_keys=True)
file.write("\n")
file.close()
file1.write("{} response:\n".format(url1))
json.dump(json1, file1, indent=2, sort_keys=True)
file1.close()
file2.write("{} response:\n".format(url2))
json.dump(json2, file2, indent=2, sort_keys=True)
file2.close()
return False

history = json1["result"]["history"]
Expand Down
42 changes: 25 additions & 17 deletions tests/api_tests/test_ah_get_ops_in_block.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@
errors = 0


def future_end_cb(future):
global errors
if future.result() == False:
errors += 1


def main():
if len(sys.argv) < 4 or len(sys.argv) > 7:
print("Usage: script_name jobs url1 url2 [wdir [last_block [first_block]]]")
Expand Down Expand Up @@ -89,11 +95,13 @@ def main():

with ProcessPoolExecutor(max_workers=jobs) as executor:
for i in range(jobs-1):
executor.submit(compare_results, first_block, (first_block + blocks_per_job - 1), url1, url2)
future = executor.submit(compare_results, first_block, (first_block + blocks_per_job - 1), url1, url2)
future.add_done_callback(future_end_cb)
first_block = first_block + blocks_per_job
executor.submit(compare_results, first_block, last_block, url1, url2)
future = executor.submit(compare_results, first_block, last_block, url1, url2)
future.add_done_callback(future_end_cb)
else:
compare_results(first_block, last_block, url1, url2)
errors = (compare_results(first_block, last_block, url1, url2) == False)

exit( errors )

Expand Down Expand Up @@ -129,7 +137,6 @@ def get_last_block(url, max_tries=10, timeout=0.1):

def compare_results(f_block, l_block, url1, url2, max_tries=10, timeout=0.1):
global wdir
global errors

print( "Compare blocks [{} : {}]".format(f_block, l_block) )

Expand All @@ -154,24 +161,25 @@ def compare_results(f_block, l_block, url1, url2, max_tries=10, timeout=0.1):

if status1 == False or status2 == False or json1 != json2:
print("Difference @block: {}\n".format(i))
errors += 1

filename = wdir / Path(str(f_block) + "_" + str(l_block) + ".log")
try: file = filename.open( "w" )
except: print( "Cannot open file:", filename ); return
filename1 = wdir / Path(str(f_block) + "_" + str(l_block) + "_ref.log")
filename2 = wdir / Path(str(f_block) + "_" + str(l_block) + "_tested.log")
try: file1 = filename1.open( "w" )
except: print( "Cannot open file:", filename1 ); return
try: file2 = filename2.open( "w" )
except: print( "Cannot open file:", filename2 ); return

file.write("Difference @block: {}\n".format(i))
file.write("{} response:\n".format(url1))
json.dump(json1, file, indent=2, sort_keys=True)
file.write("\n")
file.write("{} response:\n".format(url2))
json.dump(json2, file, indent=2, sort_keys=True)
file.write("\n")
file.close()
file1.write("{} response:\n".format(url1))
json.dump(json1, file1, indent=2, sort_keys=True)
file1.close
file2.write("{} response:\n".format(url2))
json.dump(json2, file2, indent=2, sort_keys=True)
file2.close()
print( "Compare blocks [{} : {}] break with error".format(f_block, l_block) )
return
return False

print( "Compare blocks [{} : {}] finished".format(f_block, l_block) )
return True


if __name__ == "__main__":
Expand Down
20 changes: 14 additions & 6 deletions tests/api_tests/test_list_votes.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@
errors = 0
nr_cycles = 3


def future_end_cb(future):
global errors
if future.result() == False:
errors += 1


def main():
if len( sys.argv ) < 4 or len( sys.argv ) > 7:
print( "Usage: __name__ jobs url1 url2 [nr_cycles [working_dir [comments_file]]]" )
Expand Down Expand Up @@ -84,16 +91,18 @@ def main():

if jobs > 1:
first = 0
last = length - 1
last = length
comments_per_job = length // jobs

with ProcessPoolExecutor(max_workers=jobs) as executor:
for i in range(jobs-1):
executor.submit(compare_results, url1, url2, comments[first : first+comments_per_job-1])
future = executor.submit(compare_results, url1, url2, comments[first : first+comments_per_job])
future.add_done_callback(future_end_cb)
first = first + comments_per_job
executor.submit(compare_results, url1, url2, comments[first : last])
future = executor.submit(compare_results, url1, url2, comments[first : last])
future.add_done_callback(future_end_cb)
else:
compare_results(url1, url2, comments)
errors = (compare_results(url1, url2, comments) == False)

exit( errors )

Expand Down Expand Up @@ -123,11 +132,11 @@ def compare_results(url1, url2, comments, max_tries=10, timeout=0.1):
success = False; break

print("Compare comments: [{}..{}] {}".format(comments[0], comments[ nr_cycles - 1 if nr_cycles > 0 else -1 ], "finished" if success else "break with error" ))
return success


def list_votes(url1, url2, comment_line, max_tries=10, timeout=0.1):
global wdir
global errors
LIMIT = 1000

comment_array = comment_line.split(';')
Expand Down Expand Up @@ -156,7 +165,6 @@ def list_votes(url1, url2, comment_line, max_tries=10, timeout=0.1):

if status1 == False or status2 == False or json1 != json2:
print("Comparison failed for permlink: {}; author: {}; limit: {}".format(permlink, author, LIMIT))
errors += 1

filename = wdir / permlink
try: file = filename.open("w")
Expand Down
20 changes: 14 additions & 6 deletions tests/api_tests/test_list_votes2.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@
errors = 0
nr_cycles = 3


def future_end_cb(future):
global errors
if future.result() == False:
errors += 1


def main():
if len( sys.argv ) < 4 or len( sys.argv ) > 7:
print( "Usage: __name__ jobs url1 url2 [nr_cycles [working_dir [comments_file]]]" )
Expand Down Expand Up @@ -84,16 +91,18 @@ def main():

if jobs > 1:
first = 0
last = length - 1
last = length
comments_per_job = length // jobs

with ProcessPoolExecutor(max_workers=jobs) as executor:
for i in range(jobs-1):
executor.submit(compare_results, url1, url2, comments[first : first+comments_per_job-1])
future = executor.submit(compare_results, url1, url2, comments[first : first+comments_per_job])
future.add_done_callback(future_end_cb)
first = first + comments_per_job
executor.submit(compare_results, url1, url2, comments[first : last])
future = executor.submit(compare_results, url1, url2, comments[first : last])
future.add_done_callback(future_end_cb)
else:
compare_results(url1, url2, comments)
errors = (compare_results(url1, url2, comments) == False)

exit( errors )

Expand Down Expand Up @@ -123,11 +132,11 @@ def compare_results(url1, url2, comments, max_tries=10, timeout=0.1):
success = False; break

print("Compare comments: [{}..{}] {}".format(comments[0], comments[ nr_cycles - 1 if nr_cycles > 0 else -1 ], "finished" if success else "break with error" ))
return success


def list_votes(url1, url2, comment_line, max_tries=10, timeout=0.1):
global wdir
global errors
LIMIT = 1000

comment_array = comment_line.split(';')
Expand Down Expand Up @@ -157,7 +166,6 @@ def list_votes(url1, url2, comment_line, max_tries=10, timeout=0.1):

if status1 == False or status2 == False or json1 != json2:
print("Comparison failed for permlink: {}; author: {}; limit: {}".format(permlink, author, LIMIT))
errors += 1

filename = wdir / permlink
try: file = filename.open("w")
Expand Down
Empty file modified tests/scripts/create_account_list.py
100755 → 100644
Empty file.
Empty file modified tests/scripts/test_ah_get_account_history.sh
100755 → 100644
Empty file.
Empty file modified tests/scripts/test_ah_get_ops_in_block.sh
100755 → 100644
Empty file.
3 changes: 0 additions & 3 deletions tests/smoketest/.dockerignore

This file was deleted.

14 changes: 11 additions & 3 deletions tests/smoketest/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ RUN apt-get install -y apt-utils
RUN apt-get install -y libreadline-dev
RUN apt-get install -y python3
RUN apt-get install -y python3-pip
RUN apt-get install -y net-tools
RUN apt-get install -y cpio
RUN pip3 install --upgrade pip
RUN pip3 install pyresttest

COPY . $SMOKETEST
COPY . $WDIR/

RUN apt-get clean
RUN rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
Expand All @@ -21,8 +23,14 @@ RUN rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
#tested: volume points to tested steemd
#ref_blockchain: volume points to reference folder, where blockchain folder exists
#tested_blockchain: volume points to tested folder, where blockchain folder exists
VOLUME ["reference", "tested", "ref_blockchain", "tested_blockchain"]
#logs_dir: location where non-empty logs will be copied
VOLUME ["reference", "tested", "ref_blockchain", "tested_blockchain", "logs_dir", "run"]

EXPOSE 8090
EXPOSE 8091

#CMD pyresttest
CMD cd $SMOKETEST && \
./smoketest.sh /reference/steemd /tested/steemd /ref_blockchain /tested_blockchain $STOP_REPLAY_AT_BLOCK
./smoketest.sh /reference/steemd /tested/steemd /ref_blockchain /tested_blockchain $STOP_REPLAY_AT_BLOCK $JOBS || \
find ./ -type f -not -name logs -path */logs/* | cpio -pd /logs_dir && \
chmod -R a+rw /logs_dir
Loading

0 comments on commit 1c28a60

Please sign in to comment.