Problem/Motivation

Drupal 7 core tests don't pass with SQLite.

It'd be useful if they did so that we can ensure changes made to database-related code for one RDMS don't break others (for example #2978575: Mysql 8 Support on Drupal 7).

This may be especially important after D7 EoL when the full d.o drupalci infrastructure will likely not be available for D7 testing.

Steps to reproduce

Run core tests with a SQLite database.

Proposed resolution

Fix the test failures.

Remaining tasks

Review and commit the following:

Touches shared db code / code outside of SQLite driver

Only changes are within the SQLite driver

Changes tests only

The combined patch in #15 has all 6 of the patches above, and tests are passing with all versions of PHP / MySQL / SQLite we've tried.

Review can stop here.

Maybes / follow-ups:

Done:

User interface changes

n/a

API changes

n/a ?

Data model changes

n/a ?

Release notes snippet

tbc

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mcdruid created an issue. See original summary.

mcdruid’s picture

mcdruid’s picture

Issue summary: View changes
mcdruid’s picture

Issue summary: View changes

There's a patch in #3173146: D7 CI failure with SQLite db using WAL which I think allows D7 tests to run properly in drupalci with WAL enabled for SQLite.

With that in place on a local drupalci set up the tests for #3172877-5: Enable WAL journal mode by default for SQLite database [D7 backport] ran with only these failures:

Insert tests 64 passes, 1 fail, and 0 exceptions
Field SQL storage tests 105 passes, 1 fail, and 0 exceptions
IP address blocking 50 passes, 2 fails, and 0 exceptions

So with any luck, those are the only other problems that we'll need to look at fixing; they should each have their own issue.

izmeez’s picture

@mcdruid You are doing an amazing job.

mcdruid’s picture

Issue summary: View changes

Added child issues for the 3 failing tests.

mcdruid’s picture

@izmeez awww, thank you - appreciate that!

mcdruid’s picture

Issue summary: View changes
mcdruid’s picture

Issue summary: View changes
mcdruid’s picture

Issue summary: View changes
mcdruid’s picture

Issue summary: View changes
mcdruid’s picture

It's a bit unusual to do this, but here's a patch which combines all 5 patches from the list in the IS:

  • 3172877-8.patch
  • 1713332-92.patch
  • 3173219-4.patch
  • 3173220-3.patch
  • 2427875-11.patch

The reason for doing this is that the first 2 in the list are required to actually have drupalci test SQLite patches successfully.

Once those two are committed, we can test the others normally.

With any luck though, this combined patch should demonstrate all tests passing successfully.

mcdruid’s picture

Ok, looks like there are at least two problems:

1) Looks like SQLite testing is a still a bit fragile:

https://www.drupal.org/pift-ci-job/1837005

