From eedb963cf7df614b4f811da4a661e982d89e63bd Mon Sep 17 00:00:00 2001 From: Duda Dornelles Date: Fri, 21 Nov 2014 14:45:46 -0200 Subject: refactoring so the app_test_client knows how to start itself in a thread --- service/test/functional/features/environment.py | 15 +++++---------- service/test/support/integration/app_test_client.py | 9 +++++++++ 2 files changed, 14 insertions(+), 10 deletions(-) (limited to 'service') diff --git a/service/test/functional/features/environment.py b/service/test/functional/features/environment.py index 537cd969..4c9af63e 100644 --- a/service/test/functional/features/environment.py +++ b/service/test/functional/features/environment.py @@ -18,25 +18,20 @@ import multiprocessing import logging from test.support.integration import AppTestClient from selenium import webdriver +from pixelated.controllers.features_controller import FeaturesController import pixelated def before_all(context): - pixelated.controllers.features_controller.FeaturesController.DISABLED_FEATURES.append('autoRefresh') + logging.disable('INFO') client = AppTestClient() + FeaturesController.DISABLED_FEATURES.append('autoRefresh') context.client = client - logging.disable('INFO') - - worker = lambda: client.app.run(host='localhost', port=4567, logFile=open('/tmp/behave-tests.log', 'w')) - context._process = multiprocessing.Process(target=worker) - context._process.start() - - # we must wait the server start listening - time.sleep(1) + context.call_to_terminate = client.run_on_a_thread(logfile='/tmp/behave-tests.log') def after_all(context): - context._process.terminate() + context.call_to_terminate() def before_feature(context, feature): diff --git a/service/test/support/integration/app_test_client.py b/service/test/support/integration/app_test_client.py index f6a95422..dea59399 100644 --- a/service/test/support/integration/app_test_client.py +++ b/service/test/support/integration/app_test_client.py @@ -14,7 +14,9 @@ # You should have received a copy of the GNU Affero General Public License # along with Pixelated. If not, see . import json +import multiprocessing import shutil +import time from klein.test_resource import requestMock, _render from leap.mail.imap.account import SoledadBackedAccount @@ -87,6 +89,13 @@ class AppTestClient: d.addCallback(get_request_written_data) return d, request + def run_on_a_thread(self, logfile='/tmp/app_test_client.log', port=4567, host='localhost'): + worker = lambda: self.app.run(host=host, port=port, logFile=open(logfile, 'w')) + process = multiprocessing.Process(target=worker) + process.start() + time.sleep(1) # just let it start + return lambda: process.terminate() + def get(self, path, get_args, as_json=True): request = requestMock(path) request.args = get_args -- cgit v1.2.3