2
0
mirror of https://github.com/frappe/bench.git synced 2024-11-11 15:51:03 +00:00

[Minor] Add extra test case for checking ports

* Added routine to find the max_cpus on the machine to start appropriate number of workers
* Modified supervisor.conf to get webserver_port for multi-bench setup
This commit is contained in:
shreyas 2016-02-24 22:33:52 +05:30 committed by Anand Doshi
parent 68dc8cbfd4
commit a12cffacca
4 changed files with 41 additions and 12 deletions

View File

@ -41,7 +41,9 @@ def generate_supervisor_config(bench='.', user=None):
"node": find_executable('node') or find_executable('nodejs'),
"redis_cache_config": os.path.join(bench_dir, 'config', 'redis_cache.conf'),
"redis_async_broker_config": os.path.join(bench_dir, 'config', 'redis_async_broker.conf'),
"frappe_version": get_current_frappe_version()
"frappe_version": get_current_frappe_version(),
"webserver_port": config.get('webserver_port'),
"n_workers": config.get('max_workers')
})
write_config_file(bench, 'supervisor.conf', config)
update_config({'restart_supervisor_on_update': True})

View File

@ -3,7 +3,7 @@
; killasgroup=true --> send kill signal to child processes too
[program:frappe-web]
command={{ bench_dir }}/env/bin/gunicorn -b 127.0.0.1:8000 -w 2 -t {{http_timeout}} frappe.app:application
command={{ bench_dir }}/env/bin/gunicorn -b 127.0.0.1:{{webserver_port}} -w {{n_workers}} -t {{http_timeout}} frappe.app:application
priority=4
autostart=true
autorestart=true

View File

@ -5,6 +5,7 @@ import bench.utils
import json
import os
import shutil
import socket
class TestBenchInit(unittest.TestCase):
def setUp(self):
@ -22,9 +23,6 @@ class TestBenchInit(unittest.TestCase):
bench.utils.init(bench_name)
# logging
self.assert_exists(bench_name, "logs", "bench.log")
self.assert_folders(bench_name)
self.assert_virtual_env(bench_name)
@ -37,10 +35,24 @@ class TestBenchInit(unittest.TestCase):
def test_multiple_benches(self):
self.test_init("test-bench-1")
self.assert_ports("test-bench-1")
test_bench_1_ports = {
"webserver_port": 8000,
"socketio_port": 9000,
"redis_celery_broker_port": 11000,
"redis_async_broker_port": 12000,
"redis_cache_port": 13000
}
self.assert_ports("test-bench-1", test_bench_1_ports)
self.test_init("test-bench-2")
self.assert_ports("test-bench-2")
test_bench_2_ports = {
"webserver_port": 8001,
"socketio_port": 9001,
"redis_celery_broker_port": 11001,
"redis_async_broker_port": 12001,
"redis_cache_port": 13001
}
self.assert_ports("test-bench-2", test_bench_2_ports)
def assert_folders(self, bench_name):
for folder in bench.utils.folders_in_bench:
@ -61,6 +73,7 @@ class TestBenchInit(unittest.TestCase):
config_json = os.path.exists(os.path.join(bench_name, "config.json"))
self.assertTrue(config_json)
with open(config_json, "r") as f:
print f
config_dict = json.loads(f.read().decode("utf-8"))
for key, value in bench.utils.default_config.items():
self.assertEquals(config_dict.get(key), value)
@ -81,9 +94,14 @@ class TestBenchInit(unittest.TestCase):
self.assert_exists(bench_name, "node_modules")
self.assert_exists(bench_name, "node_modules", "socket.io")
def assert_ports(self, bench_name):
pass
def assert_ports(self, bench_name, ports):
config_path = os.path.join(self.benches_path, bench_name, 'config', 'config.json')
with open(config_path, "r") as f:
config_json = json.load(f)
for key, port in ports:
self.assertEqual(config_json.get(key), port)
def assert_exists(self, *args):
self.assert_exists(*args)
self.assertTrue(os.path.exists(os.path.join(*args)))

View File

@ -30,7 +30,7 @@ default_config = {
'rebase_on_pull': False,
'update_bench_on_update': True,
'frappe_user': getpass.getuser(),
'shallow_clone': True
'shallow_clone': True,
}
folders_in_bench = ('apps', 'sites', 'config', 'logs', 'config/files')
@ -95,8 +95,17 @@ def make_bench_config():
bench_config = {}
bench_config.update(default_config)
bench_config.update(make_ports())
bench_config.update(get_max_worker_count())
return bench_config
def get_max_worker_count():
'''This function will return the maximum workers that can be started depending upon'''
'''number of cpu's present on the machine'''
n_cpus = multiprocessing.cpu_count()
return dict(max_workers=2 * n_cpus)
def make_ports(benches_path="."):
default_ports = {
"webserver_port": 8000,