Problem/Motivation

The comment module tests are slow, redundant, hard to follow, and make all sorts of assumptions.

Proposed resolution

  1. Convert CommentTestBase to not use the standard profile.
  2. Have certain tests enable the additional modules they require.
  3. Add the standard profile to several other tests that were not easily decoupled from standard (some rely on markup etc.; see #1272870: No semantics for nested comments / bad for screen-readers).
  4. Move several test methods (and their respective helpers) out of the rather bloated CommentInterfaceTest into new files.
  5. Make the following change to the commentExists() helper method:
    +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentTestBase.phpundefined
    @@ -17,20 +20,60 @@
    @@ -122,7 +165,6 @@ function commentExists(Comment $comment = NULL, $reply = FALSE) {
    
    @@ -122,7 +165,6 @@ function commentExists(Comment $comment = NULL, $reply = FALSE) {
         if ($comment) {
           $regex = '/' . ($reply ? '<div class="indented">(.*?)' : '');
           $regex .= '<a id="comment-' . $comment->id . '"(.*?)'; // Comment anchor.
    -      $regex .= '<div(.*?)'; // Begin in comment div.
           $regex .= $comment->subject . '(.*?)'; // Match subject.
           $regex .= $comment->comment . '(.*?)'; // Match comment.
           $regex .= '/s';
    

    This div is present in Bartik but not in Stark.

  6. Address additional cleanups in followup issues.

Remaining tasks

Related issues

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

xjm’s picture

Status: Active » Needs review
xjm’s picture

I'm seriously considering rewriting them from scratch.

Status: Needs review » Needs work

The last submitted patch, comment-tests.patch, failed testing.

xjm’s picture

Assigned: Unassigned » xjm
Status: Needs work » Needs review
Issue tags: +Testing system
FileSize
4.24 KB
xjm’s picture

FileSize
4.69 KB

Uhm so yeah. commentExists() depends on... Bartik markup. Good times!

Status: Needs review » Needs work

The last submitted patch, 1812034-7.patch, failed testing.

xjm’s picture

Status: Needs work » Needs review
FileSize
14.51 KB

Status: Needs review » Needs work

The last submitted patch, comment-1812034-10.patch, failed testing.

xjm’s picture

Title: Comment module tests need cleanup » Only use standard profile where necessary in comment.module tests

Narrowing scope, because I'm seeing a significant performance increase locally already.

xjm’s picture

Status: Needs work » Needs review
FileSize
24.66 KB

Status: Needs review » Needs work

The last submitted patch, comment-1812034-13.patch, failed testing.

Lars Toomre’s picture

Looking at the patch in #13 @xjm, it was not immediately apparent to me where the failures were coming from.

One thing I did notice, though, is that you have hit upon several of the tests that violate our coding standards. Class members like $this->admin_user should be $this->adminUser (e.g, use camelCase naming convention). Similarly, $user->web_user should be $this->webUser.

I opened up #1811638: [meta] Clean-up Test members - ensure property definition and use of camelCase naming convention to address a similar problem I found in the Contact module tests. Perhaps you want to add a comment there if the variable renaming does not occur in this issue?

xjm’s picture

Re: #15, this patch is a work in progress. I do know where the test failures are coming from, and I am deliberately uploading partial patches to expose the failures as I work on changing away from the standard profile.

xjm’s picture

Oh, another note -- renaming classes or member variables is outside the scope of this issue, because having changed lines in a file makes git unable to detect the renames, and changing the names of $admin_user and $web_user will result in hundreds of changed lines throughout these tests (which are huge), making the patch enormously difficult to review.

I agree with updating the documentation and standards in lines that are already changed so long as they don't affect other lines, and I will probably improve the docblocks for the changed tests. This patch will probably take a minute or two off every D8 testbot run on d.o, and so is worth committing as soon as it is functional, rather than making additional cleanups here.

xjm’s picture

Status: Needs work » Needs review
FileSize
51.43 KB

Trying again. Better approach.

Status: Needs review » Needs work

The last submitted patch, comment-1812034-19.patch, failed testing.

xjm’s picture

Status: Needs work » Needs review
FileSize
60.87 KB
xjm’s picture

FileSize
51.7 KB

Whoops, #21 totally contains another patch. Fixed here.

Status: Needs review » Needs work

The last submitted patch, comment-1812034-22.patch, failed testing.

xjm’s picture

Status: Needs work » Needs review
FileSize
51.84 KB

Well, fine then.

xjm’s picture

FileSize
58.55 KB

Not duplicating a whole test method this time.

xjm’s picture

Okay cool. So here's what this patch does:

  1. Converts CommentTestBase to not use the standard profile.
  2. Has certain tests enable the additional modules they require.
  3. Adds the standard profile to several other tests that were not easily decoupled from standard (some rely on markup etc.; see #1272870: No semantics for nested comments / bad for screen-readers).
  4. Moves several test methods (and their respective helpers) out of the rather bloated CommentInterfaceTest into new files.
  5. Makes the following change to the commentExists() helper method:
    +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentTestBase.phpundefined
    @@ -17,20 +20,60 @@
    @@ -122,7 +165,6 @@ function commentExists(Comment $comment = NULL, $reply = FALSE) {
    
    @@ -122,7 +165,6 @@ function commentExists(Comment $comment = NULL, $reply = FALSE) {
         if ($comment) {
           $regex = '/' . ($reply ? '<div class="indented">(.*?)' : '');
           $regex .= '<a id="comment-' . $comment->id . '"(.*?)'; // Comment anchor.
    -      $regex .= '<div(.*?)'; // Begin in comment div.
           $regex .= $comment->subject . '(.*?)'; // Match subject.
           $regex .= $comment->comment . '(.*?)'; // Match comment.
           $regex .= '/s';
    

    This div is present in Bartik but not in standard Stark.

I think this is a good start, and it reduces test run times a lot for me locally. It would probably be best to commit this first and then do additional cleanups later, since this patch mostly just moves code around.

Not in scope: any documentation, code style, or DX cleanups for the moved code.

tstoeckler’s picture

Title: Only use standard profile where necessary in comment.module tests » Only use standard profile where necessary in comment.module tests (10% bot speed-up)
Status: Needs review » Reviewed & tested by the community

If I read the logs on qa.drupal.org correctly, this brings down the total test time of Drupal core from 30 min to 27 min (-10%) !!! Awesomesauce!!! (adding this to the title because it's so awesome)

Looked through this and everything looks good. Let's do this.

xjm’s picture

Issue summary: View changes

Updated issue summary.

xjm’s picture

Issue summary: View changes

Updated issue summary.

xjm’s picture

Thanks @tstoeckler!

I updated the issue summary based on the final patch.

xjm’s picture

Issue summary: View changes

Updated issue summary.

xjm’s picture

FWIW I also put the QA test results for this patch side-by-side with the 8.x branch tests, stared, counted, and made sure no assertions had gone missing (adding up the counts from CommentInterfaceTest, CommentStatisticsTest, CommentLinksTest, CommentNewIndicatorTest, and CommentCSSTest to get a total of 2005, the expected one assertion more than the 2004 CommentInterfaceTest has in the branch tests). Also, everything looks pink to me now.

webchick’s picture

Status: Reviewed & tested by the community » Fixed

Well this sounds like a lovely patch. Also? You are hereby crazy. (And pink!)

Committed and pushed to 8.x. Thanks!

webchick’s picture

Issue summary: View changes

Updated issue summary.

xjm’s picture

xjm’s picture

Assigned: xjm » Unassigned

Status: Fixed » Closed (fixed)

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

xjm’s picture

xjm’s picture

Issue summary: View changes

Updated issue summary.