There's some mixup on which lock to acquire and which to release. Patch is coming.

Comments

chx’s picture

StatusFileSize
new1.81 KB
new919 bytes

Status: Needs review » Needs work

The last submitted patch, 1976172_1.patch, failed testing.

chx’s picture

Status: Needs work » Needs review
StatusFileSize
new920 bytes
new1.81 KB
andypost’s picture

Is this still valid? test passes so whats wrong?

chx’s picture

Assigned: chx » larowlan
Issue summary: View changes
andypost’s picture

Title: CommentStorageController releases the wrong lock » Comment entity acquired and releases the different locks
Priority: Normal » Major
StatusFileSize
new2.39 KB

Re-roll after #1893772: Move entity-type specific storage logic into entity classes
I don't see a way to test this, because you need to detect that lock is acquired in Comment::preSave() before Comment::postSave() executed

chx’s picture

StatusFileSize
new5.56 KB

mmmm tests.

chx’s picture

StatusFileSize
new5.46 KB

I found a way to simplify.

chx’s picture

StatusFileSize
new5.47 KB

With PSR-0 compliance. Verified to run with phpunit --debug --group Drupal |grep CommentLockTest. Previously I was just running this single class.

andypost’s picture

Status: Needs review » Reviewed & tested by the community

Awesome! Test actually covers that

There was 1 failure:

1) Drupal\comment\Tests\Entity\CommentLockTest::testLocks
Expectation failed for method name is equal to <string:release> when invoked at sequence index 1.
The expected invocation at index 1 was never reached.


FAILURES!
Tests: 414, Assertions: 1201, Failures: 1.
larowlan’s picture

+++ b/core/modules/comment/tests/Drupal/comment/Tests/Entity/CommentLockTest.php
@@ -0,0 +1,90 @@
+    $old_container = \Drupal::getContainer();
...
+    if ($old_container) {
+      \Drupal::setContainer($old_container);
+    }

Are these needed? I thought each phpunit test ran in a separate instance? If so can we get a comment as to why?

chx’s picture

I have no idea how much simpletest and phpunit integrates and whether removing that breaks, for example, the GUI runner. Even if unnecessary, I think it's best practice to not leave such a container behind.

We have a lot of discussions right now over the new phpunit page which touches on this as well and I think it's better to commit this useful patch and powerful test example then remove later if we decide unnecessary than let all this linger just because of three lines of code that might not do anything. Note it can't cause any harm.

tim.plunkett’s picture

There is a --process-isolation flag for PHPUnit which defaults to FALSE, so unfortunately this is necessary.

+++ b/core/modules/comment/tests/Drupal/comment/Tests/Entity/CommentLockTest.php
@@ -0,0 +1,90 @@
+    if ($old_container) {
+      \Drupal::setContainer($old_container);
+    }
...
+    $old_container = \Drupal::getContainer();

We do need to reset the container, but we don't usually do it in the test method.

PHPUnit has both tearDown() and tearDownAfterClass(), and our container resets look like this:


  /**
   * {@inheritdoc}
   */
  protected function tearDown() {
    parent::tearDown();
    $container = new ContainerBuilder();
    \Drupal::setContainer($container);
  }
chx’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new5.52 KB
new1.13 KB

OK we can do that.

tim.plunkett’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +PHPUnit

Looks great, thanks!

catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed/pushed to 8.x, thanks!

Status: Fixed » Closed (fixed)

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