Problem/Motivation

VocabularyCrudTest inherited from TaxonomyTestBase that involved in UI testing, but actually it testing CRUD so should be optimized.

Proposed resolution

Re-do on top of KernelTestBase

Remaining tasks

tbd

User interface changes

no

API changes

no

Beta phase evaluation

Reference: https://www.drupal.org/core/beta-changes
Issue category Bug because slows down testing for no reason
Issue priority Major because affects a whole core testing
Prioritized changes The main goal of this issue is performance of core
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Mile23’s picture

Version: 8.6.x-dev » 8.8.x-dev
Category: Bug report » Task
Issue tags: -Performance
Parent issue: » #3041700: [META] Convert some tests into Kernel or Unit tests
Manuel Garcia’s picture

Status: Active » Needs review
FileSize
6.06 KB

Here we go

Manuel Garcia’s picture

Manuel Garcia’s picture

+++ b/core/modules/taxonomy/tests/src/Kernel/VocabularyCrudTest.php
@@ -1,30 +1,59 @@
+    $this->installConfig([
+      'field',
+      'filter',
+      'system',
+      'field_test',
+      'taxonomy_crud',
+      'text',
+    ]);

I noticed that the tests still pass if we take out field and text from here, should we?

naveenvalecha’s picture

I noticed that the tests still pass if we take out field and text from here, should we?

we can remove the field, but don't have a strong opinion because I found that in the core there are mixed examples available.
The reasons why the tests are passing without field because field_test module has a dependency on the entity_test module which has a dependency on the field module.
Changes look good to me.

Manuel Garcia’s picture

Thanks @naveenvalecha for the feedback. I did notice that we do need field and text on the list of modules to enable. Its only the configuration installation that seems not to be required for the test. Perhaps its being installed like you said via dependencies.

claudiu.cristea’s picture

