diff options
author | Konstantin Pavlov <thresh@nginx.com> | 2022-06-02 16:51:49 +0400 |
---|---|---|
committer | Konstantin Pavlov <thresh@nginx.com> | 2022-06-02 16:51:49 +0400 |
commit | d9fddee1dbfc1f5d49c8f40386289d7188030952 (patch) | |
tree | 842a62b343ac33eba10e7a426a10b55bb1c46aed /test/test_php_application.py | |
parent | 420395ee2e7cd464e157c49bea3d74f15bf25f30 (diff) | |
parent | 0d48fe73c4450901622373e35f6ff3a944ec13d6 (diff) | |
download | unit-d9fddee1dbfc1f5d49c8f40386289d7188030952.tar.gz unit-d9fddee1dbfc1f5d49c8f40386289d7188030952.tar.bz2 |
Merged with the default branch.1.27.0-1
Diffstat (limited to 'test/test_php_application.py')
-rw-r--r-- | test/test_php_application.py | 94 |
1 files changed, 70 insertions, 24 deletions
diff --git a/test/test_php_application.py b/test/test_php_application.py index d9c16a6d..606ac723 100644 --- a/test/test_php_application.py +++ b/test/test_php_application.py @@ -1,3 +1,4 @@ +import getpass import os import re import shutil @@ -18,18 +19,43 @@ class TestPHPApplication(TestApplicationPHP): assert re.search(r'time: \d+', body), 'disable_functions before time' assert re.search(r'exec: \/\w+', body), 'disable_functions before exec' + def check_opcache(self): + resp = self.get() + assert resp['status'] == 200, 'status' + + headers = resp['headers'] + if 'X-OPcache' in headers and headers['X-OPcache'] == '-1': + pytest.skip('opcache is not supported') + + return resp + def set_opcache(self, app, val): assert 'success' in self.conf( {"admin": {"opcache.enable": val, "opcache.enable_cli": val}}, 'applications/' + app + '/options', ) - opcache = self.get()['headers']['X-OPcache'] - - if not opcache or opcache == '-1': - pytest.skip('opcache is not supported') + r = self.check_opcache() + assert r['headers']['X-OPcache'] == val, 'opcache value' + + def set_preload(self, preload): + with open(option.temp_dir + '/php.ini', 'w') as f: + f.write( + """opcache.preload = %(test_dir)s/php/opcache/preload\ +/%(preload)s +opcache.preload_user = %(user)s +""" + % { + 'test_dir': option.test_dir, + 'preload': preload, + 'user': option.user or getpass.getuser(), + } + ) - assert opcache == val, 'opcache value' + assert 'success' in self.conf( + {"file": option.temp_dir + "/php.ini"}, + 'applications/opcache/options', + ) def test_php_application_variables(self): self.load('variables') @@ -294,20 +320,28 @@ class TestPHPApplication(TestApplicationPHP): self.load('ini_precision') assert 'success' in self.conf( - {"file": "php.ini", "admin": {"precision": "5"}}, + {"file": "ini/php.ini", "admin": {"precision": "5"}}, 'applications/ini_precision/options', ) + assert ( + self.get()['headers']['X-File'] + == option.test_dir + '/php/ini_precision/ini/php.ini' + ), 'ini file' assert self.get()['headers']['X-Precision'] == '5', 'ini value admin' def test_php_application_ini_user(self): self.load('ini_precision') assert 'success' in self.conf( - {"file": "php.ini", "user": {"precision": "5"}}, + {"file": "ini/php.ini", "user": {"precision": "5"}}, 'applications/ini_precision/options', ) + assert ( + self.get()['headers']['X-File'] + == option.test_dir + '/php/ini_precision/ini/php.ini' + ), 'ini file' assert self.get()['headers']['X-Precision'] == '5', 'ini value user' def test_php_application_ini_user_2(self): @@ -385,9 +419,7 @@ class TestPHPApplication(TestApplicationPHP): body = self.get()['body'] - assert not re.search( - r'time: \d+', body - ), 'disable_functions comma time' + assert not re.search(r'time: \d+', body), 'disable_functions comma time' assert not re.search( r'exec: \/\w+', body ), 'disable_functions comma exec' @@ -464,9 +496,7 @@ class TestPHPApplication(TestApplicationPHP): body = self.get()['body'] - assert not re.search( - r'time: \d+', body - ), 'disable_functions space time' + assert not re.search(r'time: \d+', body), 'disable_functions space time' assert not re.search( r'exec: \/\w+', body ), 'disable_functions space exec' @@ -566,7 +596,7 @@ class TestPHPApplication(TestApplicationPHP): "listeners": {"*:7080": {"pass": "applications/script"}}, "applications": { "script": { - "type": "php", + "type": self.get_application_type(), "processes": {"spare": 0}, "root": option.test_dir + "/php/script", "script": "phpinfo.php", @@ -586,7 +616,7 @@ class TestPHPApplication(TestApplicationPHP): "listeners": {"*:7080": {"pass": "applications/phpinfo"}}, "applications": { "phpinfo": { - "type": "php", + "type": self.get_application_type(), "processes": {"spare": 0}, "root": option.test_dir + "/php/phpinfo", } @@ -613,7 +643,7 @@ class TestPHPApplication(TestApplicationPHP): "listeners": {"*:7080": {"pass": "applications/phpinfo"}}, "applications": { "phpinfo": { - "type": "php", + "type": self.get_application_type(), "processes": {"spare": 0}, "root": new_root, "working_directory": new_root, @@ -637,7 +667,8 @@ class TestPHPApplication(TestApplicationPHP): assert resp['body'] == script_cwd, 'default cwd' assert 'success' in self.conf( - '"' + option.test_dir + '"', 'applications/cwd/working_directory', + '"' + option.test_dir + '"', + 'applications/cwd/working_directory', ) resp = self.get() @@ -717,16 +748,31 @@ class TestPHPApplication(TestApplicationPHP): def test_php_application_shared_opcache(self): self.load('opcache', limits={'requests': 1}) - r = self.get() - cached = r['headers']['X-Cached'] - if cached == '-1': - pytest.skip('opcache is not supported') - + r = self.check_opcache() pid = r['headers']['X-Pid'] - - assert cached == '0', 'not cached' + assert r['headers']['X-Cached'] == '0', 'not cached' r = self.get() assert r['headers']['X-Pid'] != pid, 'new instance' assert r['headers']['X-Cached'] == '1', 'cached' + + def test_php_application_opcache_preload_chdir(self, temp_dir): + self.load('opcache') + + self.check_opcache() + + self.set_preload('chdir.php') + + assert self.get()['headers']['X-Cached'] == '0', 'not cached' + assert self.get()['headers']['X-Cached'] == '1', 'cached' + + def test_php_application_opcache_preload_ffr(self, temp_dir): + self.load('opcache') + + self.check_opcache() + + self.set_preload('fastcgi_finish_request.php') + + assert self.get()['headers']['X-Cached'] == '0', 'not cached' + assert self.get()['headers']['X-Cached'] == '1', 'cached' |