Problem/Motivation

On Ubuntu 12.04/PHP 5.5 and OS X Yosemite/PHP 5.6, I am currently getting one failing test when running all core phpunit tests with coverage reporting (--coverage-text or --coverage-html:

Time: 13.9 minutes, Memory: 246.00Mb

There was 1 failure:
1) Drupal\Tests\Core\Cache\ChainedFastBackendTest::testGetDoesntHitConsistentBackend
Drupal\Core\Cache\CacheBackendInterface::getMultiple(Array (...), false) was not expected to be called.

/var/www/drupal/core/lib/Drupal/Core/Cache/ChainedFastBackend.php:161
/var/www/drupal/core/lib/Drupal/Core/Cache/ChainedFastBackend.php:99
/var/www/drupal/core/tests/Drupal/Tests/Core/Cache/ChainedFastBackendTest.php:62

If I run the tests without coverage reporting, they complete normally.

Proposed resolution

Fix the failing report.

Remaining tasks

(done) Fix the failing report.

Beta phase evaluation

Reference: https://www.drupal.org/core/beta-changes
Issue category This is a bug because it causes a unit test to fail under certain circumstances.
Issue priority Issue is normal because the circumstances for failure aren't currently part of the automated test regime.
Unfrozen changes Unfrozen because it only changes an automated test, and makes it less fragile.
CommentFileSizeAuthor
#5 2373549-unitest-failure-in-coverage.patch1001 bytesneclimdul
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

geerlingguy’s picture

Issue summary: View changes
geerlingguy’s picture

Issue summary: View changes
geerlingguy’s picture

Title: PHPUnit test testGetDoesntHitConsistentBackend failing » PHPUnit test testGetDoesntHitConsistentBackend failing when run with coverage reporting
geerlingguy’s picture

See an example of the error in action: https://travis-ci.org/geerlingguy/drupal-travis-ci/builds/40711558#L1137

According to neclimdul, this might be caused by timing-based testing that fails when the test run is slower (running it with coverage reporting slows things down significantly).

neclimdul’s picture

Status: Active » Needs review
FileSize
1001 bytes

I was really confused when I started looking at this because running the individual test with coverage didn't cause the failure. Then I found it. Just a patch won't explain this so here's the break down.

In MemoryBackend $item->created is set like this:

      'created' => REQUEST_TIME,

In the test, we set the timestamp data for the last write to this:

    $timestamp_item = (object) array('cid' => $timestamp_cid, 'data' => time() - 60);

Since the tests are running for quite a while before this test gets run there is a large skew between REQUEST_TIME and time() and the comparison in ChainedFastBackend fails and it falls through to the consistent backend.

olli’s picture

geerlingguy’s picture

Status: Needs review » Reviewed & tested by the community

Fixes the broken test for me; #2277465: MemoryBackend cache->created should use millisecond precision is somewhat related, but this patch should go in regardless (i.e. this test is broken in the way it's currently set up).

Mile23’s picture

Issue summary: View changes

Added beta evaluation to the issue.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

This issue is a normal bug fix, and doesn't include any disruptive changes, so it is allowed per https://www.drupal.org/core/beta-changes. Committed 264b788 and pushed to 8.0.x. Thanks!

  • alexpott committed 264b788 on 8.0.x
    Issue #2373549 by neclimdul: PHPUnit test...

Status: Fixed » Closed (fixed)

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