[0m[32mTrigger update path 20 passes, 0 fails, and 0 exceptions
[0mDatabaseSchemaObjectExistsException: Table variable already exists. in /var/www/html/includes/database/schema.inc:705
Stack trace:
#0 /var/www/html/includes/database/database.inc(2803): DatabaseSchema->createTable('variable', Array)
#1 /var/www/html/includes/common.inc(7191): db_create_table('variable', Array)
#2 /var/www/html/modules/system/system.install(600): drupal_install_schema('system')
#3 /var/www/html/includes/module.inc(934): system_install()
#4 /var/www/html/includes/install.inc(731): module_invoke('system', 'install')
#5 /var/www/html/modules/simpletest/drupal_web_test_case.php(1506): drupal_install_system()
#6 /var/www/html/modules/user/user.test(2083): DrupalWebTestCase->setUp('user_form_test')
#7 /var/www/html/modules/simpletest/drupal_web_test_case.php(524): UserEditRebuildTestCase->setUp()
#8 /var/www/html/scripts/run-tests.sh(386): DrupalTestCase->run()
#9 /var/www/html/scripts/run-tests.sh(26): simpletest_script_run_one_test('1', 'UserEditRebuild...')
#10 {main}[32mAuthmap assignment 6 passes, 0 fails, and 0 exceptions
[0mFATAL UserLoginTestCase: test runner returned a non-zero error code (2).

AFAICS that may be due to concurrency. I can't really think what else would cause it to happen intermittently.

As the SQLite tests are very fast when they do work successfully, I wonder if we could dial down the concurrency and make them more reliable? I'll talk to @mixologic about it.

2) I've not seen this one before:

 Connection unit tests 4 passes, 0 fails, and 4 exceptions

...along with 4 of these:

exception: [Uncaught exception] Line 262 of includes/database/sqlite/database.inc:
PDOException: SQLSTATE[HY000]: General error: 1 no such function: CONNECTION_ID: SELECT CONNECTION_ID(); Array
(
)
 in ConnectionUnitTest->getConnectionID() (line 4093 of /var/www/html/modules/simpletest/tests/database_test.test).

AFAICS that test should be skipped for anything other than MySQL (SQLite doesn't have a CONNECTION_ID() function so this is never going to work):

https://git.drupalcode.org/project/drupal/-/blob/7.73/modules/simpletest...

    // Determine whether the database driver is MySQL. If it is not, the test
    // methods will not be executed.
    // @todo Make this test driver-agnostic, or find a proper way to skip it.
    // @see http://drupal.org/node/1273478
    $connection_info = Database::getConnectionInfo('default');
    $this->skipTest = (bool) $connection_info['default']['driver'] != 'mysql';
    if ($this->skipTest) {
      // Insert an assertion to prevent Simpletest from interpreting the test
      // as failure.
      $this->pass('This test is only compatible with MySQL.');
    }

So I'm not really sure why this code is running in the first place.

#3128880: Make ConnectionUnitTest also run for PostgreSQL is sort of relevant but doesn't have anything we can backport for SQLite.

mcdruid’s picture

Issue summary: View changes
mcdruid’s picture

Filed #3174121: Intermittent errors with D7 SQLite tests to suggest running drupalci with a lower concurrency for D7 / SQLite.

Adding 3174134-2.patch to the combined patch (also added the issue to the IS).

Again, no interdiff as that new patch would be it.

joseph.olstad’s picture

nice work!
100% success.

Mixologic’s picture

If there are intermittent errors with high concurrency, that reveals a bug with the sqlite db implementation, and isnt something that should be 'fixed' by dialing down the testbot concurrency.

joseph.olstad’s picture

@Mixologic , might be due to the fact that the previous run was only a partial patch

the full combined patch in #15 seems ok.

mcdruid’s picture

The first test run in #12 hit an exception ( https://www.drupal.org/pift-ci-job/1837005 ) which went away with a re-run, so with that small sample size, I'd call it an intermittent problem.

I won't argue that it reflects the fact that D7 might not handle a lot of db churn with high concurrency using SQLite, and I can see the point of view that we shouldn't try to avoid that by being gentler with the testbot :)

I don't think improving that's going to be a high priority any time soon, but patches always welcome!

In the meantime, it looks like we might have been unlucky and hopefully it'll work most of the time (and will eventually succeed with a rerun or two), so I think this is a definite improvement to D7's test coverage.

We'll work on getting the patches reviewed and committed.

mcdruid’s picture

Issue summary: View changes

Tidied IS to make this easy to review.

mcdruid’s picture

Issue summary: View changes
mcdruid’s picture

Looks like tests are passing with all versions of PHP / MySQL / SQLite we've tried (bar the odd testbot hiccup, typically solved by a re-run).

joseph.olstad’s picture

Status: Needs review » Reviewed & tested by the community

I just quickly went through the patch line by line.

It looks good to me, some test changes revolving around table prefixes had to look closely but the changes look good afaik.

It's definately an improvement.

The db api is a work in progress so I'd say put this into 7.x dev branch and continue working on the mysql 8 issue which will get a lot more people testing and already has some of its own test coverage.

Thanks!

mcdruid’s picture

mcdruid’s picture

Status: Reviewed & tested by the community » Fixed

Yup, looks like tests pass in SQLite and MySQL now.

Nice. Thanks for your help everyone.

joseph.olstad’s picture

Great work @mcdruid, Thanks!

joseph.olstad’s picture

My appologies if I get your name mixed up with McDavid a lightning fast hockey player. I just caught myself on it.

joseph.olstad’s picture

@mcdruid , one important thing we need to do now, can you please add automated sqlite testing to this page:

https://www.drupal.org/node/3060/qa

this should run on commit!

mcdruid’s picture

Yup, thanks @joseph.olstad I'd planned on adding SQLite tests on commit - I just added it.

I prefer all lowercase, but no big deal :)

Thanks for your help!

joseph.olstad’s picture

Thanks for that!
Lol, I was referring to this Mc:

Status: Fixed » Closed (fixed)

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