Download & Extend

SimpleTest: Database prefix added twice when cleaning database

Project:SimpleTest
Version:6.x-2.10
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:closed (fixed)

Issue Summary

When clicking the "clean environment" button, I get:

user warning: Unknown table 'dev_dev_simpletest' query: DROP TABLE dev_dev_simpletest in drupal-6/includes/database.mysql-common.inc on line 261.
user warning: Unknown table 'dev_dev_simpletest_test_id' query: DROP TABLE dev_dev_simpletest_test_id in drupal-6/includes/database.mysql-common.inc on line 261.

<?php
/**
* Removed prefixed talbes from the database that are left over from crashed tests.
*/
function simpletest_clean_database() {
 
$tables = simpletest_get_like_tables(); // --> This returns the tables already prefixed.

 
$ret = array();
  foreach (
$tables as $table) {
   
db_drop_table($ret, $table); // --> the function expects un-prefixed table names!
 
}
?>

Comments

#1

Also, i don't know if it's related, but my database has accumulated 300+ simpletest_* tables that have not been properly cleaned.

#2

I am actually surprised that simpletest actually tries to drop {simpletest} and {simpletest_test_id}.
Is that the intended behavior?

#3

Status:active» needs work

I am not sure what's the intended behavior.
I fixed the issue for myself with the attached patch:
the tables {simpletest} and {simpletest_test_id} are kept, but the countless simpletest* tables have been removed.
I removed the $prefix from the SELECT query, and I don't use db_drop_table() which will add the unwanted prefix.

AttachmentSizeStatusTest resultOperations
table_prefix_simpletest.patch1.19 KBIgnored: Check issue status.NoneNone

#4

Project:SimpleTest» Drupal core
Version:6.x-2.x-dev» 7.x-dev
Component:Code» simpletest.module

This is an issue with SimpleTest 7.x and should be fixed in core then backported.

#5

Title:prefix added twice to tables to drop» SimpleTest: Database prefix added twice when cleaning database

1) The get like tables needs to return either non-prefixed tables, 2) the prefixes need to be removed from the table names before running drop command, or 3) the $db_prefix could be set to '' just before running drops.

#6

subscribing (for 6.x-2.x branch)

http://drupal.org/files/issues/table_prefix_simpletest.patch fixes this bug for me too.

#7

Project:Drupal core» SimpleTest
Version:7.x-dev» 6.x-2.x-dev
Component:simpletest.module» Code

Core is not affected.

#8

I'm not following the problem here....can you give me detailed instructions on how to re-create.

simpletest_get_like_tables() should be looking for tables that were created with random prefix (ie. simpletest438928095)

and should return them as such.

#9

See the comments in the php code in comment #0 above.

#10

Yes, and from reading that and patch I wasn't sure...as I think they are inconsistent.

Changing the drop to a manual query if it auto adds prefix makes sense...otherwise we could do

<?php
$db_prefix
= '';
db_drop..()
$db_prefix = $original;
?>

But I don't get why the get query would change.

$result = db_query("SELECT $select FROM information_schema.tables WHERE table_schema = '$database' AND table_name LIKE '$base_table%'");

That would seem to fry simpletest tables ONLY if the $db_prefix = ''; ?

#11

Status:needs work» fixed

This no longer happens for me in simpletest 6.x-2.8, and the patch no longer applies, since the underlying code changed, so I am assuming that it is fixed.

#12

Status:fixed» closed (fixed)

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

#13

Version:6.x-2.x-dev» 6.x-2.10
Status:closed (fixed)» active

I'm running SimpleTest v 6.x-2.10 on D 6.12, and I get warnings in the status message box like these when I click the "Clean Environment" button after running tests.

User warning: Unknown table &#039;simpletest150449access&#039; query: DROP TABLE simpletest150449access in _db_query() (line 128 of /blah/blah/drupal/includes/database.mysqli.inc).
User warning: Unknown table &#039;simpletest150449actions&#039; query: DROP TABLE simpletest150449actions in _db_query() (line 128 of /blah/blah/drupal/includes/database.mysqli.inc).

Sure enough, see a bunch of tables in the DB with names like the following:

Arraysimpletest150449access
Arraysimpletest150449actions
Arraysimpletest150449actions_aid
Arraysimpletest150449authmap
Arraysimpletest150449batch
Arraysimpletest150449blocks
Arraysimpletest150449blocks_roles

HTML entity ' is an apostrophe, which presumably is being used in an attempt to escape table names.

#14

Whatever was causing the warnings described in the previous comment has now gone away on my site. I still see the word "Array" prepended to temporary DB table names for some reason, but it is not interfering with temp DB tables being creating and then deleted.

#15

Status:active» closed (fixed)

That is a different issue which is due to $db_prefix being an array and has been fixed.