Browse Source

various enhancements in multiprocess test - to be continued

PYADPT-55
Edouard Tisserant 9 years ago
parent
commit
555c93691a
  1. 46
      test/mp_sync_test.py
  2. 35
      test/multipEp.py

46
test/mp_sync_test.py

@ -2,30 +2,52 @@
test for simplest keysync scenario : two device setting up same account test for simplest keysync scenario : two device setting up same account
Launch it with something like : Launch it with something like :
DYLD_LIBRARY_PATH=/Users/ed/lib/ PYTHONPATH=`pwd`/../build/lib.macosx-10.11-x86_64-3.4 python3.4 sync_test.py LC_ALL=en_US.UTF-8 \
DYLD_LIBRARY_PATH=/Users/ed/lib/ \
PYTHONPATH=`pwd`/../build/lib.macosx-10.11-x86_64-3.4 \
python3.4 mp_sync_test.py
""" """
import multipEp as mp stored_message = []
def store_message(res, action):
stored_message.append(res)
def print_res(res, action):
print(res)
from multipEp import *
#("instance name", [instance_action_func, [args], {kwargs}], result_func),
#(manager_action_func, [args], {kwargs}, result_func),
scenario0 = [ scenario0 = [
#("instance name", [func, [args], {kwargs}]), ("GroupA1", [create_account, ["some.one@some.where", "Some One"]]),
("A", [mp.create_account, ["some.one@some.where", "Some One"]]), ("SoloA", [create_account, ["some.other@else.where", "Some Other"]]),
("B", [mp.create_account, ["some.one@some.where", "Some One"]]), # key exchange
(mp.cycle_until_no_change, ["A", "B"]), ("SoloA", [send_message, ["some.other@else.where", "some.one@some.where",
("C", [mp.create_account, ["some.one@some.where", "Some One"]]), "Hey Bro", "Heeeey Brooooo"]]),
(mp.cycle_until_no_change, ["A", "B", "C"]), ("GroupA1", [send_message, ["some.one@some.where", "some.other@else.where",
"Yo Dude", "Yooooo Duuuude"]]),
("SoloA", [encrypted_message, ["some.other@else.where",
"some.one@some.where",
"read this", "this is a secret message"]], store_message),
(flush_all_mails,),
("GroupA2", [create_account, ["some.one@some.where", "Some One"]]),
(cycle_until_no_change, ["GroupA1", "GroupA2"], expect(4)),
("GroupA2", [decrypt_message, [stored_message]], print_res),
("GroupA3", [create_account, ["some.one@some.where", "Some One"]]),
(cycle_until_no_change, ["GroupA1", "GroupA2", "GroupA3"], expect(3)),
# force consume messages # force consume messages
("C", [None, None, None, -60*15]) ("GroupA3", [None, None, None, -60*15])
] ]
scenario1 = [ scenario1 = [
#("instance name", [func, [args], {kwargs}]), #("instance name", [func, [args], {kwargs}]),
("A", [mp.send_message, ["some.one@some.where", "some.other@else.where", "Hey Bro", "Heeeey Brooooo"]]), ("B", [send_message, ["some.other@else.where", "some.one@some.where", "Hey Bro", "Heeeey Brooooo"]]),
("B", [mp.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__":
mp.run_scenario(scenario0) run_scenario(scenario0)

35
test/multipEp.py

@ -39,13 +39,17 @@ def _send_message(address, msg):
msgs.append(str(msg)) msgs.append(str(msg))
msgs_folders[address] = msgs msgs_folders[address] = msgs
def flush_all_mails():
global msgs_folders
msgs_folders.clear()
def _encrypted_message(from_address, to_address, shortmsg, longmsg): def _encrypted_message(from_address, to_address, shortmsg, longmsg):
m = pEp.outgoing_message(Identity(from_address, from_address)) m = pEp.outgoing_message(pEp.Identity(from_address, from_address))
m.to = [pEp.Identity(to_address, to_address)] m.to = [pEp.Identity(to_address, to_address)]
m.shortmsg = shortmsg m.shortmsg = shortmsg
m.longmsg = longmsg m.longmsg = longmsg
m.encrypt() m.encrypt()
return msg return m
def encrypted_message(from_address, to_address, shortmsg, longmsg): def encrypted_message(from_address, to_address, shortmsg, longmsg):
return str(_encrypted_message(from_address, to_address, shortmsg, longmsg)) return str(_encrypted_message(from_address, to_address, shortmsg, longmsg))
@ -54,9 +58,19 @@ 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(msgstr): def decrypt_message(msgs):
msg = pEp.incoming_message(msgstr) res = []
msg2, keys, rating, consumed, flags = msg.decrypt() for msgstr in msgs:
msg = pEp.incoming_message(msgstr)
printi("--- decrypt()")
msg.recv = int(time.time())
printmsg(msg)
msg2, keys, rating, consumed, flags = msg.decrypt()
res.append(rating)
printi("->-", rating, "->-")
printmsg(msg2)
printi("---")
return res
def printi(*args): def printi(*args):
global indent global indent
@ -255,10 +269,10 @@ def run_scenario(scenario):
handshakes_seen = manager.list() handshakes_seen = manager.list()
handshakes_validated = manager.list() handshakes_validated = manager.list()
res = None
for action in scenario: for action in scenario:
res = None
output = None output = None
if 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]
@ -288,9 +302,14 @@ def cycle_until_no_change(*instancelist, maxcycles=20):
count += 1 count += 1
if dict(msgs_folders) == tmp: if dict(msgs_folders) == tmp:
return return count
if count >= maxcycles: if count >= maxcycles:
raise Exception("Too many cycles waiting for stability") raise Exception("Too many cycles waiting for stability")
def expect(expectation):
def _expect(res, action):
if(expectation != res):
raise Exception("Expected " + str(expectation) + ", got " + str(res))
return _expect

Loading…
Cancel
Save