Multiple test functions and db_prefixing cause error

boombatower - March 27, 2008 - 22:35
Project:SimpleTest
Version:7.x-1.x-dev
Component:Code
Category:bug report
Priority:critical
Assigned:boombatower
Status:closed
Description

When running multiple test functions within a class something isn't working correctly so that test fails horribly. If the test functions are run individual everything works. I'm guessing this is why most the tests fail, as they used to work.

This is a very hard to catch/debug error. Chx and I have been trying to figure this out with little luck.

So far the only thing I can confirm is that if setUp and the db_prefix portion of tearDown are commented out the tests work.

From the our best reasoning chx and I believe this has to do with a caching issue.

#1

moshe weitzman - March 27, 2008 - 23:32

We should consider running all tests with the batch API. This will prevent out of memory errors as well ( thats what i got when i ran all tests from within drush)

#2

boombatower - March 28, 2008 - 18:28

@moshe weitzman: Looks like a possibility. This doesn't fix the db_prefixing issue, but could prove useful. If you would write a patch that would be great.

@all: Batch API Documentation

#3

boombatower - March 29, 2008 - 21:46
Status:active» fixed

After allot of time spent debugging this (and tearing out hair) I have discovered what I believe to be the issue.

  • Database prefix wasn't being changed because the user agent header on the internal browser wasn't be updated. Fixed by closing the curl handler and allowing the curl handler to be re-created.
  • SimpleTest module caches the original set of modules and compares them to the set of modules after the tests have run and based on that resets the modules to the original state. It also decides whether or not a module is already enabled based on the sate arrays. Due to the recreation of the database and the fact that this reset code wasn't run the $this->_modules array wasn't being reset and thus wasn't enabled repeat modules in the second test function. This, as you can imagine, creates havoc.
  • The new login handler wasn't creating issues, but was creating an extra page call since it still thought it was logged in after the database was reset.

The above was fixed with the addition of the following code:

<?php
function tearDown() {
...
 
$this->_logged_in = FALSE;
 
$this->_modules = $this->_originalModules;
 
$this->curlClose();
...
}

...

protected function
curlClose() {
  if (isset(
$this->ch)) {
   
curl_close($this->ch);
    unset(
$this->ch);
  }
}
?>

Although the fix is quiet simple, coming to this conclusion took many hours of painstaking debugging. Now that this is fixed SimpleTest should be able to reliably flush the database after each test function has run and I can move on the clean out the issue queue.

AttachmentSize
simpletest_db_prefix.patch1 KB

#4

moshe weitzman - March 29, 2008 - 21:23

very nice detective work, boombatower. thanks.

#5

Anonymous (not verified) - April 12, 2008 - 21:51
Status:fixed» closed

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

 
 

Drupal is a registered trademark of Dries Buytaert.