test_python_procman.py (550:ce9e85f49c02) test_python_procman.py (552:2e4ea9cc507e)
1import re
2import time
3import subprocess
4import unittest
5import unit
6
1import re
2import time
3import subprocess
4import unittest
5import unit
6
7class TestUnitPythonProcman(unit.TestUnitControl):
7class TestUnitPythonProcman(unit.TestUnitApplicationPython):
8
9 def setUpClass():
10 unit.TestUnit().check_modules('python')
11
8
9 def setUpClass():
10 unit.TestUnit().check_modules('python')
11
12 def pids_for_process(self, process=None):
13 if process is None:
14 process = self.app_name
15
12 def pids_for_process(self):
16 time.sleep(0.2)
17
18 output = subprocess.check_output(['ps', 'ax'])
19
20 pids = set()
13 time.sleep(0.2)
14
15 output = subprocess.check_output(['ps', 'ax'])
16
17 pids = set()
21 for m in re.findall('.*' + process, output.decode()):
18 for m in re.findall('.*' + self.app_name, output.decode()):
22 pids.add(re.search('^\s*(\d+)', m).group(1))
23
24 return pids
25
26 def setUp(self):
27 super().setUp()
28
19 pids.add(re.search('^\s*(\d+)', m).group(1))
20
21 return pids
22
23 def setUp(self):
24 super().setUp()
25
29 code, name = """
30
31def application(env, start_response):
32 start_response('200', [('Content-Length', '0')])
33 return []
34
35""", 'py_app'
36
37 self.app_name = "app-" + self.testdir.split('/')[-1]
26 self.app_name = "app-" + self.testdir.split('/')[-1]
27 self.load('empty', self.app_name)
38
28
39 self.python_application(name, code)
40
41 self.conf({
42 "listeners": {
43 "*:7080": {
44 "application": self.app_name
45 }
46 },
47 "applications": {
48 self.app_name: {
49 "type": "python",
50 "processes": { "spare": 0 },
51 "path": self.testdir + '/' + name,
52 "module": "wsgi"
53 }
54 }
55 })
56
57 def test_python_processes_access(self):
58 self.conf('1', '/applications/' + self.app_name + '/processes')
59
60 self.assertIn('error', self.conf_get('/applications/' + self.app_name +
61 '/processes/max'), 'max no access')
62 self.assertIn('error', self.conf_get('/applications/' + self.app_name +
63 '/processes/spare'), 'spare no access')
64 self.assertIn('error', self.conf_get('/applications/' + self.app_name +

--- 196 unchanged lines hidden ---
29 def test_python_processes_access(self):
30 self.conf('1', '/applications/' + self.app_name + '/processes')
31
32 self.assertIn('error', self.conf_get('/applications/' + self.app_name +
33 '/processes/max'), 'max no access')
34 self.assertIn('error', self.conf_get('/applications/' + self.app_name +
35 '/processes/spare'), 'spare no access')
36 self.assertIn('error', self.conf_get('/applications/' + self.app_name +

--- 196 unchanged lines hidden ---