From 883e4b61d23ef47d6a5fc06b3cd5c6affa948fda Mon Sep 17 00:00:00 2001 From: Edouard Tisserant Date: Wed, 19 Oct 2016 23:31:13 +0200 Subject: [PATCH] tests : fixed instance restart. added test to check survival of group to restarts (failing) --- test/mp_sync_test.py | 45 ++++++++++++++++++++++---------------------- test/multipEp.py | 22 +++++++++++++++------- 2 files changed, 37 insertions(+), 30 deletions(-) diff --git a/test/mp_sync_test.py b/test/mp_sync_test.py index 1e80511..2ad0361 100644 --- a/test/mp_sync_test.py +++ b/test/mp_sync_test.py @@ -65,15 +65,12 @@ def group_of_3_members(): for action in [ ("GroupA3", [create_account, ["first@group.a", "GroupA First"]]), (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)) ] : yield action return enc_msg -def keygen_in_a_group_of_3_members(): - prev_enc_msg = yield from group_of_3_members() +def new_address_peer_and_mail(): for action in [ ("SoloB", [create_account, ["first@solo.b", "First SoloB"]]), ("GroupA3", [create_account, ["second@group.a", "GroupA Second"]]), @@ -92,34 +89,35 @@ def keygen_in_a_group_of_3_members(): "second@group.a", "SoloB First to GroupA Second -- 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)), + (flush_all_mails,), ("GroupA1", [create_account, ["second@group.a", "GroupA Second"]]), + (flush_all_mails, expect(0)), ("GroupA2", [create_account, ["second@group.a", "GroupA Second"]]), + (flush_all_mails, expect(0)), ("GroupA2", [decrypt_message, [enc_msg]], expect(PEP_rating_reliable)), ("GroupA1", [decrypt_message, [enc_msg]], expect(PEP_rating_reliable)), ] : 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(): - prev_enc_msg = yield from group_of_3_members() - for action in [ - ("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 + yield from group_of_3_members() + enc_msg = yield from new_address_peer_and_mail() - 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 [ (flush_all_mails,), ("GroupA1", [create_account, ["second@group.a", "GroupA Second"]]), @@ -136,5 +134,6 @@ if __name__ == "__main__": run_scenario(group_on_cannotdecrypt) run_scenario(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) diff --git a/test/multipEp.py b/test/multipEp.py index 4bcd6fb..a9a439e 100644 --- a/test/multipEp.py +++ b/test/multipEp.py @@ -5,6 +5,7 @@ import importlib import tempfile import time import types +import itertools from copy import deepcopy from collections import OrderedDict @@ -58,7 +59,9 @@ def _send_message(address, msg): def flush_all_mails(): global msgs_folders + count = sum(map(len,msgs_folders.values())) msgs_folders.clear() + return count def _encrypted_message(from_address, to_address, shortmsg, longmsg): m = pEp.outgoing_message(pEp.Identity(from_address, from_address)) @@ -117,7 +120,7 @@ def printmsg(msg): def execute_order(order, handler): 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):] printheader("DECRYPT messages") @@ -178,12 +181,13 @@ def execute_order(order, handler): 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 handshakes_pending, handshakes_to_accept global handshakes_seen, handshakes_validated # assign instance globals + own_addresses = _own_addresses msgs_folders = _msgs_folders handshakes_seen = _handshakes_seen 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(own_addresses) + msgs_folders = None def pEp_instance_main(iname, tmpdirname, *args): @@ -233,7 +239,7 @@ def pEp_instance_main(iname, tmpdirname, *args): pEp_instance_run(iname, *args) print(iname + " exiting") -def start_instance(iname, tmpdir=None): +def start_instance(iname, tmpdir=None, instance_addresses = []): global handshakes_seen, handshakes_validated, msgs_folders if tmpdir is None: @@ -243,7 +249,8 @@ def start_instance(iname, tmpdir=None): conn, child_conn = multiprocessing.Pipe() proc = multiprocessing.Process( target=pEp_instance_main, - args=(iname, tmpdirname, child_conn, msgs_folders, + args=(iname, tmpdirname, instance_addresses, + child_conn, msgs_folders, handshakes_seen, handshakes_validated)) proc.start() @@ -286,8 +293,9 @@ def stop_instance(iname): proc, conn, tmpdir = instances.pop(iname) # tell process to terminate conn.send(None) + instance_addresses = conn.recv() proc.join() - return tmpdir + return tmpdir, instance_addresses def purge_instances(): global instances @@ -295,8 +303,8 @@ def purge_instances(): stop_instance(iname) def restart_instance(iname): - tmpdir = stop_instance(iname) - start_instance(iname, tmpdir) + tmpdir, instance_addresses = stop_instance(iname) + instances[iname] = start_instance(iname, tmpdir, instance_addresses) def run_instance_action(action): iname, order = action