Browse Source

multithreaded implementation as an alternative

master
Volker Birk 6 years ago
parent
commit
f078dee720
  1. 12
      src/pEpmodule.cc
  2. 1
      src/pEpmodule.hh
  3. 15
      test/sync_handshake.py
  4. 15
      test/sync_test.py

12
src/pEpmodule.cc

@ -103,6 +103,11 @@ namespace pEp {
void messageToSend(Message msg) {
throw runtime_error("implement pEp.messageToSend(msg)");
}
void do_sync_protocol()
{
::do_sync_protocol(adapter.session(), nullptr);
}
}
}
@ -490,6 +495,13 @@ BOOST_PYTHON_MODULE(pEp)
"call to deliver the handshake result of the handshake dialog")
;
def("do_sync_protocol", &pEp::PythonAdapter::do_sync_protocol,
"do_sync_protocol()\n"
"\n"
"in case of an explicit sync thread instead of a single threaded\n"
"implementation call this function in your sync thread\n"
);
// codecs
call< object >(((object)(import("codecs").attr("register"))).ptr(), make_function(sync_search));

1
src/pEpmodule.hh

@ -16,6 +16,7 @@ namespace pEp {
void _throw_status(PEP_STATUS status);
void messageToSend(Message msg);
PEP_STATUS _messageToSend(::message *msg);
void do_sync_protocol();
extern Adapter adapter;
}
}

15
test/sync_handshake.py

@ -41,6 +41,7 @@ except:
inbox = pathlib.Path("..") / "TestInbox"
device_name = ""
output = print
multithreaded = False
DONT_TRIGGER_SYNC = 0x200
SYNC_HANDSHAKE_ACCEPTED = 0
@ -131,6 +132,16 @@ def run(name, color=None):
me = pEp.Identity("alice@peptest.ch", name + " of Alice Neuman", name)
pEp.myself(me)
pEp.messageToSend = messageToSend
if multithreaded:
from threading import Thread
def sync_thread():
ui = UserInterface()
pEp.do_sync_protocol()
ui_thread = Thread(target=sync_thread)
ui_thread.start()
else:
ui_thread = None
ui = UserInterface()
try:
@ -163,6 +174,9 @@ if __name__=="__main__":
help="accept device group (default)")
optParser.add_option("-E", "--end-on", dest="notifications",
help="end test on these notifications")
optParser.add_option("-j", "--multi-threaded", action="store_true",
dest="multithreaded",
help="use multithreaded instead of single threaded implementation")
options, args = optParser.parse_args()
if not options.exec_for:
@ -174,5 +188,6 @@ if __name__=="__main__":
except TypeError:
end_on = (end_on,)
multithreaded = options.multithreaded
run(options.exec_for, options.color)

15
test/sync_test.py

@ -20,7 +20,7 @@ import shutil
import pathlib
def test_for(path, color=None, end_on=None):
def test_for(path, color=None, end_on=None, mt=False):
cwd = os.getcwd();
os.chdir(path)
os.environ["HOME"] = os.getcwd()
@ -29,6 +29,7 @@ def test_for(path, color=None, end_on=None):
import sync_handshake
if end_on:
sync_handshake.end_on = end_on
sync_handshake.multithreaded = mt
sync_handshake.run(path, color)
os.chdir(cwd)
@ -91,6 +92,9 @@ if __name__ == "__main__":
help="end test on these notifications")
optParser.add_option("-3", "--third-device", action="store_true", dest="third",
help="start Pad as third device")
optParser.add_option("-j", "--multi-threaded", action="store_true",
dest="multithreaded",
help="use multithreaded instead of single threaded implementation")
options, args = optParser.parse_args()
if options.cleanall:
@ -154,10 +158,13 @@ if __name__ == "__main__":
try: None in end_on
except TypeError:
end_on = (end_on,)
Phone = Process(target=test_for, args=("Phone", "red", end_on))
Laptop = Process(target=test_for, args=("Laptop", "green", end_on))
Phone = Process(target=test_for, args=("Phone", "red", end_on,
options.multithreaded))
Laptop = Process(target=test_for, args=("Laptop", "green", end_on,
options.multithreaded))
if options.third:
Pad = Process(target=test_for, args=("Pad", "cyan", end_on))
Pad = Process(target=test_for, args=("Pad", "cyan", end_on,
options.multithreaded))
Phone.start()
Laptop.start()

Loading…
Cancel
Save