Tests: added more OPcache tests.

This commit is contained in:
Andrei Zeliankou 2021-12-11 00:16:59 +00:00
parent ad843df965
commit 4b3efcea0d
4 changed files with 65 additions and 12 deletions

View file

@ -12,7 +12,7 @@ if (function_exists('opcache_is_script_cached')) {
opcache_compile_file(__DIR__ . '/test.php'); opcache_compile_file(__DIR__ . '/test.php');
} }
} else { } else {
header('X-Cached: -1'); header('X-OPcache: -1');
} }
?> ?>

View file

@ -0,0 +1,7 @@
<?php
chdir(realpath(__DIR__ . '/..'));
opcache_compile_file('index.php');
?>

View file

@ -0,0 +1,5 @@
<?php
fastcgi_finish_request();
?>

View file

@ -1,3 +1,4 @@
import getpass
import os import os
import re import re
import shutil import shutil
@ -18,18 +19,43 @@ class TestPHPApplication(TestApplicationPHP):
assert re.search(r'time: \d+', body), 'disable_functions before time' assert re.search(r'time: \d+', body), 'disable_functions before time'
assert re.search(r'exec: \/\w+', body), 'disable_functions before exec' 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): def set_opcache(self, app, val):
assert 'success' in self.conf( assert 'success' in self.conf(
{"admin": {"opcache.enable": val, "opcache.enable_cli": val}}, {"admin": {"opcache.enable": val, "opcache.enable_cli": val}},
'applications/' + app + '/options', 'applications/' + app + '/options',
) )
opcache = self.get()['headers']['X-OPcache'] r = self.check_opcache()
assert r['headers']['X-OPcache'] == val, 'opcache value'
if not opcache or opcache == '-1': def set_preload(self, preload):
pytest.skip('opcache is not supported') 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): def test_php_application_variables(self):
self.load('variables') self.load('variables')
@ -725,16 +751,31 @@ class TestPHPApplication(TestApplicationPHP):
def test_php_application_shared_opcache(self): def test_php_application_shared_opcache(self):
self.load('opcache', limits={'requests': 1}) self.load('opcache', limits={'requests': 1})
r = self.get() r = self.check_opcache()
cached = r['headers']['X-Cached']
if cached == '-1':
pytest.skip('opcache is not supported')
pid = r['headers']['X-Pid'] pid = r['headers']['X-Pid']
assert r['headers']['X-Cached'] == '0', 'not cached'
assert cached == '0', 'not cached'
r = self.get() r = self.get()
assert r['headers']['X-Pid'] != pid, 'new instance' assert r['headers']['X-Pid'] != pid, 'new instance'
assert r['headers']['X-Cached'] == '1', 'cached' 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'