This issue is part of #2157455: [Meta] Make Drupal 8 work with PostgreSQL or remove support from core before release.

Problem/Motivation

We have failing tests with PostgreSQL as Database backend in:

  • DRUPAL\LOCALE\TESTS\LOCALEUPDATECRONTEST
  • DRUPAL\SYSTEM\TESTS\SYSTEM\CRONQUEUETEST

The root cause is the claimItem() method that does not ensure to return the queue items in the correct order. This is because claimItem() orders the items by creation date. The creation date is a timestamp (Unix time), but that is problematic because many items get the same timestamp, e.g. created within the same second.

Proposed resolution

Change order by to additionally include the item_id to ensure correct ordering for queue items by ASC and to make PostgreSQL pass and to prevent possible random fails in MySQL.

User interface changes

None

API changes

None

Beta phase evaluation

Reference: https://www.drupal.org/core/beta-changes
Issue category Bug because of broken tests
Issue priority Major because of broken test environment
Disruption None disruptive for core/contributed and custom modules/themes because it is a bugfix only
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

bzrudi71’s picture

Issue summary: View changes
FileSize
269.37 KB

Just two fails in LocaleUpdateCronTest...

bzrudi71’s picture

Issue summary: View changes
jaredsmith’s picture

Re-ran the tests using the drupalci test infrastructure, with PHP 5.5 and PostgreSQL 9.1. Still seeing the same two failed tests.

Test run started:
Friday, February 13, 2015 - 16:16

Test summary
------------
Drupal\locale\Tests\LocaleConfigManagerTest 5 passes
Drupal\locale\Tests\LocaleConfigTranslationImportTest 30 passes
Drupal\locale\Tests\LocaleConfigSubscriberTest 87 passes
Drupal\locale\Tests\LocaleConfigTranslationTest 93 passes
Drupal\locale\Tests\LocaleJavascriptTranslationTest 46 passes
Drupal\locale\Tests\LocaleExportTest 59 passes
Drupal\locale\Tests\LocaleLibraryAlterTest 2 passes
Drupal\locale\Tests\LocaleContentTest 128 passes
Drupal\locale\Tests\LocaleLocaleLookupTest 22 passes
Drupal\locale\Tests\LocalePathTest 47 passes
Drupal\locale\Tests\LocaleStringTest 28 passes
Drupal\locale\Tests\LocaleTranslatedSchemaDefinitionTest 18 passes
Drupal\locale\Tests\LocaleTranslationProjectsTest 4 passes
Drupal\locale\Tests\LocaleTranslateStringTourTest 22 passes
Drupal\locale\Tests\LocalePluralFormatTest 184 passes
Drupal\locale\Tests\LocaleUpdateCronTest 50 passes 2 fails
Drupal\locale\Tests\LocaleUpdateInterfaceTest 58 passes
Drupal\locale\Tests\LocaleImportFunctionalTest 321 passes
Drupal\locale\Tests\LocaleTranslationUiTest 338 passes
Drupal\locale\Tests\LocaleUpdateTest 427 passes

Test run duration: 8 min 28 sec

jaredsmith’s picture

The two failing tests in LocaleUpdateCronTest are because the timestamps aren't being properly updated in the database during this test. Still trying to figure out why, but it seems to be the call to the db_merge function in the locale_translation_update_file_history function that's not working correctly.

I've got limited connectivity right now (as I'm on an airplane, and will be traveling all day), but maybe someone can take a look at db_merge and ensure it's working as it should in PostgreSQL. If not, I'll continue to look at it as soon as I'm able.

bzrudi71’s picture

Status: Active » Needs review
FileSize
1015 bytes

@jaredsmith: Based on your information I tried to trace this down. In addition to this, I found out that we have a fail in the

Drupal\system\Tests\System\CronQueueTest

itself, so I looked at this first.
With the help of some debug I hopefully found the (tricky) root cause in Drupal\Core\Queue\QueueInterface::claimItem(). The claimItem() method returns the items ordered by creation time. And this is not save, as all items in test are created within the same second and get the same unix time timestamp. I changed the order to make use the item_id as argument and this seems to work now.
Let's see if the attached patch works for MySQL also, and if so we need to test this on PG bot too.
Thanks!

bzrudi71’s picture

Priority: Normal » Major
Issue summary: View changes

We have pass for MySQL, so changed issue summary to explain the problem in detail.

bzrudi71’s picture

Nice, patch makes tests pass on PG bot now, so please review.

tstoeckler’s picture

I think in general (and conceptually) ordering by created makes sense (thinking of a FIFO queue) so maybe we can order by created first and then by item_id?

bzrudi71’s picture

Issue summary: View changes
FileSize
1 KB

Sure we can. Changed issue summary to reflect the now additionally order by item_id.

jaredsmith’s picture

Status: Needs review » Reviewed & tested by the community
FileSize
2.24 KB

DCI_PHPVERSION=5.5
DCI_DRUPALBRANCH=8.0.x
DCI_TESTGROUPS=locale
DCI_UPDATEREPO=TRUE
DCI_DBTYPE=pgsql
DCI_DBVER=9.1
DCI_PATCH=https://www.drupal.org/files/issues/claim-item-2.patch

Reviewed and tested both manually and with the drupalci infrastructure support for pgsql. With the patch from #2356983-9: Fix SystemQueue::claimItem() returns items in the wrong order (resolves locale test failures on PostgreSQL), all tests pass on PostgreSQL using the above parameters. Setting as RTBC, as it's a simple one-line patch and obviously does the right thing with queues.

webchick’s picture

Status: Reviewed & tested by the community » Fixed

Committed and pushed to 8.0.x. Thanks!

  • webchick committed a881702 on 8.0.x
    Issue #2356983 by bzrudi71, jaredsmith: PostgreSQL: Fix tests in locale...

Status: Fixed » Closed (fixed)

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

Dave Reid’s picture

Version: 8.0.x-dev » 7.x-dev
Component: postgresql db driver » system.module
Status: Closed (fixed) » Needs review
FileSize
940 bytes

This should have been marked for backport for Drupal 7, I've encountered queue items being processed out of order when they all contain the same timestamp as well.

jaredsmith’s picture

Status: Needs review » Reviewed & tested by the community

Patch in comment 14 works as expected. I think this is ready to be committed to the 7.x branch now as well.

Dave Reid’s picture

Title: PostgreSQL: Fix tests in locale test group » Fix SystemQueue::claimItem() returns items in the wrong order (resolves locale test failures on PostgreSQL)

Re-titling to be more clear this is a bug in the queue, not necessarily PostgreSQL or locale tests.

David_Rothstein’s picture

Status: Reviewed & tested by the community » Fixed

Committed to 7.x - thanks!

  • David_Rothstein committed 39762b7 on 7.x
    Issue #2356983 by bzrudi71, Dave Reid, jaredsmith: SystemQueue::...

Status: Fixed » Closed (fixed)

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