diff options
author | Andrei Zeliankou <zelenkov@nginx.com> | 2021-12-11 00:16:59 +0000 |
---|---|---|
committer | Andrei Zeliankou <zelenkov@nginx.com> | 2021-12-11 00:16:59 +0000 |
commit | 4b3efcea0dfcc842fb1a0f62b610652323844d35 (patch) | |
tree | a890dc7c7c6cbc79e86557d19bfb92d2d4719229 /test | |
parent | ad843df965f47b5d209603de49d0b3b16938149d (diff) | |
download | unit-4b3efcea0dfcc842fb1a0f62b610652323844d35.tar.gz unit-4b3efcea0dfcc842fb1a0f62b610652323844d35.tar.bz2 |
Tests: added more OPcache tests.
Diffstat (limited to '')
-rw-r--r-- | test/php/opcache/index.php | 2 | ||||
-rw-r--r-- | test/php/opcache/preload/chdir.php | 7 | ||||
-rw-r--r-- | test/php/opcache/preload/fastcgi_finish_request.php | 5 | ||||
-rw-r--r-- | test/test_php_application.py | 65 |
4 files changed, 66 insertions, 13 deletions
diff --git a/test/php/opcache/index.php b/test/php/opcache/index.php index de4002bb..cf67c4c2 100644 --- a/test/php/opcache/index.php +++ b/test/php/opcache/index.php @@ -12,7 +12,7 @@ if (function_exists('opcache_is_script_cached')) { opcache_compile_file(__DIR__ . '/test.php'); } } else { - header('X-Cached: -1'); + header('X-OPcache: -1'); } ?> diff --git a/test/php/opcache/preload/chdir.php b/test/php/opcache/preload/chdir.php new file mode 100644 index 00000000..ad75e6ad --- /dev/null +++ b/test/php/opcache/preload/chdir.php @@ -0,0 +1,7 @@ +<?php + +chdir(realpath(__DIR__ . '/..')); + +opcache_compile_file('index.php'); + +?> diff --git a/test/php/opcache/preload/fastcgi_finish_request.php b/test/php/opcache/preload/fastcgi_finish_request.php new file mode 100644 index 00000000..31630cfa --- /dev/null +++ b/test/php/opcache/preload/fastcgi_finish_request.php @@ -0,0 +1,5 @@ +<?php + +fastcgi_finish_request(); + +?> diff --git a/test/test_php_application.py b/test/test_php_application.py index 194caa9f..97bb9437 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') @@ -725,16 +751,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' |