Status: Needs review » Needs work
Issue tags: +Test suite performance
  1. +++ b/core/modules/taxonomy/tests/src/Kernel/VocabularyCrudTest.php
    @@ -1,30 +1,59 @@
    +  public static $modules = [
    

    s/public/protected

  2. +++ b/core/modules/taxonomy/tests/src/Kernel/VocabularyCrudTest.php
    @@ -1,30 +1,59 @@
    +    'field_test',
    

    This module is not used.

  3. +++ b/core/modules/taxonomy/tests/src/Kernel/VocabularyCrudTest.php
    @@ -1,30 +1,59 @@
    +  protected $vocabulary;
    ...
         $this->vocabulary = $this->createVocabulary();
    

    This vocab is used only in 2 tests. The other tests are deleting the vocab prior running their tets logic. Let's remove it as class property and create it as local var only in the tests that are requiring it. Then we can drop also the vocabs removal from the other tests.

  4. +++ b/core/modules/taxonomy/tests/src/Kernel/VocabularyCrudTest.php
    @@ -1,30 +1,59 @@
    +    $this->installConfig([
    +      'field',
    +      'filter',
    +      'system',
    +      'field_test',
    +      'taxonomy_crud',
    +      'text',
    +    ]);
    

    Re #10, #11, #12: It seems that we don't need any config to be installed. Drop the whole $this->installConfig().

  5. +++ b/core/modules/taxonomy/tests/src/Kernel/VocabularyCrudTest.php
    @@ -67,7 +96,7 @@ public function testTaxonomyVocabularyDeleteWithTerms() {
    -    $this->assertEqual($this->vocabulary->label(), $original_vocabulary->label(), 'Vocabulary loaded successfully.');
    +    $this->assertEquals($this->vocabulary->label(), $original_vocabulary->label(), 'Vocabulary loaded successfully.');
    

    In simpletest, the assert custom message has described the success. Contrary, the PHPUnit tests are describing the failure. We have to either recreate all messages to describe the failure or to, simply, remove them. I would go with the later. We should do the same for all test occurrences.

  6. +++ b/core/modules/taxonomy/tests/src/Kernel/VocabularyCrudTest.php
    @@ -67,7 +96,7 @@ public function testTaxonomyVocabularyDeleteWithTerms() {
    @@ -77,7 +106,7 @@ public function testTaxonomyVocabularyLoadStaticReset() {
    

    I don't understand what this test is testing. All these tests should be covered by generic config entities testing. I would remove the whole test.

  7. +++ b/core/modules/taxonomy/tests/src/Kernel/VocabularyCrudTest.php
    @@ -77,7 +106,7 @@ public function testTaxonomyVocabularyLoadStaticReset() {
    @@ -107,34 +136,42 @@ public function testTaxonomyVocabularyLoadMultiple() {
    

    The method starts with an empty line.

  8. +++ b/core/modules/taxonomy/tests/src/Kernel/VocabularyCrudTest.php
    @@ -107,34 +136,42 @@ public function testTaxonomyVocabularyLoadMultiple() {
         // Fetch the vocabularies with entity_load_multiple(), specifying IDs.
    

    entity_load_multiple() is deprecated and should be replaced in the comment.

  9. +++ b/core/modules/taxonomy/tests/src/Kernel/VocabularyCrudTest.php
    @@ -107,34 +136,42 @@ public function testTaxonomyVocabularyLoadMultiple() {
         $this->assertIdentical($loaded_order, $expected_order);
    

    This method is deprecated.

  10. +++ b/core/modules/taxonomy/tests/src/Kernel/VocabularyCrudTest.php
    @@ -107,34 +136,42 @@ public function testTaxonomyVocabularyLoadMultiple() {
    +    $controller = $this->container->get('entity_type.manager')->getStorage('taxonomy_vocabulary');
    

    The naming: s/$controller/$storage

Manuel Garcia’s picture

Status: Needs work » Needs review
FileSize
8.24 KB
9.04 KB

Re #13:
Thanks so much for the review!
1. Done
2.Nice, removed.
3. We actually use the vocabulary on testTaxonomyVocabularyDeleteWithTerms apparently, but I generally like this approach too, so I've moved it out of setUp().
4. Brilliant, removed.
5. Done.
6. I honestly don't know but I'd assume so, if they are not covered by generic entity testing, we should move it over there. Removing it here in any case for now.
7. Fixed.
8. Done.
9. Done.
10. Done.

claudiu.cristea’s picture

Status: Needs review » Needs work

Great. Thank you. I'm still seeing few issues.

  1. +++ b/core/modules/taxonomy/tests/src/Kernel/VocabularyCrudTest.php
    @@ -32,43 +31,23 @@ class VocabularyCrudTest extends KernelTestBase {
    -    $this->assertEqual(0, $query->execute(), 'There are no terms remaining.');
    +    $this->assertEquals($query->execute(), 0);
    
    @@ -82,47 +61,20 @@ public function testTaxonomyVocabularyDeleteWithTerms() {
    -    $this->assertEqual(5, $query->execute(), 'There are 5 terms found.');
    +    $this->assertEquals($query->execute(), 5);
    ...
    -    $this->assertEqual(0, $query->execute(), 'All terms are deleted.');
    ...
    +    $this->assertEquals($query->execute(), 0);
    

    The order was correct before. In PHPUnit first come the expectation and that is 0 (or 5).

  2. +++ b/core/modules/taxonomy/tests/src/Kernel/VocabularyCrudTest.php
    @@ -136,16 +88,16 @@ public function testTaxonomyVocabularyLoadMultiple() {
    -    $this->assertEquals($names[$vocabulary1->id()], $vocabulary1->id(), 'Vocabulary 1 name found.');
    +    $this->assertEquals($names[$vocabulary1->id()], $vocabulary1->id());
    

    It looks that $vocabulary1->id() is the expectation here. So it should be the first parameter.

  3. +++ b/core/modules/taxonomy/tests/src/Kernel/VocabularyCrudTest.php
    @@ -199,7 +152,7 @@ public function testUninstallReinstall() {
         require_once $this->root . '/core/includes/install.inc';
    

    What is the reason for this file inclusion? I guess the test doesn't need it.

  4. +++ b/core/modules/taxonomy/tests/src/Kernel/VocabularyCrudTest.php
    @@ -209,8 +162,8 @@ public function testUninstallReinstall() {
         // connected to this vocabulary name should have been removed when the
         // module was uninstalled. Creating a new field with the same name and
         // an instance of this field on the same bundle name should be successful.
    

    This docblock needs some love. The words "connected to this" could go one line up and the rest of lines could be reorganized to honour the coding standards rule from https://www.drupal.org/docs/develop/standards/api-documentation-and-comm...

    Lines containing comments (including docblocks) must wrap as close to 80 characters as possible without going over, (...)

  5. +++ b/core/modules/taxonomy/tests/src/Kernel/VocabularyCrudTest.php
    @@ -209,8 +162,8 @@ public function testUninstallReinstall() {
    +    $vocabulary->enforceIsNew();
    +    $vocabulary->save();
    

    This can be chained as $vocabulary->enforceIsNew()->save();

Manuel Garcia’s picture

Status: Needs work » Needs review
FileSize
2.72 KB
13.16 KB

Thanks again @claudiu.cristea for the review!

Re #15:

  1. Good catch, fixed.
  2. Yup, fixed.
  3. Tested without it, and indeed it isn't necessary, removed it.
  4. Yes, done.
  5. Sure, done.

Some stats on the new kernel test: Time: 57.26 seconds, Memory: 6.00MB (on an Intel® Core™ i5-7200U CPU @ 2.50GHz × 4) - I would imagine the savings to be significant on this one, since it was 4 functional tests before, though I haven’t run them locally to measure the difference.

claudiu.cristea’s picture

Status: Needs review » Reviewed & tested by the community

Thank you!

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 16: 2473681-16.patch, failed testing. View results

claudiu.cristea’s picture

Status: Needs work » Reviewed & tested by the community

Unrelated DB server failure.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 16: 2473681-16.patch, failed testing. View results

yogeshmpawar’s picture

Status: Needs work » Reviewed & tested by the community

All looks good so setting back to RTBC! Tests failure is not related (see #3055648: Frequent random fail in \Drupal\Tests\media_library\FunctionalJavascript\MediaLibraryTest).

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 16: 2473681-16.patch, failed testing. View results

claudiu.cristea’s picture

Status: Needs work » Reviewed & tested by the community
claudiu.cristea’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs reroll

The patch doesn't apply anymore.

yogeshmpawar’s picture

Assigned: Unassigned » yogeshmpawar
yogeshmpawar’s picture

Assigned: yogeshmpawar » Unassigned
Status: Needs work » Needs review
Issue tags: -Needs reroll
FileSize
13.17 KB

Re-rolled #16 patch.

claudiu.cristea’s picture

Status: Needs review » Reviewed & tested by the community

Thank you. Back to RTBC

catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed 202ad58 and pushed to 8.8.x. Thanks!

  • catch committed 202ad58 on 8.8.x
    Issue #2473681 by Manuel Garcia, yogeshmpawar, claudiu.cristea, andypost...

Status: Fixed » Closed (fixed)

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