Download & Extend

[Module]Bundle is registered too late in WebTestBase::setUp()

Project:Drupal core
Version:8.x-dev
Component:base system
Category:bug report
Priority:major
Assigned:Unassigned
Status:closed (fixed)
Issue tags:Dependency Injection (DI), VDC, WSCCI

Issue Summary

#1535868-40: Change notice: Convert all blocks into plugins
or: http://qa.drupal.org/pifr/test/340923

Many irrelevant test failures:

Undefined index: plid Notice menu.module 198 menu_enable()

A hook_menu() implementation tries to use/retrieve a service that is registered by a module (bundle) -- which causes menu_router_rebuild() to blow up.

menu_router_rebuild() contains a try/catch block, so the actual exception is hidden. As a result, menu_enable() does not find any links in the menu links table.

The actual exception thrown is:

DependencyInjection... "The service definition "plugin.manager.system.plugin_ui" does not exist."

However, this service is registered on the container in a SystemBundle in that patch.

SystemBundle::build() gets invoked. But possibly too late or whatever.

Comments

#1

Priority:normal» major
Issue tags:+VDC

We've been having this problem in Views, as well as #1708692: Simpletest slow and other problems following Bundle services aren't available in the request that enables the module, I think we just assumed it was all the other issue.

#2

@tim.plunkett: Can you post a small patch here that demonstrates the bug with a failing test? I just tried a fresh checkout of Views 8.x-3.x, and tests seem to be passing without the hack in #1708692-19: Simpletest slow and other problems following Bundle services aren't available in the request that enables the module.

#3

Status:active» needs review

Simply add protected $profile = 'standard'; to any Views test.

I can work over the next few days to distill it down to a "small patch", but in the meantime, here's this :D

AttachmentSizeStatusTest resultOperations
views-1786990-3.patch2.49 MBIdleFAILED: [[SimpleTest]]: [MySQL] 43,291 pass(es), 15 fail(s), and 1 exception(s).View details

#4

I don't get that. As for the OP, the service is registered by SystemBundle, which is (or should be) available at all times, regardless of install profile.

#5

Perhaps the install profile part is a separate issue. Perhaps not.
But this is not normal:

#0 /var/lib/drupaltestbot/sites/default/files/checkout/core/vendor/symfony/dependency-injection/Symfony/Component/DependencyInjection/ContainerBuilder.php(338): Symfony\Component\DependencyInjection\ContainerBuilder->getDefinition('plugin.manager....')
#1 /var/lib/drupaltestbot/sites/default/files/checkout/core/modules/views/views.module(1460): Symfony\Component\DependencyInjection\ContainerBuilder->get('plugin.manager....')
#2 /var/lib/drupaltestbot/sites/default/files/checkout/core/modules/views/views.module(202): views_get_plugin_definitions()
#3 /var/lib/drupaltestbot/sites/default/files/checkout/core/includes/theme.inc(425): views_theme(Array, 'module', 'views', 'core/modules/vi...')
#4 /var/lib/drupaltestbot/sites/default/files/checkout/core/includes/theme.inc(577): _theme_process_registry(Array, 'views', 'module', 'views', 'core/modules/vi...')
#5 /var/lib/drupaltestbot/sites/default/files/checkout/core/includes/theme.maintenance.inc(95): _theme_build_registry(Object(stdClass), Array, 'phptemplate')
#6 [internal function]: _theme_load_offline_registry(Object(stdClass), Array, 'phptemplate', false)
#7 /var/lib/drupaltestbot/sites/default/files/checkout/core/includes/theme.inc(276): call_user_func_array('_theme_load_off...', Array)
#8 /var/lib/drupaltestbot/sites/default/files/checkout/core/includes/common.inc(2328): theme_get_registry(false)
#9 /var/lib/drupaltestbot/sites/default/files/checkout/core/modules/filter/filter.module(366): l('Filtered HTML', 'admin/config/co...')
#10 [internal function]: filter_permission()
#11 /var/lib/drupaltestbot/sites/default/files/checkout/core/includes/module.inc(901): call_user_func_array('filter_permissi...', Array)
#12 /var/lib/drupaltestbot/sites/default/files/checkout/core/modules/user/user.module(2341): module_invoke('filter', 'permission')
#13 /var/lib/drupaltestbot/sites/default/files/checkout/core/modules/user/user.module(2403): user_permission_get_modules()
#14 /var/lib/drupaltestbot/sites/default/files/checkout/core/modules/user/user.module(3070): user_role_grant_permissions('administrator', Array)
#15 [internal function]: user_modules_installed(Array)
#16 /var/lib/drupaltestbot/sites/default/files/checkout/core/includes/module.inc(925): call_user_func_array('user_modules_in...', Array)
#17 /var/lib/drupaltestbot/sites/default/files/checkout/core/includes/module.inc(515): module_invoke_all('modules_install...', Array)
#18 /var/lib/drupaltestbot/sites/default/files/checkout/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php(718): module_enable(Array, true)
#19 /var/lib/drupaltestbot/sites/default/files/checkout/core/modules/comment/lib/Drupal/comment/Tests/CommentTestBase.php(29): Drupal\simpletest\WebTestBase->setUp()
#20 /var/lib/drupaltestbot/sites/default/files/checkout/core/modules/comment/lib/Drupal/comment/Tests/CommentNodeAccessTest.php(37): Drupal\comment\Tests\CommentTestBase->setUp()
#21 /var/lib/drupaltestbot/sites/default/files/checkout/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php(584): Drupal\comment\Tests\CommentNodeAccessTest->setUp()
#22 /var/lib/drupaltestbot/sites/default/files/checkout/core/scripts/run-tests.sh(381): Drupal\simpletest\TestBase->run()
#23 /var/lib/drupaltestbot/sites/default/files/checkout/core/scripts/run-tests.sh(22): simpletest_script_run_one_test('59', 'Drupal\comment\...')
#24 {main}FATAL Drupal\comment\Tests\CommentNodeAccessTest: test runner returned a non-zero error code (1)

