quicksketch reports http://skitch.com/quicksketch/dkefx/php-stack-trace

I report that when nextIdDelete fires (shutdown function) from includes/database/mysql/database.inc after a test class is finished in the browser then prefixTables sees the simpletest prefix. Here is a dump once _simpletest_batch_operation is finished from prefixTables (i removed a bunch of newlines from the SQL queries to shorten it:

default prefix 
SELECT 1 AS expression FROM {sessions} sessions WHERE  (sid = :db_condition_placeholder_0)  FOR UPDATE
default prefix 
UPDATE {sessions} SET uid=:db_update_placeholder_0, cache=:db_update_placeholder_1, hostname=:db_update_placeholder_2, session=:db_update_placeholder_3, timestamp=:db_update_placeholder_4 WHERE  (sid = :db_condition_placeholder_0) 
default prefix 
SELECT data, created, expire, serialized FROM {cache_bootstrap} WHERE cid = :cid
default prefix 
SELECT 1 AS expression FROM  {cache_bootstrap} cache_bootstrap WHERE  (cid = :db_condition_placeholder_0)  FOR UPDATE
default prefix 
UPDATE {cache_bootstrap} SET serialized=:db_update_placeholder_0, created=:db_update_placeholder_1, expire=:db_update_placeholder_2, data=:db_update_placeholder_3 WHERE  (cid = :db_condition_placeholder_0) 
default prefix 
UPDATE {batch} SET batch=:db_update_placeholder_0 WHERE  (bid = :db_condition_placeholder_0) 
default prefix simpletest652543
SELECT MAX(value) FROM {sequences}

That's a db_merge from sessions, then a cache_set for cache_bootstrap, a batch refresh and then nextIdDelete. The right question to ask is why this function fires? It only got called during system install and we presumedly restore the shutdown functions. A dump of drupal_register_shutdown_function does not show nextIdDelete however.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

chx’s picture

FileSize
624 bytes

With less debug.

catch’s picture

Status: Needs review » Reviewed & tested by the community

ouch.

chx’s picture

Dries’s picture

Status: Reviewed & tested by the community » Fixed

Good catch. Committed to CVS HEAD. Thanks!

Berdir’s picture

We (I, requested by Crell) did not use drupal_register_shutdown_function() on purpose to avoid adding more dependencies. But as this has shown, it's needed, so...

Crell’s picture

Status: Fixed » Needs work

As Berdir notes, not using drupal_register_shutdown_function() there was very deliberate. chx, from your description I don't quite follow why we have to use it here. That's another hard dependency between subsystems that we have gone to great lengths to avoid.

Berdir’s picture

Status: Needs work » Fixed

The fix is correct (unfortunately ;)).

We clear the shutdown functions after a test run has finished so that they don't run in the original environment (and database)*. We can only do that with functions registered with drupal_register_shutdown_function() as we don't have any influence on those registered with register_shutdown_function().

* I just learned that in this issue, this was new to me too but makes sense. If that wouldn't be the case, we could use register_shutdown_function() and use try/catch to handle any exceptions.

Edit: I wonder if Crell is automatically subscribed to an issue when someone writes down his nickname in a comment... ;)

Damien Tournoud’s picture

Status: Fixed » Needs work

No sorry, the fix is wrong.

It is by design that we are getting a prefixed database here. We just need to ignore the exceptions that might be thrown during the cleanup process.

Berdir’s picture

Yes, the prefixed database is by design.

However, the query should never run because it is supposed to be run in the test database and simpletest is responsible for cleaning up the shutdown functions. It can do that only if drupal_register_shutdown_function() is used so I don't see what's wrong with the fix.

In theory, to fully simulate an installation, simpletest could execute the shutdown functions *before* the test database is deleted but it doesn't matter since the whole install is deleted anyway.

That we get these unholy "exception thrown without stackstrace" errors again/still is a different issue and looked at in the other issue.

chx’s picture

Status: Needs work » Needs review
FileSize
902 bytes

Hrm.

Crell’s picture

Status: Needs review » Needs work

I think I still prefer DamZ's suggestion in #8. If the cleanup query fails there's no serious harm, it will only happen if the DB goes away mid-process which only happens during simpletest, and it introduces no dependencies, hard or soft, on the Drupal layers above it.

chx’s picture

Status: Needs work » Needs review
FileSize
1.78 KB

Sure thing. I wrote this patch too before posting the other. :)

Dries’s picture

Oopsie! Glad we're fixing it already. :)

+++ includes/database/mysql/database.inc	2010-06-29 18:38:02 +0000
@@ -110,10 +110,18 @@ class DatabaseConnection_mysql extends D
+    // During testing, this function is called from shutdown with the
+    // wrong prefix so we need to ignore the database errors. There is no

Could we mention why it is called with the wrong prefix?

Crell’s picture

Status: Needs review » Needs work

There should also be a period, not a comma, in "ignoring errors here, if these queries".

Other than that and Dries' comment comment (is that a meta comment), I'm good with #12.

chx’s picture

Status: Needs work » Needs review
FileSize
1.89 KB

No :D good god. that's difficult to explain.

mcrittenden’s picture

Status: Needs review » Needs work
and those table

Should be tables.

shutdown is called  so we need

Two spaces between "called" and "so"

There is no problem with completely ignoring errors here, if
+    // these queries fail, the sequence will work just fine just take a bit
+    // more space.

Not a proper sentence.

webchick’s picture

While we're at it, let's comment

-      drupal_register_shutdown_function(array($this, 'nextIdDelete'));
+      register_shutdown_function(array($this, 'nextIdDelete'));

this change to indicate that we're intentionally not going through drupal_register_shutdown_function(), so that someone later on doesn't try and "fix" this.

carlos8f’s picture

@mcrittenden

Should be tables.

A literal reference should be surrounded in quotes: "tables".

Two spaces between "called" and "so"

This needs a period at the end.

Not a proper sentence.

"Not a proper sentence." is not a proper sentence :)

Damien Tournoud’s picture

I do not comment on meta-comments.

That was a meta-comment.

carlos8f’s picture

#18 implements hook_humor()

Crell’s picture

I will refrain from commenting on DamZ's lack of comment about carlos8f's comment regarding mcrittenden's comments about the code comments in the latest patch.

chx’s picture

Status: Needs work » Needs review
FileSize
2.01 KB
Berdir’s picture

Removed a trailing whitespace and added () to the function in the comment.

tstoeckler’s picture

+++ includes/database/mysql/database.inc
@@ -111,9 +113,19 @@ class DatabaseConnection_mysql extends DatabaseConnection {
+      // We know we are using MySQL here, so need for the slower db_delete().
+      $this->query('DELETE FROM {sequences} WHERE value < :value', array(':value' => $max_id));

need -> no need
I don't want to start another commenting avalanche, but this typo is really confusing.

Leaving at needs review for more reviews (...), but the next reroll should fix that.

Powered by Dreditor.

chx’s picture

you surely are aware that was there in HEAD and I just indented it?

Crell’s picture

Status: Needs review » Reviewed & tested by the community

Quick, before someone else comments!

tstoeckler’s picture

No I wasn't. Dreditor makes it too easy to ignore the deleted lines...
+1 on the RTBC as someone without deeper insight into either the DB-system or SImpleTest (=== 'me') can grasp the patch and its reasoning from the inline comments.

webchick’s picture

Status: Reviewed & tested by the community » Fixed

Added a comma between $this->connection and and ;), and committed to HEAD. thanks!

Yay, testbot! So good to have you back!

Status: Fixed » Closed (fixed)

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