Last modified: 2013-11-08 08:12:40 UTC

Wikimedia Bugzilla is closed!

Wikimedia migrated from Bugzilla to Phabricator. Bug reports are handled in Wikimedia Phabricator.
This static website is read-only and for historical purposes. It is not possible to log in and except for displaying bug reports and their history, links might be broken. See T45571, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 43571 - PHPUnit tests choke with MySQL views
PHPUnit tests choke with MySQL views
Status: RESOLVED FIXED
Product: MediaWiki
Classification: Unclassified
Unit tests (Other open bugs)
1.21.x
PC Linux
: Normal normal (vote)
: 1.22.0 release
Assigned To: Antoine "hashar" Musso (WMF)
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2013-01-01 19:10 UTC by physikerwelt
Modified: 2013-11-08 08:12 UTC (History)
7 users (show)

See Also:
Web browser: ---
Mobile Platform: ---
Assignee Huggle Beta Tester: ---
hashar: Backport_to_Stable+


Attachments

Description physikerwelt 2013-01-01 19:10:03 UTC
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)
Comment 1 physikerwelt 2013-01-01 23:47:16 UTC
Sorry. My git clone was not up to date.
Comment 2 physikerwelt 2013-01-02 00:45:42 UTC
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.
Comment 3 Andre Klapper 2013-01-02 02:04:42 UTC
MySQL, PHP and MediaWiki version information would be good as a start, plus confirming that you did run update.php.
Comment 4 physikerwelt 2013-01-02 02:40:57 UTC
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.
Comment 5 Antoine "hashar" Musso (WMF) 2013-01-07 12:37:21 UTC
Reopening and rephrased summary.
Comment 6 Antoine "hashar" Musso (WMF) 2013-01-07 12:40:14 UTC
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.
Comment 7 physikerwelt 2013-01-07 12:49:34 UTC
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.
Comment 8 Daniel Renfro 2013-05-22 17:45:23 UTC
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.)
Comment 9 Gerrit Notification Bot 2013-05-24 15:43:27 UTC
Related URL: https://gerrit.wikimedia.org/r/65301 (Gerrit Change I8650baa4b721fe69ea3e1d557dd76745c0c7754e)
Comment 10 Antoine "hashar" Musso (WMF) 2013-10-23 10:58:14 UTC
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.
Comment 11 Gerrit Notification Bot 2013-11-06 15:31:31 UTC
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
Comment 12 Antoine "hashar" Musso (WMF) 2013-11-06 15:34:59 UTC
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.
Comment 13 Mark A. Hershberger 2013-11-07 09:32:55 UTC
(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?
Comment 14 Antoine "hashar" Musso (WMF) 2013-11-07 09:45:28 UTC
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 +
Comment 15 Gerrit Notification Bot 2013-11-07 09:52:13 UTC
Change 65301 merged by jenkins-bot:
MySQL method to find out view + fix fatal in tests

https://gerrit.wikimedia.org/r/65301
Comment 16 Gerrit Notification Bot 2013-11-07 09:55:00 UTC
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
Comment 17 Antoine "hashar" Musso (WMF) 2013-11-07 09:55:38 UTC
Change https://gerrit.wikimedia.org/r/94119 is the cherry-pick for REL1_22.
Comment 18 Gerrit Notification Bot 2013-11-08 01:58:57 UTC
Change 94119 merged by MarkAHershberger:
MySQL method to find out view + fix fatal in tests

https://gerrit.wikimedia.org/r/94119
Comment 19 Antoine "hashar" Musso (WMF) 2013-11-08 08:12:40 UTC
Will be included in 1.22.0.

Note You need to log in before you can comment on or make changes to this bug.


Navigation
Links