diff options
Diffstat (limited to 'common/src')
3 files changed, 20 insertions, 12 deletions
diff --git a/common/src/leap/soledad/common/tests/test_couch_operations_atomicity.py b/common/src/leap/soledad/common/tests/test_couch_operations_atomicity.py index 32f676ad..3fe6441b 100644 --- a/common/src/leap/soledad/common/tests/test_couch_operations_atomicity.py +++ b/common/src/leap/soledad/common/tests/test_couch_operations_atomicity.py @@ -69,7 +69,7 @@ class CouchAtomicityTestCase(CouchDBTestCase, TestCaseWithServer): def _put_doc_side_effect(doc): self._doc_put = doc - return Soledad( + soledad = Soledad( user, passphrase, secrets_path=os.path.join(self.tempdir, prefix, secrets_path), @@ -79,6 +79,8 @@ class CouchAtomicityTestCase(CouchDBTestCase, TestCaseWithServer): cert_file=cert_file, auth_token=auth_token, shared_db=self.get_default_shared_mock(_put_doc_side_effect)) + self.addCleanup(soledad.close) + return soledad def make_app(self): self.request_state = CouchServerState(self._couch_url) diff --git a/common/src/leap/soledad/common/tests/test_server.py b/common/src/leap/soledad/common/tests/test_server.py index 3ed23184..bfb4a225 100644 --- a/common/src/leap/soledad/common/tests/test_server.py +++ b/common/src/leap/soledad/common/tests/test_server.py @@ -307,6 +307,9 @@ class EncryptedSyncTestCase( server = getattr(self, 'server', None) if server: server_address = getattr(self.server, 'server_address', None) + else: + host = self.port.getHost() + server_address = (host.host, host.port) if server_address: server_url = 'http://%s:%d' % (server_address) diff --git a/common/src/leap/soledad/common/tests/u1db_tests/__init__.py b/common/src/leap/soledad/common/tests/u1db_tests/__init__.py index 9efe7ebf..132c45e3 100644 --- a/common/src/leap/soledad/common/tests/u1db_tests/__init__.py +++ b/common/src/leap/soledad/common/tests/u1db_tests/__init__.py @@ -36,6 +36,9 @@ from StringIO import StringIO import testscenarios from twisted.trial import unittest +from twisted.web.server import Site +from twisted.web.wsgi import WSGIResource +from twisted.internet import reactor from u1db import ( errors, @@ -338,32 +341,32 @@ class TestCaseWithServer(TestCase): def setUp(self): super(TestCaseWithServer, self).setUp() - self.server = self.server_thread = None + self.server = self.server_thread = self.port = None def tearDown(self): if self.server is not None: self.server.shutdown() self.server_thread.join() self.server.server_close() + if self.port: + self.port.stopListening() super(TestCaseWithServer, self).tearDown() @property def url_scheme(self): - return self.server_def()[-1] + return 'http' def startServer(self): - server_def = self.server_def() - server_class, shutdown_meth, _ = server_def application = self.make_app() - self.server = server_class(('127.0.0.1', 0), application) - self.server_thread = threading.Thread(target=self.server.serve_forever, - kwargs=dict(poll_interval=0.01)) - self.server_thread.start() - self.addCleanup(self.server_thread.join) - self.addCleanup(getattr(self.server, shutdown_meth)) + resource = WSGIResource(reactor, reactor.getThreadPool(), application) + site = Site(resource) + self.port = reactor.listenTCP(0, site, interface='127.0.0.1') + host = self.port.getHost() + self.server_address = (host.host, host.port) + self.addCleanup(self.port.stopListening) def getURL(self, path=None): - host, port = self.server.server_address + host, port = self.server_address if path is None: path = '' return '%s://%s:%s/%s' % (self.url_scheme, host, port, path) |