Page MenuHomePhabricator

PHPUnit tests choke with MySQL views
Closed, ResolvedPublic

Description

Author: physik

Description:
I have created some views in my mysql database. This has the effect that the phpunitests don't start. If I delete the views everything works fine.
Maybe the views can be ignored?

I get the following output for the view viewname:
tests/phpunit$ php phpunit.php
PHPUnit 3.6.10 by Sebastian Bergmann.

Configuration read from /tests/phpunit/suite.xml

A database error has occurred. Did you forget to run maintenance/update.php after upgrading? See: https://www.mediawiki.org/wiki/Manual:Upgrading#Run_the_update_script
Query: CREATE TEMPORARY TABLE unittest_viewname (LIKE viewname)
Function: DatabaseMysql::duplicateTableStructure
Error: 1347 'db.viewname' is not BASE TABLE (localhost)


Version: 1.21.x
Severity: normal
OS: Linux
Platform: PC

Details

Reference
bz43571

Event Timeline

bzimport raised the priority of this task from to Medium.Nov 22 2014, 1:16 AM
bzimport set Reference to bz43571.

physik wrote:

Sorry. My git clone was not up to date.

physik wrote:

It's somehow strage. Now I get the error again.
I deleted the views everything ran fine. Afterwards I added them again and went on testing, the tests of my extension. Finally I wanted to rerun all tests, and the error poped up again. Furthermore I'm not able to run my tests now.

MySQL, PHP and MediaWiki version information would be good as a start, plus confirming that you did run update.php.

physik wrote:

Yes I ran the update.php script again.

Following hack resolved the error:
diff --git a/tests/phpunit/MediaWikiTestCase.php b/tests/phpunit/MediaWikiTestCa
index cbf9a8e..7bb81f9 100644

  • a/tests/phpunit/MediaWikiTestCase.php

+++ b/tests/phpunit/MediaWikiTestCase.php
@@ -521,7 +521,11 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_

static private function isNotUnittest( $table ) {
        return strpos( $table, 'unittest_' ) !== 0;
}

+
+ static private function isNotView( $table ) {
+ return strpos( $table, 'view_' ) !== 0;
+ }
+

public static function listTables( $db ) {
        global $wgDBprefix;

@@ -531,6 +535,9 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_T

// Don't duplicate test tables from the previous fataled run
$tables = array_filter( $tables, array( __CLASS__, 'isNotUnittes

+ // Don't duplicate test tables from the previous fataled run
+ $tables = array_filter( $tables, array( CLASS, 'isNotView' )

Product Version
MediaWiki 1.21alpha (ba16916)
PHP 5.4.4-10 (apache2handler)
MySQL 5.5.28-1

Maybe the problem is that the listtable implementation of the mysql database acess also lists the views.

Reopening and rephrased summary.

The patch in comment #4 assume the views to be named using a 'view_' prefix. I guess views could be named differently, we need a more generic way to filter out views.

physik wrote:

Yes. Sure. Therefore I called it hack and not bugfix.
Maybe the function listTables has to be implemented in a proper way and added to the normal Database Access Classes.

I get the same error:

$ php ./phpunit.php
PHPUnit 3.7.7 by Sebastian Bergmann.

Configuration read from /home/wiki/wiki/wiki/tests/phpunit/suite.xml

A database query syntax error has occurred.
The last attempted database query was:
"CREATE TEMPORARY TABLE unittest_view_categorylinks_nonhiddencat (LIKE vpw_view_categorylinks_nonhiddencat)"
from within function "DatabaseMysql::duplicateTableStructure".
Database returned error "1347: 'wikidb.vpw_view_categorylinks_nonhiddencat' is not BASE TABLE (localhost)"

This is because MySQL cannot create temporary tables based on views. I quote from the MySQL online documentation (http://dev.mysql.com/doc/refman/5.1/en/create-table.html):

Use LIKE to create an empty table based on the definition of another table,
including any column attributes and indexes defined in the original table
...
LIKE works only for base tables, not for views.

This means that if any MW installations that want to run PHPUnit unit tests have views in their database, the MW-specific unit-test setup will fail (because MySQL will fail.)

Related URL: https://gerrit.wikimedia.org/r/65301 (Gerrit Change I8650baa4b721fe69ea3e1d557dd76745c0c7754e)

I have been reviewing the patch last summer but eventually completely forgot about it. Reviewed the latest patchset, we would want to get that in 1.22 ideally.

Change 65301 had a related patch set uploaded by Hashar:
MySQL method to find out view + fix fatal in tests

https://gerrit.wikimedia.org/r/65301

I really really want this to land in MediaWiki 1.22 as a courtesy toward Daniel Renfro who is very helpful.

Patch is close to land in master, and will happily backport it in REL1_22.

(In reply to comment #12)

Patch is close to land in master, and will happily backport it in REL1_22.

Do you have an ETA for REL1_22 landing?

Daniel solved the last trivial errors overnight, I have amended a tiny issue and about to land the patch in master; Will submit a cherry-pick for REL1_22 inclusion.

Changing backport field to +

Change 65301 merged by jenkins-bot:
MySQL method to find out view + fix fatal in tests

https://gerrit.wikimedia.org/r/65301

Change 94119 had a related patch set uploaded by Hashar:
MySQL method to find out view + fix fatal in tests

https://gerrit.wikimedia.org/r/94119

Change 94119 merged by MarkAHershberger:
MySQL method to find out view + fix fatal in tests

https://gerrit.wikimedia.org/r/94119