Browse Source

test: moved some code around to prepare for test including instances restart

PYADPT-55
Edouard Tisserant 9 years ago
parent
commit
210d4089a3
  1. 52
      test/multipEp.py

52
test/multipEp.py

@ -226,26 +226,27 @@ def pEp_instance_run(iname, conn, _msgs_folders, _handshakes_seen, _handshakes_v
msgs_folders = None
def pEp_instance_main(iname, *args):
def pEp_instance_main(iname, tmpdirname, *args):
# run with a dispensable $HOME to get fresh DB and PGP keyrings
with tempfile.TemporaryDirectory() as tmpdirname:
print("Instance " + iname + " runs into " + tmpdirname)
os.environ['HOME'] = tmpdirname
pEp_instance_run(iname, *args)
print(iname + " exiting")
def run_instance_action(action):
def start_instance(iname, tmpdir=None):
global handshakes_seen, handshakes_validated, msgs_folders
global instances
iname, order = action
if iname not in instances:
if tmpdir is None:
tmpdir = tempfile.TemporaryDirectory()
tmpdirname = tmpdir.name
conn, child_conn = multiprocessing.Pipe()
proc = multiprocessing.Process(
target=pEp_instance_main,
args=(iname, child_conn, msgs_folders,
args=(iname, tmpdirname, child_conn, msgs_folders,
handshakes_seen, handshakes_validated))
proc.start()
instances[iname] = (proc, conn)
debug = False
if "debug_"+iname in sys.argv :
debug = True
@ -269,18 +270,39 @@ def run_instance_action(action):
import appscript
appscript.app('Terminal').do_script('lldb -p ' + str(proc.pid))
time.sleep(2)
else:
proc, conn = instances[iname]
conn.send(order)
return conn.recv()
return (proc, conn, tmpdir)
def purge_instance():
def get_instance(iname):
global instances
for iname, (proc, conn) in instances.items():
if iname not in instances:
res = start_instance(iname)
instances[iname] = res
return res
else:
return instances[iname]
def stop_instance(iname):
proc, conn, tmpdir = instances.pop(iname)
# tell process to terminate
conn.send(None)
proc.join()
return tmpdir
def purge_instances():
global instances
for iname in instances.keys():
stop_instance(iname)
def restart_instance(iname):
tmpdir = stop_instance(iname)
start_instance(iname, tmpdir)
def run_instance_action(action):
iname, order = action
proc, conn, tmpdir = get_instance(iname)
conn.send(order)
return conn.recv()
def run_manager_action(action):
func, args, kwargs = action[0:] + (None, [], {})[len(action):]
@ -320,7 +342,7 @@ def run_scenario(scenario):
"Press ENTER to cleanup\n" +
"#"*80 + "\n")
purge_instance()
purge_instances()
def cycle_until_no_change(*instancelist, maxcycles=20):
count = 0

Loading…
Cancel
Save