Skip to content

Commit 73e64cd

Browse files
committed
fix(testing): Handles opcache config better
Previously it was assumed that the Zend OPCache module was NOT loaded in the environment which integration and mutliverse tests were run. Now the PHP Docker images have Zend OPCache loaded by default, causing errors when the integration_runner also tried to load this module. These changes identify if the module is loaded by default and handles setting the opcache.enable and opcache.enable_cli INI value based on the value of the "-opcache_off" command line option.
1 parent 7f6aacf commit 73e64cd

File tree

3 files changed

+70
-7
lines changed

3 files changed

+70
-7
lines changed

daemon/internal/newrelic/integration/test.go

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,28 @@ func (t *Test) MakeRun(ctx *Context) (Tx, error) {
214214
}
215215
}
216216

217-
settings = merge(settings, t.PhpModules)
217+
// Make a copy of t.PhpModules and remove any entries containing "opcache.so"
218+
// if opcache.so is loaded by default
219+
//
220+
// three cases:
221+
// 1. C test - no opcache.so needed as PHP is not going to be run
222+
// 2. Web test and php-cgi has opcache.so loaded by default - remove any PHPMODULE spec for opcache.so
223+
// 3. PHP test and php has opcache.so loaded by default - remove any PHPMODULE spec for opcache.so
224+
phpModulesCopy := make(map[string]string)
225+
if (!t.IsC()) {
226+
if (t.IsWeb() && ctx.OPCacheModuleLoaded[ctx.CGI]) ||
227+
(ctx.OPCacheModuleLoaded[ctx.PHP]) {
228+
for k, v := range t.PhpModules {
229+
if !strings.Contains(v, "opcache.so") {
230+
phpModulesCopy[k] = v
231+
}
232+
}
233+
}
234+
} else {
235+
fmt.Printf("ERROR - UNEXPECTED - Running C test: %s\n", t.Path)
236+
os.Exit(1)
237+
}
238+
settings = merge(settings, phpModulesCopy)
218239

219240
if t.IsC() {
220241
return CTx(ScriptFile(t.Path), t.Env, settings, headers, ctx)

daemon/internal/newrelic/integration/transaction.go

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,36 @@ func PhpTx(src Script, env, settings map[string]string, ctx *Context) (Tx, error
4848

4949
// Make a copy of settings to avoid mutating the original map
5050
phpSettings := make(map[string]string, len(settings))
51+
setOPCacheEnable := true
52+
setOPCacheEnableCLI := true
5153
for k, v := range settings {
5254
phpSettings[k] = v
55+
56+
// see if settings affect opcache config
57+
// if so then we will not set config below
58+
if k == "opcache.enable" {
59+
setOPCacheEnable = false
60+
} else if k == "opcache.enable_cli" {
61+
setOPCacheEnableCLI = false
62+
}
5363
}
5464
if ctx.UseOPCache {
55-
if !ctx.OPCacheModuleLoaded[ctx.PHP] {
65+
if !ctx.OPCacheModuleLoaded[ctx.CGI] {
5666
phpSettings["zend_extension"] = "opcache.so"
5767
}
58-
phpSettings["opcache.enable"] = "1"
59-
phpSettings["opcache.enable_cli"] = "1"
68+
if setOPCacheEnable {
69+
phpSettings["opcache.enable"] = "1"
70+
}
71+
if setOPCacheEnableCLI {
72+
phpSettings["opcache.enable_cli"] = "1"
73+
}
74+
} else {
75+
if setOPCacheEnable {
76+
phpSettings["opcache.enable"] = "0"
77+
}
78+
if setOPCacheEnableCLI {
79+
phpSettings["opcache.enable_cli"] = "0"
80+
}
6081
}
6182

6283
args := phpArgs(nil, filepath.Base(src.Name()), false, phpSettings)
@@ -121,15 +142,36 @@ func CgiTx(src Script, env, settings map[string]string, headers http.Header, ctx
121142

122143
// Make a copy of settings to avoid mutating the original map
123144
cgiSettings := make(map[string]string, len(settings))
145+
setOPCacheEnable := true
146+
setOPCacheEnableCLI := true
124147
for k, v := range settings {
125148
cgiSettings[k] = v
149+
150+
// see if settings affect opcache config
151+
// if so then we will not set config below
152+
if k == "opcache.enable" {
153+
setOPCacheEnable = false
154+
} else if k == "opcache.enable_cli" {
155+
setOPCacheEnableCLI = false
156+
}
126157
}
127158
if ctx.UseOPCache {
128159
if !ctx.OPCacheModuleLoaded[ctx.CGI] {
129160
cgiSettings["zend_extension"] = "opcache.so"
130161
}
131-
cgiSettings["opcache.enable"] = "1"
132-
cgiSettings["opcache.enable_cli"] = "1"
162+
if setOPCacheEnable {
163+
cgiSettings["opcache.enable"] = "1"
164+
}
165+
if setOPCacheEnableCLI {
166+
cgiSettings["opcache.enable_cli"] = "1"
167+
}
168+
} else {
169+
if setOPCacheEnable {
170+
cgiSettings["opcache.enable"] = "0"
171+
}
172+
if setOPCacheEnableCLI {
173+
cgiSettings["opcache.enable_cli"] = "0"
174+
}
133175
}
134176

135177
if ctx.Valgrind != "" {

daemon/internal/newrelic/integration/util.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func GetOPCacheModuleLoaded(php, cgi string) map[string]bool {
5555
result[php] = IsOPcacheLoaded(php)
5656
result[cgi] = IsOPcacheLoaded(cgi)
5757

58-
fmt.Printf("OPcache loaded status: %+v\n", result)
58+
fmt.Printf("OPcache default loading status: %+v\n", result)
5959

6060
return result
6161
}

0 commit comments

Comments
 (0)