1import getpass
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
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'
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 )
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 )
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()
755 pid = r['headers']['X-Pid']
756 assert r['headers']['X-Cached'] == '0', 'not cached'
757
735 assert cached == '0', 'not cached'
736
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'