phpunit database teardown is incomplete

Bug #1515794 reported by Aaron Wells on 2015-11-12
12
This bug affects 2 people
Affects Status Importance Assigned to Milestone
Mahara
Low
Jean-Philippe Gaudreau
15.10
Low
Unassigned

Bug Description

As noticed in Bug 1515473.

If you run the Mahara phpunit tests twice against the same database (by doing "make phpunit") you get errors on the second run. Phpunit attempts to tear down the test database and re-create it, but it misses some items and errors out when it tries to recreate them, because they already exist. This happens in Postgres or MySQL.

I'm guessing it's because there are some database entities that we create through direct execution of DDL statements rather than through XMLDB and install.xml files. Probably the teardown uses the install.xml files to remove everything, misses the directly-created things, and then the subsequent installer tries to re-create them.

Aaron Wells (u-aaronw) wrote :
Download full text (7.4 KiB)

MySQL:

[INF] ce (lib/phpunit.php:159) Installing blocktype.blog/taggedposts
[DBG] ce (lib/dml.php:150) mysqli error: [1050: Table 'tst_blocktype_taggedposts_tags' already exists] in adodb_throw(CREATE TABLE tst_blocktype_taggedposts_tags (
[DBG] ce (lib/dml.php:150) id BIGINT(10) NOT NULL auto_increment,
[DBG] ce (lib/dml.php:150) block_instance BIGINT(10) NOT NULL,
[DBG] ce (lib/dml.php:150) tag VARCHAR(128) NOT NULL,
[DBG] ce (lib/dml.php:150) tagtype BIGINT(10) NOT NULL,
[DBG] ce (lib/dml.php:150) CONSTRAINT PRIMARY KEY (id)
[DBG] ce (lib/dml.php:150) )ENGINE=innodb, )
[DBG] ce (lib/dml.php:150) Command was: CREATE TABLE tst_blocktype_taggedposts_tags (
[DBG] ce (lib/dml.php:150) id BIGINT(10) NOT NULL auto_increment,
[DBG] ce (lib/dml.php:150) block_instance BIGINT(10) NOT NULL,
[DBG] ce (lib/dml.php:150) tag VARCHAR(128) NOT NULL,
[DBG] ce (lib/dml.php:150) tagtype BIGINT(10) NOT NULL,
[DBG] ce (lib/dml.php:150) CONSTRAINT PRIMARY KEY (id)
[DBG] ce (lib/dml.php:150) )ENGINE=innodb
[DBG] ce (lib/ddl.php:753) Array
[DBG] ce (lib/ddl.php:753) (
[DBG] ce (lib/ddl.php:753) [0] => CREATE TABLE tst_blocktype_taggedposts_tags (
[DBG] ce (lib/ddl.php:753) id BIGINT(10) NOT NULL auto_increment,
[DBG] ce (lib/ddl.php:753) block_instance BIGINT(10) NOT NULL,
[DBG] ce (lib/ddl.php:753) tag VARCHAR(128) NOT NULL,
[DBG] ce (lib/ddl.php:753) tagtype BIGINT(10) NOT NULL,
[DBG] ce (lib/ddl.php:753) CONSTRAINT PRIMARY KEY (id)
[DBG] ce (lib/ddl.php:753) )ENGINE=innodb
[DBG] ce (lib/ddl.php:753) )
[DBG] ce (lib/ddl.php:753)
PHP Fatal error: Uncaught exception 'SQLException' with message 'Failed to install (check logs for xmldb errors)' in /home/aaronw/www/mahara/htdocs/lib/ddl.php:754
Stack trace:
#0 /home/aaronw/www/mahara/htdocs/lib/upgrade.php(429): install_from_xmldb_file('/home/aaronw/ww...')
#1 /home/aaronw/www/mahara/htdocs/lib/phpunit.php(173): upgrade_plugin(Object(stdClass))
#2 /home/aaronw/www/mahara/htdocs/lib/tests/phpunit/bootstrap.php(34): UnitTestBootstrap->install_mahara()
#3 /home/aaronw/www/mahara/external/vendor/phpunit/phpunit/PHPUnit/Util/Fileloader.php(92): include_once('/home/aaronw/ww...')
#4 /home/aaronw/www/mahara/external/vendor/phpunit/phpunit/PHPUnit/Util/Fileloader.php(76): PHPUnit_Util_Fileloader::load('/home/aaronw/ww...')
#5 /home/aaronw/www/mahara/external/vendor/phpunit/phpunit/PHPUnit/TextUI/Command.php(778): PHPUnit_Util_Fileloader::checkAndLoad('/home/aaronw/ww...')
#6 /home/aaronw/www/mahara/external/vendor/phpunit/phpunit/PHPUnit/TextUI/Command.php(606): PHPUnit_TextUI_Command->handleBootstrap('/home/aaro in /home/aaronw/www/mahara/htdocs/lib/ddl.php on line 754

