diff options
author | drebs <drebs@leap.se> | 2014-09-08 17:12:45 -0300 |
---|---|---|
committer | drebs <drebs@leap.se> | 2014-09-10 10:13:58 -0300 |
commit | 2f1ee76a7169abc100efdf706f12a0abf6032f04 (patch) | |
tree | 2b4413b685a06abbf939cb270e5f0d3e7c29e154 /scripts/profiling/mail/soledad_server.py | |
parent | 3ab68fd26bae17c82dbbb0c0171933b8a7540c73 (diff) |
Add benchmarking scripts.
Diffstat (limited to 'scripts/profiling/mail/soledad_server.py')
-rw-r--r-- | scripts/profiling/mail/soledad_server.py | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/scripts/profiling/mail/soledad_server.py b/scripts/profiling/mail/soledad_server.py new file mode 100644 index 00000000..ad014456 --- /dev/null +++ b/scripts/profiling/mail/soledad_server.py @@ -0,0 +1,48 @@ +import threading + +from wsgiref.simple_server import make_server + +from leap.soledad.common.couch import CouchServerState + +from leap.soledad.server import SoledadApp +from leap.soledad.server.gzip_middleware import GzipMiddleware +from leap.soledad.server.auth import SoledadTokenAuthMiddleware + +from util import log + + +class SoledadServerThread(threading.Thread): + def __init__(self, server): + threading.Thread.__init__(self) + self._server = server + + def run(self): + self._server.serve_forever() + + def stop(self): + self._server.shutdown() + + @property + def port(self): + return self._server.server_port + + +def make_soledad_server_thread(couch_port): + state = CouchServerState( + 'http://127.0.0.1:%d' % couch_port, + 'shared', + 'tokens') + application = GzipMiddleware( + SoledadTokenAuthMiddleware(SoledadApp(state))) + server = make_server('', 0, application) + t = SoledadServerThread(server) + return t + + +def get_soledad_server(couchdb_port): + log("Starting soledad server... ", line_break=False) + soledad_server = make_soledad_server_thread(couchdb_port) + soledad_server.start() + log("soledad server started on port %d." % soledad_server.port) + return soledad_server + |