Index: includes/common.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/common.inc,v
retrieving revision 1.814
diff -u -9 -p -r1.814 common.inc
--- includes/common.inc	31 Oct 2008 02:23:24 -0000	1.814
+++ includes/common.inc	1 Nov 2008 13:15:43 -0000
@@ -491,20 +491,20 @@ function drupal_http_request($url, $head
     $defaults['Authorization'] = 'Authorization: Basic ' . base64_encode($uri['user'] . (!empty($uri['pass']) ? ":" . $uri['pass'] : ''));
   }
 
   // If the database prefix is being used by SimpleTest to run the tests in a copied
   // database then set the user-agent header to the database prefix so that any
   // calls to other Drupal pages will run the SimpleTest prefixed database. The
   // user-agent is used to ensure that multiple testing sessions running at the
   // same time won't interfere with each other as they would if the database
   // prefix were stored statically in a file or database variable.
-  if (preg_match("/^simpletest\d+/", $db_prefix)) {
-    $headers['User-Agent'] = $db_prefix;
+  if (preg_match("/simpletest\d+/", $db_prefix, $reg)) {
+    $headers['User-Agent'] = $reg[0];
   }
 
   foreach ($headers as $header => $value) {
     $defaults[$header] = $header . ': ' . $value;
   }
 
   $request = $method . ' ' . $path . " HTTP/1.0\r\n";
   $request .= implode("\r\n", $defaults);
   $request .= "\r\n\r\n";
Index: includes/database/database.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/database/database.inc,v
retrieving revision 1.19
diff -u -9 -p -r1.19 database.inc
--- includes/database/database.inc	31 Oct 2008 15:46:16 -0000	1.19
+++ includes/database/database.inc	1 Nov 2008 13:15:44 -0000
@@ -999,19 +999,19 @@ abstract class Database {
       // If we have any active logging objects for this connection key, we need
       // to associate them with the connection we just opened.
       if (!empty(self::$logs[$key])) {
         self::$connections[$key][$target]->setLogger(self::$logs[$key]);
       }
 
       // We need to pass around the simpletest database prefix in the request
       // and we put that in the user_agent header.
       if (preg_match("/^simpletest\d+$/", $_SERVER['HTTP_USER_AGENT'])) {
-        $db_prefix = $_SERVER['HTTP_USER_AGENT'];
+        $db_prefix .= $_SERVER['HTTP_USER_AGENT'];
       }
 
       // Return the target that was actually opened in case the requested one
       // didn't exist.
       return $target;
     }
     catch (Exception $e) {
       // It is extremely rare that an exception will be generated here other
       // than when installing.  We therefore intercept it and try the installer,
Index: modules/simpletest/drupal_web_test_case.php
===================================================================
RCS file: /cvs/drupal/drupal/modules/simpletest/drupal_web_test_case.php,v
retrieving revision 1.52
diff -u -9 -p -r1.52 drupal_web_test_case.php
--- modules/simpletest/drupal_web_test_case.php	20 Oct 2008 13:06:15 -0000	1.52
+++ modules/simpletest/drupal_web_test_case.php	1 Nov 2008 13:15:44 -0000
@@ -683,19 +683,19 @@ class DrupalWebTestCase {
    */
   function setUp() {
     global $db_prefix;
 
     // Store necessary current values before switching to prefixed database.
     $this->db_prefix_original = $db_prefix;
     $clean_url_original = variable_get('clean_url', 0);
 
     // Generate temporary prefixed database to ensure that tests have a clean starting point.
-    $db_prefix = 'simpletest' . mt_rand(1000, 1000000);
+    $db_prefix = Database::getActiveConnection()->prefixTables('{simpletest' . mt_rand(1000, 1000000) . '}');
 
     include_once DRUPAL_ROOT . '/includes/install.inc';
     drupal_install_system();
 
     // Add the specified modules to the list of modules in the default profile.
     $args = func_get_args();
     $modules = array_unique(array_merge(drupal_get_profile_modules('default', 'en'), $args));
     drupal_install_modules($modules);
 
@@ -794,20 +794,20 @@ class DrupalWebTestCase {
       $this->ch = curl_init();
       $curl_options = $this->curl_options + array(
         CURLOPT_COOKIEJAR => $this->cookie_file,
         CURLOPT_URL => $base_url,
         CURLOPT_FOLLOWLOCATION => TRUE,
         CURLOPT_RETURNTRANSFER => TRUE,
         CURLOPT_SSL_VERIFYPEER => FALSE,  // Required to make the tests run on https://
         CURLOPT_SSL_VERIFYHOST => FALSE,  // Required to make the tests run on https://
       );
-      if (preg_match('/simpletest\d+/', $db_prefix)) {
-        $curl_options[CURLOPT_USERAGENT] = $db_prefix;
+      if (preg_match('/simpletest\d+/', $db_prefix, $reg)) {
+        $curl_options[CURLOPT_USERAGENT] = $reg[0];
       }
       if (!isset($curl_options[CURLOPT_USERPWD]) && ($auth = variable_get('simpletest_httpauth_username', ''))) {
         if ($pass = variable_get('simpletest_httpauth_pass', '')) {
           $auth .= ':' . $pass;
         }
         $curl_options[CURLOPT_USERPWD] = $auth;
       }
       return $this->curlExec($curl_options);
     }
Index: modules/simpletest/simpletest.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/simpletest/simpletest.module,v
retrieving revision 1.24
diff -u -9 -p -r1.24 simpletest.module
--- modules/simpletest/simpletest.module	31 Oct 2008 11:13:30 -0000	1.24
+++ modules/simpletest/simpletest.module	1 Nov 2008 13:15:44 -0000
@@ -499,23 +499,28 @@ function simpletest_clean_environment() 
   simpletest_clean_database();
   simpletest_clean_temporary_directories();
   simpletest_clean_results_table();
 }
 
 /**
  * Removed prefixed talbes from the database that are left over from crashed tests.
  */
 function simpletest_clean_database() {
-  $tables = db_find_tables(Database::getActiveConnection()->prefixTables('simpletest') . '%');
+  global $db_prefix;
+  $tables = db_find_tables(Database::getActiveConnection()->prefixTables('{simpletest}') . '%');
   $schema = drupal_get_schema_unprocessed('simpletest');
   $ret = array();
   foreach (array_diff_key($tables, $schema) as $table) {
-    db_drop_table($ret, $table);
+    // Strip $db_prefix and skip tables without digets following "simpletest",
+    // e.g. {simpletest_tets_id}.
+    if (preg_match('/simpletest\d+.*/', $table, $reg)) {
+      db_drop_table($ret, $reg[0]);
+    }
   }
 
   if (count($ret) > 0) {
     drupal_set_message(t('Removed @count left over tables.', array('@count' => count($ret))));
   }
   else {
     drupal_set_message(t('No left over tables to remove.'));
   }
 }
Index: modules/simpletest/tests/common.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/simpletest/tests/common.test,v
retrieving revision 1.10
diff -u -9 -p -r1.10 common.test
--- modules/simpletest/tests/common.test	26 Oct 2008 18:06:39 -0000	1.10
+++ modules/simpletest/tests/common.test	1 Nov 2008 13:15:44 -0000
@@ -315,18 +315,19 @@ class JavaScriptTestCase extends DrupalW
       'description' => t("Tests the JavaScript system."),
       'group' => t('System')
     );
   }
   
   /**
    * Implementation of setUp().
    */
   function setUp() {
+    parent::setUp();
     // Reset drupal_add_js() before each test.
     drupal_add_js(NULL, NULL, TRUE);
   }
   
   /**
    * Test default JavaScript is empty.
    */
   function testDefault() {
     $this->assertEqual(array(), drupal_add_js(), t('Default JavaScript is empty.'));
Index: modules/system/system.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/system/system.test,v
retrieving revision 1.22
diff -u -9 -p -r1.22 system.test
--- modules/system/system.test	31 Oct 2008 11:13:31 -0000	1.22
+++ modules/system/system.test	1 Nov 2008 13:15:44 -0000
@@ -112,19 +112,19 @@ class EnableDisableCoreTestCase extends 
 
   /**
    * Assert tables that begin with the specified base table name.
    *
    * @param string $base_table Begginning of table name to look for.
    * @param boolean $count Assert tables that match specified base table.
    * @return boolean Tables with specified base table.
    */
   function assertTableCount($base_table, $count) {
-    $tables = db_find_tables(Database::getActiveConnection()->prefixTables($base_table) . '%');
+    $tables = db_find_tables(Database::getActiveConnection()->prefixTables('{' . $base_table . '}') . '%');
 
     if ($count) {
       return $this->assertTrue($tables, t('Tables matching "@base_table" found.', array('@base_table' => $base_table)));
     }
     return $this->assertFalse($tables, t('Tables matching "@base_table" not found.', array('@base_table' => $base_table)));
   }
 
   /**
    * Assert the list of modules are enabled or disabled.
