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.

CommentFileSizeAuthor
#3 simpletest_db_prefix.patch1 KBboombatower
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

moshe weitzman’s picture

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)

boombatower’s picture

@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

boombatower’s picture

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:

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.

moshe weitzman’s picture

Status: Active » Fixed

very nice detective work, boombatower. thanks.

Anonymous’s picture

Status: Fixed » Closed (fixed)

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