Browse Source

Multi process test use now generator instead of sequence to describe the test, making easier to implement test logic and storage of intermediate results

PYADPT-55
Edouard Tisserant 9 years ago
parent
commit
67f1d46c15
  1. 41
      test/mp_sync_test.py
  2. 20
      test/multipEp.py

41
test/mp_sync_test.py

@ -9,46 +9,39 @@ python3.4 mp_sync_test.py
""" """
stored_message = []
def store_message(res, action):
stored_message.append(res)
def print_res(res, action):
print(res)
from multipEp import * from multipEp import *
#("instance name", [instance_action_func, [args], {kwargs}], result_func), #("instance name", [instance_action_func, [args], {kwargs}], result_func),
#(manager_action_func, [args], {kwargs}, result_func), #(manager_action_func, [args], {kwargs}, result_func),
scenario0 = [
def scenario0():
for action in [
("GroupA1", [create_account, ["some.one@some.where", "Some One"]]), ("GroupA1", [create_account, ["some.one@some.where", "Some One"]]),
("SoloA", [create_account, ["some.other@else.where", "Some Other"]]), ("SoloA", [create_account, ["some.other@else.where", "Some Other"]]),
# key exchange # key exchange
("SoloA", [send_message, ["some.other@else.where", "some.one@some.where", ("SoloA", [send_message, ["some.other@else.where",
"some.one@some.where",
"Hey Bro", "Heeeey Brooooo"]]), "Hey Bro", "Heeeey Brooooo"]]),
("GroupA1", [send_message, ["some.one@some.where", "some.other@else.where", ("GroupA1", [send_message, ["some.one@some.where",
"Yo Dude", "Yooooo Duuuude"]]), "some.other@else.where",
("SoloA", [encrypted_message, ["some.other@else.where", "Yo Dude", "Yooooo Duuuude"]])
] : yield action
enc_msg = yield ("SoloA", [encrypted_message, ["some.other@else.where",
"some.one@some.where", "some.one@some.where",
"read this", "this is a secret message"]], store_message), "read this", "this is a secret message"]])
("GroupA1", [decrypt_message, [stored_message]], expect([6])), for action in [
("GroupA1", [decrypt_message, [enc_msg]], expect(6)),
(flush_all_mails,), (flush_all_mails,),
("GroupA2", [create_account, ["some.one@some.where", "Some One"]]), ("GroupA2", [create_account, ["some.one@some.where", "Some One"]]),
(cycle_until_no_change, ["GroupA1", "GroupA2"], expect(4)), (cycle_until_no_change, ["GroupA1", "GroupA2"], expect(4)),
("GroupA2", [decrypt_message, [stored_message]], expect([6])), ("GroupA2", [decrypt_message, [enc_msg]], expect(6)),
("GroupA3", [create_account, ["some.one@some.where", "Some One"]]), ("GroupA3", [create_account, ["some.one@some.where", "Some One"]]),
(cycle_until_no_change, ["GroupA1", "GroupA2", "GroupA3"], expect(3)), (cycle_until_no_change, ["GroupA1", "GroupA2", "GroupA3"], expect(3)),
# force consume messages # force consume messages
# ("GroupA3", [None, None, None, -60*15]), # ("GroupA3", [None, None, None, -60*15]),
("GroupA3", [decrypt_message, [stored_message]], expect([6])) ("GroupA3", [decrypt_message, [enc_msg]], expect(6))
] ] : yield action
scenario1 = [
#("instance name", [func, [args], {kwargs}]),
("B", [send_message, ["some.other@else.where", "some.one@some.where", "Hey Bro", "Heeeey Brooooo"]]),
("A", [send_message, ["some.one@some.where", "some.other@else.where", "Hey Bro", "Heeeey Brooooo"]]),
]
if __name__ == "__main__": if __name__ == "__main__":
run_scenario(scenario0) run_scenario(scenario0)

20
test/multipEp.py

@ -57,19 +57,16 @@ def send_message(from_address, to_address, shortmsg, longmsg):
msg = _encrypted_message(from_address, to_address, shortmsg, longmsg) msg = _encrypted_message(from_address, to_address, shortmsg, longmsg)
_send_message(to_address, msg) _send_message(to_address, msg)
def decrypt_message(msgs): def decrypt_message(msgstr):
res = []
for msgstr in msgs:
msg = pEp.incoming_message(msgstr) msg = pEp.incoming_message(msgstr)
printi("--- decrypt()") printi("--- decrypt()")
msg.recv = int(time.time()) msg.recv = int(time.time())
printmsg(msg) printmsg(msg)
msg2, keys, rating, consumed, flags = msg.decrypt() msg2, keys, rating, consumed, flags = msg.decrypt()
res.append(rating)
printi("->-", rating, "->-") printi("->-", rating, "->-")
printmsg(msg2) printmsg(msg2)
printi("---") printi("---")
return res return rating
def printi(*args): def printi(*args):
global indent global indent
@ -109,7 +106,7 @@ def execute_order(order, handler):
printheader("DECRYPT messages") printheader("DECRYPT messages")
# decrypt every non-consumed message for all instance accounts # decrypt every non-consumed message for all instance accounts
for own_address in own_addresses: for own_address in own_addresses:
msgs_for_me = msgs_folders[own_address] msgs_for_me = msgs_folders.get(own_address, [])
for msgstr in msgs_for_me: for msgstr in msgs_for_me:
msg = pEp.incoming_message(msgstr) msg = pEp.incoming_message(msgstr)
printi("--- decrypt()") printi("--- decrypt()")
@ -206,6 +203,7 @@ def pEp_instance_run(iname, conn, _msgs_folders, _handshakes_seen, _handshakes_v
if order is None: if order is None:
break break
print(order)
res = execute_order(order, handler) res = execute_order(order, handler)
conn.send(res) conn.send(res)
@ -270,13 +268,17 @@ def run_scenario(scenario):
handshakes_seen = manager.list() handshakes_seen = manager.list()
handshakes_validated = manager.list() handshakes_validated = manager.list()
for action in scenario: sc = scenario()
try:
action = next(sc)
while True:
res = None res = None
output = None output = None
if len(action) > 1 and type(action[-1]) == types.FunctionType: if len(action) > 1 and type(action[-1]) == types.FunctionType:
output = action[-1] output = action[-1]
action = action[:-1] action = action[:-1]
print(action)
if type(action[0]) == str: if type(action[0]) == str:
res = run_instance_action(action) res = run_instance_action(action)
else: else:
@ -285,6 +287,10 @@ def run_scenario(scenario):
if output is not None: if output is not None:
output(res, action) output(res, action)
action = sc.send(res)
except StopIteration: pass
if "wait_for_debug" in sys.argv: if "wait_for_debug" in sys.argv:
input("#"*80 + "\n" + input("#"*80 + "\n" +
"Press ENTER to cleanup\n" + "Press ENTER to cleanup\n" +

Loading…
Cancel
Save