Browse Source

various enhancements in multiprocess test - to be continued

master
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
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 = [
#("instance name", [func, [args], {kwargs}]),
("A", [mp.create_account, ["some.one@some.where", "Some One"]]),
("B", [mp.create_account, ["some.one@some.where", "Some One"]]),
(mp.cycle_until_no_change, ["A", "B"]),
("C", [mp.create_account, ["some.one@some.where", "Some One"]]),
(mp.cycle_until_no_change, ["A", "B", "C"]),
("GroupA1", [create_account, ["some.one@some.where", "Some One"]]),
("SoloA", [create_account, ["some.other@else.where", "Some Other"]]),
# key exchange
("SoloA", [send_message, ["some.other@else.where", "some.one@some.where",
"Hey Bro", "Heeeey Brooooo"]]),
("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
("C", [None, None, None, -60*15])
("GroupA3", [None, None, None, -60*15])
]
scenario1 = [
#("instance name", [func, [args], {kwargs}]),
("A", [mp.send_message, ["some.one@some.where", "some.other@else.where", "Hey Bro", "Heeeey Brooooo"]]),
("B", [mp.send_message, ["some.other@else.where", "some.one@some.where", "Hey Bro", "Heeeey Brooooo"]]),
("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__":
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_folders[address] = msgs
def flush_all_mails():
global msgs_folders
msgs_folders.clear()
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.shortmsg = shortmsg
m.longmsg = longmsg
m.encrypt()
return msg
return m
def 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)
_send_message(to_address, msg)
def decrypt_message(msgstr):
msg = pEp.incoming_message(msgstr)
msg2, keys, rating, consumed, flags = msg.decrypt()
def decrypt_message(msgs):
res = []
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):
global indent
@ -255,10 +269,10 @@ def run_scenario(scenario):
handshakes_seen = manager.list()
handshakes_validated = manager.list()
res = None
for action in scenario:
res = None
output = None
if type(action[-1]) == types.FunctionType:
if len(action) > 1 and type(action[-1]) == types.FunctionType:
output = action[-1]
action = action[:-1]
@ -288,9 +302,14 @@ def cycle_until_no_change(*instancelist, maxcycles=20):
count += 1
if dict(msgs_folders) == tmp:
return
return count
if count >= maxcycles:
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