Skip to content

Commit f25f685

Browse files
committed
chore(integration_runner): Refactors code to handle PHPMODULES
1 parent c5527e8 commit f25f685

File tree

1 file changed

+29
-52
lines changed
  • daemon/internal/newrelic/integration

1 file changed

+29
-52
lines changed

daemon/internal/newrelic/integration/test.go

Lines changed: 29 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,25 @@ func merge(a, b map[string]string) map[string]string {
201201
return merged
202202
}
203203

204+
// checks the context to see if opcache is loaded by default
205+
// and then handles the PHP modules requests to make sure
206+
// we don't load opcache.so if it is already loaded by default
207+
func (t *Test) HandlePHPModules(php_executable string, ctx *Context) map[string]string {
208+
// two cases:
209+
// 1. Web test and php-cgi has opcache.so loaded by default - remove any PHPMODULE spec for opcache.so
210+
// 2. PHP test and php has opcache.so loaded by default - remove any PHPMODULE spec for opcache.so
211+
phpModulesCopy := make(map[string]string)
212+
if ctx.OPCacheModuleLoaded[php_executable] {
213+
for k, v := range t.PhpModules {
214+
if !strings.Contains(v, "opcache.so") {
215+
phpModulesCopy[k] = v
216+
}
217+
}
218+
}
219+
220+
return phpModulesCopy
221+
}
222+
204223
func (t *Test) MakeRun(ctx *Context) (Tx, error) {
205224

206225
// we don't support running C tests - assert this so we can
@@ -222,68 +241,22 @@ func (t *Test) MakeRun(ctx *Context) (Tx, error) {
222241
}
223242
}
224243

225-
// Make a copy of settings to avoid mutating the original map
226-
// Need to adjust settings to opcache
227-
phpSettings := make(map[string]string, len(settings))
228-
setOPCacheEnable := true
229-
setOPCacheEnableCLI := true
230244
var php_executable string
231245
if t.IsWeb() {
232246
php_executable = ctx.CGI
233-
} else {
247+
} else if t.IsPHP() {
234248
php_executable = ctx.PHP
235-
}
236-
for k, v := range settings {
237-
phpSettings[k] = v
238-
239-
// see if settings affect opcache config
240-
// if so then we will not set config below
241-
if k == "opcache.enable" {
242-
setOPCacheEnable = false
243-
} else if k == "opcache.enable_cli" {
244-
setOPCacheEnableCLI = false
245-
}
246-
}
247-
if ctx.UseOPCache {
248-
if !ctx.OPCacheModuleLoaded[php_executable] {
249-
phpSettings["zend_extension"] = "opcache.so"
250-
}
251-
if setOPCacheEnable {
252-
phpSettings["opcache.enable"] = "1"
253-
}
254-
if setOPCacheEnableCLI {
255-
phpSettings["opcache.enable_cli"] = "1"
256-
}
257249
} else {
258-
if setOPCacheEnable {
259-
phpSettings["opcache.enable"] = "0"
260-
}
261-
if setOPCacheEnableCLI {
262-
phpSettings["opcache.enable_cli"] = "0"
263-
}
264-
}
265-
266-
// Make a copy of t.PhpModules and remove any entries containing "opcache.so"
267-
// if opcache.so is loaded by default
268-
//
269-
// two cases:
270-
// 1. Web test and php-cgi has opcache.so loaded by default - remove any PHPMODULE spec for opcache.so
271-
// 2. PHP test and php has opcache.so loaded by default - remove any PHPMODULE spec for opcache.so
272-
phpModulesCopy := make(map[string]string)
273-
if ctx.OPCacheModuleLoaded[php_executable] {
274-
for k, v := range t.PhpModules {
275-
if !strings.Contains(v, "opcache.so") {
276-
phpModulesCopy[k] = v
277-
}
278-
}
250+
return nil, fmt.Errorf("unknown test type for %s", t.Path)
279251
}
280252

281-
phpSettings = merge(phpSettings, phpModulesCopy)
253+
phpModulesCopy := t.HandlePHPModules(php_executable, ctx)
254+
settings = merge(settings, phpModulesCopy)
282255

283256
if t.IsWeb() {
284-
return CgiTx(ScriptFile(t.Path), t.Env, phpSettings, headers, ctx)
257+
return CgiTx(ScriptFile(t.Path), t.Env, settings, headers, ctx)
285258
}
286-
return PhpTx(ScriptFile(t.Path), t.Env, phpSettings, ctx)
259+
return PhpTx(ScriptFile(t.Path), t.Env, settings, ctx)
287260
}
288261

289262
func (t *Test) MakeSkipIf(ctx *Context) (Tx, error) {
@@ -302,6 +275,10 @@ func (t *Test) MakeSkipIf(ctx *Context) (Tx, error) {
302275
data: t.rawSkipIf,
303276
}
304277

278+
// handle the PHPMODULES directive
279+
phpModulesCopy := t.HandlePHPModules(ctx.PHP, ctx)
280+
settings = merge(settings, phpModulesCopy)
281+
305282
return PhpTx(src, t.Env, settings, ctx)
306283
}
307284

0 commit comments

Comments
 (0)