test_php_application.py (2053:83a2f582bc2a) test_php_application.py (2054:357dee5c1861)
1import getpass
1import os
2import re
3import shutil
4import signal
5import time
6
7import pytest
8from unit.applications.lang.php import TestApplicationPHP

--- 4 unchanged lines hidden (view full) ---

13 prerequisites = {'modules': {'php': 'all'}}
14
15 def before_disable_functions(self):
16 body = self.get()['body']
17
18 assert re.search(r'time: \d+', body), 'disable_functions before time'
19 assert re.search(r'exec: \/\w+', body), 'disable_functions before exec'
20
2import os
3import re
4import shutil
5import signal
6import time
7
8import pytest
9from unit.applications.lang.php import TestApplicationPHP

--- 4 unchanged lines hidden (view full) ---

14 prerequisites = {'modules': {'php': 'all'}}
15
16 def before_disable_functions(self):
17 body = self.get()['body']
18
19 assert re.search(r'time: \d+', body), 'disable_functions before time'
20 assert re.search(r'exec: \/\w+', body), 'disable_functions before exec'
21
22 def check_opcache(self):
23 resp = self.get()
24 assert resp['status'] == 200, 'status'
25
26 headers = resp['headers']
27 if 'X-OPcache' in headers and headers['X-OPcache'] == '-1':
28 pytest.skip('opcache is not supported')
29
30 return resp
31
21 def set_opcache(self, app, val):
22 assert 'success' in self.conf(
23 {"admin": {"opcache.enable": val, "opcache.enable_cli": val}},
24 'applications/' + app + '/options',
25 )
26
32 def set_opcache(self, app, val):
33 assert 'success' in self.conf(
34 {"admin": {"opcache.enable": val, "opcache.enable_cli": val}},
35 'applications/' + app + '/options',
36 )
37
27 opcache = self.get()['headers']['X-OPcache']
38 r = self.check_opcache()
39 assert r['headers']['X-OPcache'] == val, 'opcache value'
28
40
29 if not opcache or opcache == '-1':
30 pytest.skip('opcache is not supported')
41 def set_preload(self, preload):
42 with open(option.temp_dir + '/php.ini', 'w') as f:
43 f.write(
44 """opcache.preload = %(test_dir)s/php/opcache/preload\
45/%(preload)s
46opcache.preload_user = %(user)s
47"""
48 % {
49 'test_dir': option.test_dir,
50 'preload': preload,
51 'user': option.user or getpass.getuser(),
52 }
53 )
31
54
32 assert opcache == val, 'opcache value'
55 assert 'success' in self.conf(
56 {"file": option.temp_dir + "/php.ini"},
57 'applications/opcache/options',
58 )
33
34 def test_php_application_variables(self):
35 self.load('variables')
36
37 body = 'Test body string.'
38
39 resp = self.post(
40 headers={

--- 679 unchanged lines hidden (view full) ---

720 self.get(url='/?chdir=/')['body'] != 'test'
721 ), 'relative path w/ chdir'
722
723 assert self.get()['body'] == 'test', 'relative path 2'
724
725 def test_php_application_shared_opcache(self):
726 self.load('opcache', limits={'requests': 1})
727
59
60 def test_php_application_variables(self):
61 self.load('variables')
62
63 body = 'Test body string.'
64
65 resp = self.post(
66 headers={

--- 679 unchanged lines hidden (view full) ---

746 self.get(url='/?chdir=/')['body'] != 'test'
747 ), 'relative path w/ chdir'
748
749 assert self.get()['body'] == 'test', 'relative path 2'
750
751 def test_php_application_shared_opcache(self):
752 self.load('opcache', limits={'requests': 1})
753
728 r = self.get()
729 cached = r['headers']['X-Cached']
730 if cached == '-1':
731 pytest.skip('opcache is not supported')
732
754 r = self.check_opcache()
733 pid = r['headers']['X-Pid']
755 pid = r['headers']['X-Pid']
756 assert r['headers']['X-Cached'] == '0', 'not cached'
734
757
735 assert cached == '0', 'not cached'
736
737 r = self.get()
738
739 assert r['headers']['X-Pid'] != pid, 'new instance'
740 assert r['headers']['X-Cached'] == '1', 'cached'
758 r = self.get()
759
760 assert r['headers']['X-Pid'] != pid, 'new instance'
761 assert r['headers']['X-Cached'] == '1', 'cached'
762
763 def test_php_application_opcache_preload_chdir(self, temp_dir):
764 self.load('opcache')
765
766 self.check_opcache()
767
768 self.set_preload('chdir.php')
769
770 assert self.get()['headers']['X-Cached'] == '0', 'not cached'
771 assert self.get()['headers']['X-Cached'] == '1', 'cached'
772
773 def test_php_application_opcache_preload_ffr(self, temp_dir):
774 self.load('opcache')
775
776 self.check_opcache()
777
778 self.set_preload('fastcgi_finish_request.php')
779
780 assert self.get()['headers']['X-Cached'] == '0', 'not cached'
781 assert self.get()['headers']['X-Cached'] == '1', 'cached'