Problem/Motivation
Steps to reproduce
Working with @travis.carden to get his tests running locally we figure the problem was that \Drupal\package_manager\Validator\XdebugValidator was failing because he had xdebug on
In Build tests this caused a failure at \Drupal\Tests\automatic_updates\Build\CoreUpdateTest::testCron because $assert_session->pageTextContains('Your site is ready for automatic updates.'); because there was message about xdebug error on the status report
for build tests #3320792: Make build tests fail 1) more explicitly, 2) earlier when possible (failing StatusCheckEvent subscribers) will display the reasons "Your site is ready for automatic updates" is not displayed
In kernel tests it failed because of \Drupal\Tests\package_manager\Traits\ValidationTestTrait::assertValidationResultsEqual
failed at $this->assertCount(count($expected_results), $actual_results); where we expected only 1 result but we got 2. We still got the expect result but got an additional result for xdebug.
This is not true any more since #3320815: Make validation result comparison test messages more helpful you would get a clear indication in the error that extra error message is dealing with xdebug. See the summary of that issue for an example
Originally Neither 1 of these gave you any indication what the error was really. Now #3320815 gives a clear indication for kernel tests and #3320792 will give a clear indication for build tests.
Proposed resolution
If xdebug is on automatically fail the test early. This can be done by calling new method in \Drupal\Tests\package_manager\Traits\AssertPreconditionsTrait::setUpBeforeClass() this will then apply to all our tests.
Add an environmental var PACKAGE_MANAGER_ALLOW_XDEBUG_TESTING to turn to not do this. In our message to the user we would mention setting PACKAGE_MANAGER_ALLOW_XDEBUG_TESTING
we will update XdebugValidator to return early if PACKAGE_MANAGER_ALLOW_XDEBUG_TESTING was set to true.
We deciding against having a setting in settings.php like PACKAGE_MANAGER_ALLOW_XDEBUG_TESTING because this could accidently be pushed to production and in the worst case scenario people might try to apply a critical security release when they did not know xdebug was enabled and it would timeout in the apply stage leaving them half updated.
Remaining tasks
| Comment | File | Size | Author |
|---|---|---|---|
| #25 | 3320782-25.patch | 6.1 KB | wim leers |
| #25 | interdiff.txt | 3.8 KB | wim leers |
| #23 | 3320782-23.patch | 5.41 KB | wim leers |
| #23 | interdiff.txt | 726 bytes | wim leers |
| #22 | 3320782-22.patch | 5.47 KB | wim leers |
Comments
Comment #2
tedbowI think we should probably do 1) disable the validator everywhere except were we test it. PackageManagerKernelTestBase and AutomaticUpdatesFunctionalTestBase both have a
$disableValidatorsproperty that make this easy but I can't remember for build tests.Comment #3
traviscarden commentedComment #4
wim leersMy input:
IOW: I disagree strongly with #2, because it modifies application state in functional aka integration tests, which is precisely where we're testing how the entire application works.
P.S.: why do we have both
\Drupal\automatic_updates\Validator\XdebugValidatorand\Drupal\automatic_updates\Validator\XdebugValidator? Either we should add the missing docs for that here, alternatively we need a follow-up issue for that.Comment #5
tedbow\Drupal\automatic_updates\Validator\XdebugValidatorjust subscribes toStatusCheckEventand adds a warning. This is meant to inform the user but will not stop operations. It is inpackage_managerso it is not Automatic Updates specific\Drupal\automatic_updates\Validator\XdebugValidatoris automatic_updates specific it subscribes toPreCreateEventand adds an error if the stage is an instance ofCronUpdater. This is because there will be no user to see the warning when cron is run.Related I found this issue just now #3321206: The same xdebug warning shows on the status report 2 times
Comment #6
wim leersWhat you wrote in #5 is documentation that's missing from
\Drupal\package_manager\Validator\XdebugValidator.Comment #7
wim leersThis blocked @kunal.sachdev for hours 😬
This just cost us 30 minutes of a pairing session to figure out the root cause for! 😭 (Issue: #3312619: Ensure all validation results use translatable strings except when created from throwables.)
This very much impedes productivity. This needs to be solved ASAP.
Comment #8
wim leersComment #9
tedbowUpdate the summary to detail how 2 related issues make the problem not as bad. #3320792: Make build tests fail 1) more explicitly, 2) earlier when possible (failing StatusCheckEvent subscribers) still needs to be finished but it will make the build test problem much clearer and also apply to any other problem that we check for in status checks
Set the proposed solution
Comment #10
yash.rode commentedBefore starting to work on this, according to the proposed solution if we fail the test if xdebug is on, won't it be a problem for debugging?
Comment #11
yash.rode commentedDiscussed this with @wim on a call today so, we are not facing this problem anymore, we get clear message that the error in the test is caused by XDebug being on. So, this issue can be closed as outdated, @omakr.podey and @kunal.sachdev agrees with this!
Comment #12
wim leersTo expand on #11: I marked this critical because while mentoring @yash.rode, @omkar.podey and @kunal.sachdev in early November — when I just got started on AU — they ran into problems with debugging of tests all the time.
Since then, I've helped them get their environments in order, and they now all use
xdebug offandxdebug oncommands. For the past ~6 weeks they have not run into problems around this anymore. So … closing 😊Comment #13
tedbowOk since #3320792: Make build tests fail 1) more explicitly, 2) earlier when possible (failing StatusCheckEvent subscribers) should make the situation better for build tests I am fine closing this.
Let keep in mind that this issue is here if we other problems raised by having xdebug on it testing
Comment #14
wim leersJust discussed in call.
Rescoping this to instead of doing this as a precondition prior to running tests:
\Drupal\automatic_updates\Validator\XdebugValidatoraware of whether it runs in a test or not, and NOT complain about xdebug if we're in a test$this->disableValidators[] = 'package_manager.validator.xdebug';casesComment #15
wim leersThis implements #14.2
Comment #16
wim leers\Drupal\Tests\automatic_updates\Kernel\StatusCheck\StatusCheckerTest::testGetResults()is an example of a kernel test that will fail with xdebug on,\Drupal\Tests\automatic_updates\Functional\StatusCheckTest::testStatusChecksOnStatusReportis an example of a functional test.Let's find out what other tests will fail due to #15, by pretending
xdebugis always enabled… 🤓Comment #17
wim leersThis makes
XdebugValidatorcorrectly detect when it's running in a test, and then it won't do anything.Comment #20
wim leersAdjust the two
XdebugValidatorTests.Comment #22
wim leersMaking
XdebugValidatornot fail in build tests was especially tricky :O That actually already didn't work correctly in HEAD either, because #15 touched nothing on the build test side…… but I never ever want to have to revisit this, so I spent an hour or so trying to find a way that this could reliably be detected. I think I just managed to find a way! 2🤓
Comment #23
wim leersYay! That worked 🥳
Time to stop simulating Xdebug being on at all times now!
Comment #24
phenaproximaOnly a couple of minor points which, honestly, don't block commit in my opinion. But, feel free to implement if you agree.
I wonder if this should be moved to a private static helper function, so as to keep a cleaner separation between production code and test code.
We should probably add a @see the relevant part of XdebugValidator, since this otherwise looks kinda inexplicable.
I love that we can finally get away from disabling the validator in tests!
Comment #25
wim leers#24:
Self-RTBC'ing per #24.
Comment #26
tedbowComment #27
tedbowCommitted! Thanks!