Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DebugSubscriber - Fix test-suite compatibility with XDebug 3 #22197

Merged
merged 1 commit into from
Dec 1, 2021

Conversation

totten
Copy link
Member

@totten totten commented Dec 1, 2021

Overview

The DebugSubscriber listens to APIv3 calls and appends extra debug information (memory usage, runtime, etc). Of course, this only works in some environments (eg when XDebug is enabled). The DebugSubscriber includes some guards to enable/disable data depending on XDebug v2 presence. This fixes the guard to also work with XDebug v3.

ping @seamuslee001

Before

If you run with XDebug 3 and use xdebug.mode=debug, then several tests will fail with errors like this:

Failure in api call for Payment get:  Function must be enabled in php.ini by setting 'xdebug.mode' to 'develop'
#0 /Users/totten/bknix/build/dmaster/web/sites/all/modules/civicrm/api/v3/Payment.php(50): civicrm_api3('FinancialTrxn', 'get', Array)
#1 /Users/totten/bknix/build/dmaster/web/sites/all/modules/civicrm/Civi/API/Provider/MagicFunctionProvider.php(89): civicrm_api3_payment_get(Array)
#2 /Users/totten/bknix/build/dmaster/web/sites/all/modules/civicrm/Civi/API/Kernel.php(149): Civi\API\Provider\MagicFunctionProvider->invoke(Array)

The problem? In XDebug v3, xdebug_time_index() only works if php.ini specifies "xdebug.mode=develop". Otherwise, it will emit warnings and return NULL. The warnings manifest as test-failures.

After

Tests pass. xdebug_time_index is not called if it's not going work.

Comments

  • In XDebug v3, the setting xdebug.mode is a comma-separated list of values from https://xdebug.org/docs/all_settings#mode
  • XDebug v3 has multiple ways to set xdebug.mode/XDEBUG_MODE. I was a little confused about how to rapidly experiment with different values, so I played with a few formulations. The first in this list (php -d xdebug.mode...) appears to be the most consistent/reliable when setting multiple modes.
    php -d 'xdebug.mode=develop,debug' -r 'print_r([ini_get("xdebug.mode")]);'
    
    XDEBUG_MODE=develop,debug php -r 'print_r([ini_get("xdebug.mode")]);'
    XDEBUG_MODE="develop debug" php -r 'print_r([ini_get("xdebug.mode")]);'
    
    XDEBUG_MODE=develop,debug php -d 'xdebug.mode=develop,debug' -r 'print_r([ini_get("xdebug.mode")]);'
    XDEBUG_MODE="develop debug" php -d 'xdebug.mode=develop,debug'  -r 'print_r([ini_get("xdebug.mode")]);'
    
  • So for example you can run commands like these:
    php -d 'xdebug.mode=off' ./bin/cv.phar ev 'return civicrm_api3("Contact","get",["debug"=>1])["xdebug"];'
    ## ^^ Does not try to generate stats
    
    php -d 'xdebug.mode=debug' ./bin/cv.phar ev 'return civicrm_api3("Contact","get",["debug"=>1])["xdebug"];'
    ## ^^ Does not try to generate stats
    
    php -d 'xdebug.mode=develop' ./bin/cv.phar ev 'return civicrm_api3("Contact","get",["debug"=>1])["xdebug"];'
    ## ^^ Does try to generate stats - and succeeds
    
    php -d 'xdebug.mode=debug,develop' ./bin/cv.phar ev 'return civicrm_api3("Contact","get",["debug"=>1])["xdebug"];'
    ## ^^ Does try to generate stats - and succeeds
    
  • Background: https://xdebug.org/docs/upgrade_guide

@civibot
Copy link

civibot bot commented Dec 1, 2021

(Standard links)

@civibot civibot bot added the master label Dec 1, 2021
@seamuslee001
Copy link
Contributor

This looks fine to me MOP

@totten
Copy link
Member Author

totten commented Dec 1, 2021

Thanks @seamuslee001

Test failure in api.v4.Action.DateTest.testRelativeDateRanges appears unrelated - other contemporaneous PRs are reporting the same failure for different changes (eg https://test.civicrm.org/job/CiviCRM-Core-PR/45666/testReport/). Console doesn't show anything else suspicious.

@totten totten merged commit e65f2a8 into civicrm:master Dec 1, 2021
@totten totten deleted the master-xdebug3 branch December 1, 2021 03:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants