Browse Source

tests : fixed instance restart. added test to check survival of group to restarts (failing)

PYADPT-55
Edouard Tisserant 9 years ago
parent
commit
883e4b61d2
  1. 45
      test/mp_sync_test.py
  2. 22
      test/multipEp.py

45
test/mp_sync_test.py

@ -65,15 +65,12 @@ def group_of_3_members():
for action in [ for action in [
("GroupA3", [create_account, ["first@group.a", "GroupA First"]]), ("GroupA3", [create_account, ["first@group.a", "GroupA First"]]),
(cycle_until_no_change, ["GroupA1", "GroupA2", "GroupA3"], expect(4)), (cycle_until_no_change, ["GroupA1", "GroupA2", "GroupA3"], expect(4)),
# force consume messages
# ("GroupA3", [None, None, None, -60*15]),
("GroupA3", [decrypt_message, [enc_msg]], expect(PEP_rating_reliable)) ("GroupA3", [decrypt_message, [enc_msg]], expect(PEP_rating_reliable))
] : yield action ] : yield action
return enc_msg return enc_msg
def keygen_in_a_group_of_3_members(): def new_address_peer_and_mail():
prev_enc_msg = yield from group_of_3_members()
for action in [ for action in [
("SoloB", [create_account, ["first@solo.b", "First SoloB"]]), ("SoloB", [create_account, ["first@solo.b", "First SoloB"]]),
("GroupA3", [create_account, ["second@group.a", "GroupA Second"]]), ("GroupA3", [create_account, ["second@group.a", "GroupA Second"]]),
@ -92,34 +89,35 @@ def keygen_in_a_group_of_3_members():
"second@group.a", "second@group.a",
"SoloB First to GroupA Second -- encrypted", "SoloB First to GroupA Second -- encrypted",
"SoloB First to GroupA Second -- long encrypted"]]) "SoloB First to GroupA Second -- long encrypted"]])
for action in [
return enc_msg
def keygen_in_a_group_of_3_members(pre_actions=[]):
yield from group_of_3_members()
enc_msg = yield from new_address_peer_and_mail()
for action in pre_actions + [
(cycle_until_no_change, ["GroupA1", "GroupA2", "GroupA3"], expect(1)), (cycle_until_no_change, ["GroupA1", "GroupA2", "GroupA3"], expect(1)),
(flush_all_mails,),
("GroupA1", [create_account, ["second@group.a", "GroupA Second"]]), ("GroupA1", [create_account, ["second@group.a", "GroupA Second"]]),
(flush_all_mails, expect(0)),
("GroupA2", [create_account, ["second@group.a", "GroupA Second"]]), ("GroupA2", [create_account, ["second@group.a", "GroupA Second"]]),
(flush_all_mails, expect(0)),
("GroupA2", [decrypt_message, [enc_msg]], expect(PEP_rating_reliable)), ("GroupA2", [decrypt_message, [enc_msg]], expect(PEP_rating_reliable)),
("GroupA1", [decrypt_message, [enc_msg]], expect(PEP_rating_reliable)), ("GroupA1", [decrypt_message, [enc_msg]], expect(PEP_rating_reliable)),
] : yield action ] : yield action
def group_suvives_restart():
yield from keygen_in_a_group_of_3_members([
(restart_instance, ["GroupA1"]),
(restart_instance, ["GroupA2"]),
(restart_instance, ["GroupA3"])
])
def nokey_in_a_group_of_3_members(): def nokey_in_a_group_of_3_members():
prev_enc_msg = yield from group_of_3_members() yield from group_of_3_members()
for action in [ enc_msg = yield from new_address_peer_and_mail()
("SoloB", [create_account, ["first@solo.b", "First SoloB"]]),
("GroupA3", [create_account, ["second@group.a", "GroupA Second"]]),
# key exchange
("SoloB", [send_message, ["first@solo.b",
"second@group.a",
"SoloB First to GroupA second",
"SoloB First to GroupA second -- long"]]),
("GroupA3", [send_message, ["second@group.a",
"first@solo.b",
"GroupA second to SoloB First",
"GroupA second to SoloB First"]]),
] : yield action
enc_msg = yield ("SoloB", [encrypted_message, ["first@solo.b",
"second@group.a",
"SoloB First to GroupA Second -- encrypted",
"SoloB First to GroupA Second -- long encrypted"]])
for action in [ for action in [
(flush_all_mails,), (flush_all_mails,),
("GroupA1", [create_account, ["second@group.a", "GroupA Second"]]), ("GroupA1", [create_account, ["second@group.a", "GroupA Second"]]),
@ -136,5 +134,6 @@ if __name__ == "__main__":
run_scenario(group_on_cannotdecrypt) run_scenario(group_on_cannotdecrypt)
run_scenario(group_of_3_members) run_scenario(group_of_3_members)
run_scenario(keygen_in_a_group_of_3_members) run_scenario(keygen_in_a_group_of_3_members)
# run_scenario(group_suvives_restart)
run_scenario(nokey_in_a_group_of_3_members) run_scenario(nokey_in_a_group_of_3_members)

22
test/multipEp.py

@ -5,6 +5,7 @@ import importlib
import tempfile import tempfile
import time import time
import types import types
import itertools
from copy import deepcopy from copy import deepcopy
from collections import OrderedDict from collections import OrderedDict
@ -58,7 +59,9 @@ def _send_message(address, msg):
def flush_all_mails(): def flush_all_mails():
global msgs_folders global msgs_folders
count = sum(map(len,msgs_folders.values()))
msgs_folders.clear() msgs_folders.clear()
return count
def _encrypted_message(from_address, to_address, shortmsg, longmsg): def _encrypted_message(from_address, to_address, shortmsg, longmsg):
m = pEp.outgoing_message(pEp.Identity(from_address, from_address)) m = pEp.outgoing_message(pEp.Identity(from_address, from_address))
@ -117,7 +120,7 @@ def printmsg(msg):
def execute_order(order, handler): def execute_order(order, handler):
global handshakes_pending, handshakes_to_accept, handshakes_seen global handshakes_pending, handshakes_to_accept, handshakes_seen
global handshakes_validated, msgs_folders global handshakes_validated, msgs_folders, own_addresses
func, args, kwargs, timeoff = order[0:] + [None, [], {}, 0][len(order):] func, args, kwargs, timeoff = order[0:] + [None, [], {}, 0][len(order):]
printheader("DECRYPT messages") printheader("DECRYPT messages")
@ -178,12 +181,13 @@ def execute_order(order, handler):
return res return res
def pEp_instance_run(iname, conn, _msgs_folders, _handshakes_seen, _handshakes_validated): def pEp_instance_run(iname, _own_addresses, conn, _msgs_folders, _handshakes_seen, _handshakes_validated):
global pEp, handler, own_addresses, i_name, msgs_folders global pEp, handler, own_addresses, i_name, msgs_folders
global handshakes_pending, handshakes_to_accept global handshakes_pending, handshakes_to_accept
global handshakes_seen, handshakes_validated global handshakes_seen, handshakes_validated
# assign instance globals # assign instance globals
own_addresses = _own_addresses
msgs_folders = _msgs_folders msgs_folders = _msgs_folders
handshakes_seen = _handshakes_seen handshakes_seen = _handshakes_seen
handshakes_validated = _handshakes_validated handshakes_validated = _handshakes_validated
@ -224,6 +228,8 @@ def pEp_instance_run(iname, conn, _msgs_folders, _handshakes_seen, _handshakes_v
conn.send(res) conn.send(res)
conn.send(own_addresses)
msgs_folders = None msgs_folders = None
def pEp_instance_main(iname, tmpdirname, *args): def pEp_instance_main(iname, tmpdirname, *args):
@ -233,7 +239,7 @@ def pEp_instance_main(iname, tmpdirname, *args):
pEp_instance_run(iname, *args) pEp_instance_run(iname, *args)
print(iname + " exiting") print(iname + " exiting")
def start_instance(iname, tmpdir=None): def start_instance(iname, tmpdir=None, instance_addresses = []):
global handshakes_seen, handshakes_validated, msgs_folders global handshakes_seen, handshakes_validated, msgs_folders
if tmpdir is None: if tmpdir is None:
@ -243,7 +249,8 @@ def start_instance(iname, tmpdir=None):
conn, child_conn = multiprocessing.Pipe() conn, child_conn = multiprocessing.Pipe()
proc = multiprocessing.Process( proc = multiprocessing.Process(
target=pEp_instance_main, target=pEp_instance_main,
args=(iname, tmpdirname, child_conn, msgs_folders, args=(iname, tmpdirname, instance_addresses,
child_conn, msgs_folders,
handshakes_seen, handshakes_validated)) handshakes_seen, handshakes_validated))
proc.start() proc.start()
@ -286,8 +293,9 @@ def stop_instance(iname):
proc, conn, tmpdir = instances.pop(iname) proc, conn, tmpdir = instances.pop(iname)
# tell process to terminate # tell process to terminate
conn.send(None) conn.send(None)
instance_addresses = conn.recv()
proc.join() proc.join()
return tmpdir return tmpdir, instance_addresses
def purge_instances(): def purge_instances():
global instances global instances
@ -295,8 +303,8 @@ def purge_instances():
stop_instance(iname) stop_instance(iname)
def restart_instance(iname): def restart_instance(iname):
tmpdir = stop_instance(iname) tmpdir, instance_addresses = stop_instance(iname)
start_instance(iname, tmpdir) instances[iname] = start_instance(iname, tmpdir, instance_addresses)
def run_instance_action(action): def run_instance_action(action):
iname, order = action iname, order = action

Loading…
Cancel
Save