Fatal error: Uncaught exception 'SQLException' with message 'Failed to install (check logs for xmldb errors)' in /home/aaronw/www/mahara/htdocs/lib/ddl.php:754
Stack trace:
#0 /home/aaronw/www/mahara/htdocs/lib/upgrade.php(429): install_from_xmldb_file('/home/aaronw/ww...')
#1 /home/aaronw/www/mahara/htdocs/lib/phpunit.php(173): upgrade_plugin(Object(stdClass))
#2 /home/aaronw/www/mahara/htdocs/lib/tests/phpunit/bootstrap.php(34): UnitTestBootstrap->install_mahara()
#3 /home/aaronw/www/mahara/external...

Read more...

Aaron Wells (u-aaronw) wrote :

Hm, actually it's failing trying to create a table. The blocktype_taggedposts_tags, from artefact.blog/blocktype:taggedposts

This particular blocktype is the *only* blocktype that lives inside an artefact *and* has its own install.xml file. So probably the deal is that phpunit's tearer-downer isn't noticing that install.xml file because of its unique location.

I found a clean way to fix this issue using the get_installed_plugins_paths function. Pushing the patch right away.

Changed in mahara:
assignee: nobody → Jean-Philippe Gaudreau (jp-gaudreau)
Changed in mahara:
status: Confirmed → In Progress

I first used the wrong bug number (1523499) in my commit so it made a bit of a mess, sorry...

Here's the Gerrit review: Patch for "master" branch: https://reviews.mahara.org/5871

It would be appreciate if someone could tell me how to properly recall the bot when this happens so I could do it right the next time ;)

Changed in mahara:
status: In Progress → Fix Committed
status: Fix Committed → In Progress

Reviewed: https://reviews.mahara.org/5871
Committed: https://git.mahara.org/mahara/mahara/commit/b8682571c822237bc096afd6956e3a75b4dc8c36
Submitter: Robert Lyon (<email address hidden>)
Branch: master

commit b8682571c822237bc096afd6956e3a75b4dc8c36
Author: Jean-Philippe Gaudreau <email address hidden>
Date: Tue Jan 5 15:38:46 2016 -0500

Bug 1515794: Fixing incomplete phpunit database teardown

Table from plugin artefact.blog/blocktype:taggedposts wasn't deleted
because plugins inside an artefact were not retrieved in the uninstall
process.

behatnotneeded: Not related to the interface, only unit tests.

Change-Id: I82f5ca40f2e6b17869228aef0d81e21ba69ed675

Mahara Bot (dev-mahara) wrote :

Reviewed: https://reviews.mahara.org/5891
Committed: https://git.mahara.org/mahara/mahara/commit/ca9c4fbc90e3e90330f96ef0b14d9e06f04235fc
Submitter: Robert Lyon (<email address hidden>)
Branch: 15.10_STABLE

commit ca9c4fbc90e3e90330f96ef0b14d9e06f04235fc
Author: Jean-Philippe Gaudreau <email address hidden>
Date: Tue Jan 5 15:38:46 2016 -0500

Bug 1515794: Fixing incomplete phpunit database teardown

Table from plugin artefact.blog/blocktype:taggedposts wasn't deleted
because plugins inside an artefact were not retrieved in the uninstall
process.

behatnotneeded: Not related to the interface, only unit tests.

Change-Id: I82f5ca40f2e6b17869228aef0d81e21ba69ed675

Robert Lyon (robertl-9) on 2016-02-04
Changed in mahara:
status: In Progress → Fix Committed
milestone: none → 16.04.0
Changed in mahara:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers