Skip to content

Commit

Permalink
Working ping test!
Browse files Browse the repository at this point in the history
  • Loading branch information
lsankar4033 committed Aug 14, 2020
1 parent 770627d commit 2140710
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 33 deletions.
7 changes: 6 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,10 @@ services:
before_install:
- pip install -U pip

install:
- cp ./bin/rumor-v0.2.3-linux-amd64 ./bin/rumor # move rumor into place for test discovery
- pip install .
- pip install -r requirements.txt

script:
- ./steth.py logging_test
- ./steth.py test -o tests/reqresp/ping.py
Binary file added bin/rumor
Binary file not shown.
Binary file added bin/rumor-v0.2.3-linux-amd64
Binary file not shown.
7 changes: 5 additions & 2 deletions lib/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,15 @@ def run_test_files(fixture_name, files, args):
failures[module] = (return_code, logs)

if len(failures) > 0:
print('')
print('--failures--')
for module, (return_code, logs) in failures.items():
print('')
print(f'\t{module} {return_code_to_status(return_code)}')

for log in logs:
print(f'\t{log}')
print(f'\t\t{log}')

print('')

return 1

Expand Down
26 changes: 16 additions & 10 deletions tests/reqresp/ping.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,32 @@
from eth2spec.utils.ssz.ssz_typing import uint64
from sclients import connect_rumor

from ..utils import parse_response, with_rumor
from ..utils import parse_chunk_response, with_rumor


@with_rumor
async def run(rumor, args):
peer_id = await connect_rumor(rumor, args['client'], args['enr'])

logs = []
return_code = 0
for i in range(5):
req = uint64(i).encode_bytes().hex()
resp = await rumor.rpc.ping.req.raw(peer_id, req, raw=True, compression='snappy')
(rc, resp_data) = parse_response(resp)
if rc != 0:
return_code = rc
continue

req_data = uint64(0).encode_bytes().hex()
req_call = rumor.rpc.ping.req.raw(peer_id, req_data, raw=True, compression='snappy')
await req_call
await req_call.next()
resp = await req_call.next()

(resp_data, l) = parse_chunk_response(resp)
logs.extend(l)
if resp_data is None:
return_code = 1

else:
pong = uint64.decode_bytes(bytes.fromhex(resp_data))

if not isinstance(pong, int) or pong < 0:
# TODO: add logs
logs.append(f'invalid ping response: {pong}')
return_code = 1

return (return_code, [])
return (return_code, logs)
27 changes: 7 additions & 20 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

def with_rumor(async_run_fn):
async def wrapped_run_fn(args):
async with SubprocessConn(cmd='rumor bare --level=trace') as conn:
async with SubprocessConn(cmd='./bin/rumor bare --level=trace') as conn:
async with trio.open_nursery() as nursery:
try:
rumor = Rumor(conn, nursery)
Expand All @@ -18,24 +18,11 @@ async def wrapped_run_fn(args):

return wrapped_run_fn

def compare_containers(expected: Container, actual: Container):
if expected != actual:
error_str = ''
for field in expected.fields():
compare_vals(getattr(expected, field), getattr(actual, field), field)
def parse_chunk_response(resp):
if not(resp['result_code'] == 0):
return (None, [f"request error: {resp['msg']}"])

if 'data' not in resp:
return (None, [f"request error: 'data' field not in response"])

def compare_vals(expected, actual, name):
if expected != actual:
print(
f'{name} -- expected {expected} actual {actual}',
file=sys.stderr
)


# NOTE: Eventually, return code will be handled on an object
def parse_response(resp):
if not('chunk' in resp and 'data' in resp['chunk']):
return (1, None)

return (0, resp['chunk']['data'])
return (resp['data'], [])

0 comments on commit 2140710

Please sign in to comment.