Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
The comment module tests are slow, redundant, hard to follow, and make all sorts of assumptions.
Proposed resolution
- Convert
CommentTestBase
to not use the standard profile. - Have certain tests enable the additional modules they require.
- 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).
- Move several test methods (and their respective helpers) out of the rather bloated
CommentInterfaceTest
into new files. - 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.
- Address additional cleanups in followup issues.
Remaining tasks
Related issues
Comment | File | Size | Author |
---|---|---|---|
#25 | comment-1812034-25.patch | 58.55 KB | xjm |
#24 | comment-1812034-24b.patch | 51.84 KB | xjm |
#22 | comment-1812034-22.patch | 51.7 KB | xjm |
#21 | comment-1812034-21.patch | 60.87 KB | xjm |
#19 | comment-1812034-19.patch | 51.43 KB | xjm |
Comments
Comment #1
xjmComment #2
xjmI'm seriously considering rewriting them from scratch.
Comment #6
xjmComment #7
xjmUhm so yeah.
commentExists()
depends on... Bartik markup. Good times!Comment #10
xjmComment #12
xjmNarrowing scope, because I'm seeing a significant performance increase locally already.
Comment #13
xjmComment #15
Lars Toomre CreditAttribution: Lars Toomre commentedLooking 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?
Comment #16
xjmRe: #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.
Comment #17
xjmOh, 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.
Comment #19
xjmTrying again. Better approach.
Comment #21
xjmComment #22
xjmWhoops, #21 totally contains another patch. Fixed here.
Comment #24
xjmWell, fine then.
Comment #25
xjmNot duplicating a whole test method this time.
Comment #26
xjmOkay cool. So here's what this patch does:
CommentTestBase
to not use the standard profile.CommentInterfaceTest
into new files.commentExists()
helper method:This div is present in Bartik but not in
standardStark.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.
Comment #27
tstoecklerIf 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.
Comment #27.0
xjmUpdated issue summary.
Comment #27.1
xjmUpdated issue summary.
Comment #28
xjmThanks @tstoeckler!
I updated the issue summary based on the final patch.
Comment #28.0
xjmUpdated issue summary.
Comment #29
xjmFWIW 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
, andCommentCSSTest
to get a total of 2005, the expected one assertion more than the 2004CommentInterfaceTest
has in the branch tests). Also, everything looks pink to me now.Comment #30
webchickWell this sounds like a lovely patch. Also? You are hereby crazy. (And pink!)
Committed and pushed to 8.x. Thanks!
Comment #30.0
webchickUpdated issue summary.
Comment #31
xjmFollowup: #1814868: Convert remaining comment tests to the testing profile
Comment #32
xjmComment #34
xjmFollowup: #1847540: [META] Clean up comment module tests and decouple from node
Comment #34.0
xjmUpdated issue summary.