Copying this over from the other issue:

Here's the relevant call stack for one such occurence: https://privatepaste.com/ddf8081988
Note lines 13 and 14. l() is being called, which is calling theme_get_registry(), and then everything goes to hell.

So, I tried putting this into ViewTestBase:

  /**
   * Overrides TestBase::changeDatabasePrefix().
   *
   * This is the dirtiest hack. It is the only method called in
   * WebTestBase::setUp() that is after it resets $conf and before it calls
   * module_enable().
   */
  protected function changeDatabasePrefix() {
    variable_set('theme_link', FALSE);
    return parent::changeDatabasePrefix();
  }

And it all worked out.

#6

Status:needs review» needs work

The last submitted patch, views-1786990-3.patch, failed testing.

#7

Status:needs work» needs review

From #1805996-8: [META] Views in Drupal Core:

5. Include Views and Views UI in the standard install profile.
Blocked on #1786990: [Module]Bundle is registered too late in WebTestBase::setUp()

Here's a patch that's identical to that one, but with views and views_ui added as dependencies to standard.info. I'm curious what breaks.

AttachmentSizeStatusTest resultOperations
vdc-test.patch2.5 MBIdleFAILED: [[SimpleTest]]: [MySQL] 43,540 pass(es), 16 fail(s), and 0 exception(s).View details

#8

Status:needs review» needs work

The last submitted patch, vdc-test.patch, failed testing.

#9

Status:needs work» needs review

Will the exact same tests fail on just this?

AttachmentSizeStatusTest resultOperations
bundle-registration-1786990-9.patch1.79 KBIdleFAILED: [[SimpleTest]]: [MySQL] 40,283 pass(es), 12 fail(s), and 0 exception(s).View details

#10

Status:needs review» needs work

The last submitted patch, bundle-registration-1786990-9.patch, failed testing.

#11

That has got to be the single best example of narrowing scope I've ever seen. 2.5 MB to less than 2K. ;)

And yep, looks like they're all croaking with:

exception 'Symfony\Component\DependencyInjection\Exception\InvalidArgumentException' with message 'The service definition "views.bundle" does not exist.' in /var/lib/drupaltestbot/sites/default/files/checkout/core/vendor/symfony/dependency-injection/Symfony/Component/DependencyInjection/ContainerBuilder.php:690

#12

Looks like there's 4 ModuleAPI failures in #7 that aren't in #9. Trying to find out what's causing them.

#13

Ah, those were a red herring, just due to standard.info not including 'config', a Views dependency. Ok, looks like registration of [Module]Bundle happening after hook_theme() is the key scope of this issue, as demonstrated in #9.

#14

I suspect we need to turn the conclusion around. Possible causes:

1) theme() may be invoked before full bootstrap, or, before the kernel container is instantiated.

2) hook_theme() may be called by the installer, but the installer may not register bundles of modules.

3) Unlimited variations of 1) and 2) ;)

#15

Status:needs work» needs review

That's caused by filter_permission()

<?php
$format_name_replacement
= user_access('administer filters') ? l($format->name, 'admin/config/content/formats/' . $format->format) : drupal_placeholder($format->name);
?>

and then common.inc l()
<?php
 
