Problem/Motivation

I haven't seen reports of this happening in testbot but I'm sure it will. On my local testing jobs I'm getting random test failures because EntityUnitTest is using random values for test data.

The problem is that in EntityUnitTest::testCacheTags it is adding and removing values form tags and testing an explicit return value. \Drupal\Core\Cache\Cache::mergeTags runs a sort over the tag array though so they are always ordered. This means that when the entityTypeName is alphabetically lower then the test tag we will get a failure.

Proposed resolution

I'd prefer to use and explicit value for the type instead of a random machine name but I'm not sure there will be support for that. The attached patch just sorts the expected values, mimicking the mergeTags behavior.

This is a follow up to #2512718: EntityManager::getTranslationFromContext() should add the content language cache context to the entity

CommentFileSizeAuthor
random_failures_in_EntityUnitTest.patch919 bytesneclimdul

Comments

daffie’s picture

Status: Needs review » Reviewed & tested by the community

We have had these kind of sort problems before in test.

Looks good to me.

larowlan’s picture

Yep saw this on two issues yesterday

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Nice find and fix @neclimdul.

Committed a87f47d and pushed to 8.0.x. Thanks!

  • alexpott committed a87f47d on 8.0.x
    Issue #2529442 by neclimdul: Random phpunit failures in EntityUnitTest
    

Status: Fixed » Closed (fixed)

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