mirror of
https://github.com/php/frankenphp.git
synced 2026-03-23 16:42:13 +01:00
tests: opcache_preload (#2257)
Adds a test to reproduce #2254 and verify `opcache_preload` works as intended with the changes from https://github.com/php/frankenphp/pull/2252.
This commit is contained in:
committed by
GitHub
parent
c1e30cd638
commit
1f484321a0
@@ -22,6 +22,7 @@ import (
|
||||
"net/url"
|
||||
"os"
|
||||
"os/exec"
|
||||
"os/user"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -1302,3 +1303,30 @@ func TestSessionNoLeakAfterExit_worker(t *testing.T) {
|
||||
realServer: true,
|
||||
})
|
||||
}
|
||||
|
||||
func TestOpcachePreload_module(t *testing.T) {
|
||||
testOpcachePreload(t, &testOptions{env: map[string]string{"TEST": "123"}})
|
||||
}
|
||||
|
||||
func TestOpcachePreload_worker(t *testing.T) {
|
||||
testOpcachePreload(t, &testOptions{workerScript: "preload-check.php", nbWorkers: 1, nbParallelRequests: 1, env: map[string]string{"TEST": "123"}})
|
||||
}
|
||||
|
||||
func testOpcachePreload(t *testing.T, opts *testOptions) {
|
||||
cwd, _ := os.Getwd()
|
||||
preloadScript := cwd + "/testdata/preload.php"
|
||||
|
||||
u, err := user.Current()
|
||||
require.NoError(t, err)
|
||||
|
||||
opts.phpIni = map[string]string{
|
||||
"opcache.enable": "1",
|
||||
"opcache.preload": preloadScript,
|
||||
"opcache.preload_user": u.Username,
|
||||
}
|
||||
|
||||
runTest(t, func(handler func(http.ResponseWriter, *http.Request), _ *httptest.Server, i int) {
|
||||
body, _ := testGet("http://example.com/preload-check.php", handler, t)
|
||||
assert.Equal(t, "I am preloaded", body)
|
||||
}, opts)
|
||||
}
|
||||
|
||||
12
testdata/preload-check.php
vendored
Normal file
12
testdata/preload-check.php
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__.'/_executor.php';
|
||||
|
||||
return function () {
|
||||
if (function_exists('preloaded_function')) {
|
||||
echo preloaded_function();
|
||||
} else {
|
||||
echo 'not preloaded';
|
||||
}
|
||||
};
|
||||
|
||||
8
testdata/preload.php
vendored
Normal file
8
testdata/preload.php
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
// verify ENV can be accessed during preload
|
||||
$_ENV['TEST'] = '123';
|
||||
function preloaded_function(): string
|
||||
{
|
||||
return 'I am preloaded';
|
||||
}
|
||||
Reference in New Issue
Block a user