if (!isset($use_theme) && function_exists('theme')) {
   
// Allow edge cases to prevent theme initialization and force inline link
    // rendering.
   
if (variable_get('theme_link', TRUE)) {
     
drupal_theme_initialize();
     
$registry = theme_get_registry(FALSE);
?>
AttachmentSizeStatusTest resultOperations
filter_broken.jpg33.07 KBIgnored: Check issue status.NoneNone
bundle-registration-1786990-15.patch2.72 KBIdlePASSED: [[SimpleTest]]: [MySQL] 42,146 pass(es).View details
1786990-interdiff-9vs15.txt868 bytesIgnored: Check issue status.NoneNone

#16

Status:needs review» needs work

That treats the symptom, yes.

But as sun points out in #14, this could happen in other ways as well.

#17

Status:needs work» needs review

The problem is in WebTestBase::setUp(), we install_drupal() for the profile being tested and then module_enable() any additional modules needed by the test. The module_enable() invokes hooks which could end up calling l(), or any number of other functions that end up expecting services from modules enabled by install_drupal(). Here's a really ugly fix, though I hope we can fix this more robustly in other issues like #1708692: Simpletest slow and other problems following Bundle services aren't available in the request that enables the module and #1784312: Stop doing so much pre-kernel bootstrapping.

AttachmentSizeStatusTest resultOperations
bundle-registration-1786990-17.patch5.41 KBIdlePASSED: [[SimpleTest]]: [MySQL] 42,152 pass(es).View details
bundle-registration-1786990-17-fix-only.patch3.48 KBIdlePASSED: [[SimpleTest]]: [MySQL] 42,122 pass(es).View details

#18

+++ b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php
@@ -716,24 +717,9 @@ protected function setUp() {
     if ($modules) {
       $success = module_enable($modules, TRUE);
       $this->assertTrue($success, t('Enabled modules: %modules', array('%modules' => implode(', ', $modules))));
+      $this->rebuildContainer();
     }

I think we need the rebuild in all cases, not just when additional modules to install have been specified. That is, because ->kernel and ->container are provided for test classes.

+++ b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php
@@ -779,6 +765,35 @@ protected function refreshVariables() {
+  protected function rebuildContainer() {

Given #1774388: Unit Tests Remastered™, we likely need to move this into TestBase.

#19

Since both patches in #17 are green, I removed the mock Views example from here on out. I don't think we need any test case in this patch, because the real problem still needs to be dealt with in #1708692: Simpletest slow and other problems following Bundle services aren't available in the request that enables the module. The purpose of this issue is just to allow #1805996: [META] Views in Drupal Core to add Views to the Standard install profile.

This implements #18.2. #18.1 is already taken care of: notice there's 2 lines in WebTestBase :).

AttachmentSizeStatusTest resultOperations
bundle-registration-1786990-19.patch3.93 KBIdleFAILED: [[SimpleTest]]: [MySQL] 1,294 pass(es), 487 fail(s), and 151 exception(s).View details

#20

@sun, if this is what you meant in your first comment, then that's fine.

As to the second part, first to RTBC wins :)

EDIT: Ignore this, go with 19.

AttachmentSizeStatusTest resultOperations
drupal-1786990-18-with-views.patch5.38 KBIdlePASSED: [[SimpleTest]]: [MySQL] 42,150 pass(es).View details
drupal-1786990-18.patch3.6 KBIdlePASSED: [[SimpleTest]]: [MySQL] 42,116 pass(es).View details
interdiff.txt707 bytesIgnored: Check issue status.NoneNone

#21

Same as #19, but needed to copy the use statement to TestBase.

AttachmentSizeStatusTest resultOperations
bundle-registration-1786990-21.patch4.13 KBIdlePASSED: [[SimpleTest]]: [MySQL] 42,127 pass(es).View details

#22

Status:needs review» needs work

The last submitted patch, bundle-registration-1786990-21.patch, failed testing.

#23

Status:needs work» needs review

#21: bundle-registration-1786990-21.patch queued for re-testing.

#24

Status:needs review» reviewed & tested by the community

I'm OK with this as a temporary stop-gap, so RTBC on the assumption that the testbot comes back green at some point.

#1809248: Enable apc.enable_cli php.ini setting on testbots was deployed on two testbots, right at the time when #21 was in process of testing, so if there won't be results in a 1-2 hours, I'd recommend to re-upload this patch (or manually send it for re-testing).

(@tim.plunkett: The same apparently applies to your VDC sandbox, FWIW.)

#25

Status:reviewed & tested by the community» fixed

Looks straight-forward enough.

Committed and pushed to 8.x. Thanks!

#26

Status:fixed» reviewed & tested by the community

I don't see this in the commit log, can you

git pull --rebase;
git push

please?

#27

Status:reviewed & tested by the community» fixed

Pushed now, thanks

#28

Status:fixed» closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

nobody click here