=== modified file 'modules/simpletest/drupal_web_test_case.php'
--- modules/simpletest/drupal_web_test_case.php	2008-11-26 13:48:49 +0000
+++ modules/simpletest/drupal_web_test_case.php	2008-11-29 08:42:03 +0000
@@ -771,16 +771,57 @@ class DrupalWebTestCase {
     // Store necessary current values before switching to prefixed database.
     $this->originalPrefix = $db_prefix;
     $clean_url_original = variable_get('clean_url', 0);
+    $db_prefix_registry = Database::getActiveConnection()->prefixTables('{simpletest_all_}');
+    $db_prefix = $db_prefix_registry;
+    if (!db_table_exists('registry')) {
+      $ret = array();
+      // Switch back to the original database to load a few bits of information.
+      $db_prefix = $this->originalPrefix;
+      $modules = module_rebuild_cache();
+      $registry = drupal_get_schema('registry');
+      $registry_file = drupal_get_schema('registry_file');
+      // Now create the registry.
+      $db_prefix = $db_prefix_registry;
+      db_create_table($ret, 'registry', $registry);
+      db_create_table($ret, 'registry_file', $registry_file);
+      // Preload what we already have. This ensures that the database classes
+      // necessary for the merge in registry rebuild can run without a problem.
+      db_query('INSERT INTO {registry} SELECT * FROM ' . $this->originalPrefix .'registry');
+      db_query('INSERT INTO {registry_file} SELECT * FROM ' . $this->originalPrefix . 'registry_file');
+      include_once DRUPAL_ROOT . '/includes/registry.inc';
+      foreach ($modules as $module) {
+        $dir = dirname($module->filename);
+        foreach ($module->info['files'] as $file) {
+          $files["$dir/$file"] = array('module' => $module->name, 'weight' => $module->weight);
+        }
+        foreach (file_scan_directory('includes', '/\.inc$/') as $filename => $file) {
+          $files["$filename"] = array('module' => '', 'weight' => 0);
+        }
+      }
+      _registry_parse_files($files);
+    }
+    $db_prefix = $this->originalPrefix;
 
     // Generate temporary prefixed database to ensure that tests have a clean starting point.
     $db_prefix = Database::getActiveConnection()->prefixTables('{simpletest' . mt_rand(1000, 1000000) . '}');
 
     include_once DRUPAL_ROOT . '/includes/install.inc';
-    drupal_install_system();
-
+    include_once DRUPAL_ROOT . '/modules/system/system.install';
     // 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));
+    // Grab the schema and make sure the registry table are not recreated.
+    $schema = system_schema(TRUE);
+    db_create_table($ret, 'registry', $schema['registry']);
+    db_create_table($ret, 'registry_file', $schema['registry_file']);
+    $registry_modules = array_merge($modules, array(''));
+    $placeholders = implode(', ', array_fill(0, count($registry_modules), '?'));
+    db_query('INSERT INTO {registry} SELECT * FROM ' . $db_prefix_registry .'registry WHERE module IN ('. $placeholders .')', $registry_modules);
+    db_query('INSERT INTO {registry_file} SELECT DISTINCT rf.* FROM ' . $db_prefix_registry . 'registry r INNER JOIN ' . $db_prefix_registry . 'registry_file rf USING(filename) WHERE module IN (' . $placeholders . ')', $registry_modules);
+    drupal_install_system();
+    // Reset the system schema.
+    system_schema(FALSE);
+
     drupal_install_modules($modules);
 
     // Because the schema is static cached, we need to flush

=== modified file 'modules/system/system.install'
--- modules/system/system.install	2008-11-25 13:16:38 +0000
+++ modules/system/system.install	2008-11-29 08:39:54 +0000
@@ -420,7 +420,8 @@ function system_install() {
 /**
  * Implementation of hook_schema().
  */
-function system_schema() {
+function system_schema($registry_set = NULL) {
+  static $registry_done = FALSE;
   // NOTE: {variable} needs to be created before all other tables, as
   // some database drivers, e.g. Oracle and DB2, will require variable_get()
   // and variable_set() for overcoming some database specific limitations.
@@ -1053,74 +1054,79 @@ function system_schema() {
     'primary key' => array('mlid'),
   );
 
-  $schema['registry'] = array(
-    'description' => "Each record is a function, class, or interface name and the file it is in.",
-    'fields' => array(
-      'name'   => array(
-        'description' => 'The name of the function, class, or interface.',
-        'type' => 'varchar',
-        'length' => 255,
-        'not null' => TRUE,
-        'default' => '',
-      ),
-      'type'   => array(
-        'description' => 'Either function or class or interface.',
-        'type' => 'varchar',
-        'length' => 9,
-        'not null' => TRUE,
-        'default' => '',
-      ),
-      'filename'   => array(
-        'description' => 'Name of the file.',
-        'type' => 'varchar',
-        'length' => 255,
-        'not null' => TRUE,
-      ),
-      'module' => array(
-        'description' => 'Name of the module the file belongs to.',
-        'type' => 'varchar',
-        'length' => 255,
-        'not null' => TRUE,
-        'default' => ''
-      ),
-      'suffix' => array(
-        'description' => "The part of the function name after the module, which is the hook this function implements, if any.",
-        'type' => 'varchar',
-        'length' => 68,
-        'not null' => TRUE,
-        'default' => ''
-      ),
-      'weight' => array(
-        'description' => "The order in which this module's hooks should be invoked relative to other modules. Equal-weighted modules are ordered by name.",
-        'type' => 'int',
-        'not null' => TRUE,
-        'default' => 0,
+  if (!$registry_done) {
+    $schema['registry'] = array(
+      'description' => "Each record is a function, class, or interface name and the file it is in.",
+      'fields' => array(
+        'name'   => array(
+          'description' => 'The name of the function, class, or interface.',
+          'type' => 'varchar',
+          'length' => 255,
+          'not null' => TRUE,
+          'default' => '',
+        ),
+        'type'   => array(
+          'description' => 'Either function or class or interface.',
+          'type' => 'varchar',
+          'length' => 9,
+          'not null' => TRUE,
+          'default' => '',
+        ),
+        'filename'   => array(
+          'description' => 'Name of the file.',
+          'type' => 'varchar',
+          'length' => 255,
+          'not null' => TRUE,
+        ),
+        'module' => array(
+          'description' => 'Name of the module the file belongs to.',
+          'type' => 'varchar',
+          'length' => 255,
+          'not null' => TRUE,
+          'default' => ''
+        ),
+        'suffix' => array(
+          'description' => "The part of the function name after the module, which is the hook this function implements, if any.",
+          'type' => 'varchar',
+          'length' => 68,
+          'not null' => TRUE,
+          'default' => ''
+        ),
+        'weight' => array(
+          'description' => "The order in which this module's hooks should be invoked relative to other modules. Equal-weighted modules are ordered by name.",
+          'type' => 'int',
+          'not null' => TRUE,
+          'default' => 0,
+        ),
+      ),
+      'primary key' => array('name', 'type'),
+      'indexes' => array(
+        'hook' => array('type', 'suffix', 'weight', 'module'),
       ),
-    ),
-    'primary key' => array('name', 'type'),
-    'indexes' => array(
-      'hook' => array('type', 'suffix', 'weight', 'module'),
-    ),
-  );
+    );
 
-  $schema['registry_file'] = array(
-    'description' => "Files parsed to build the registry.",
-    'fields' => array(
-      'filename'   => array(
-        'description' => 'Path to the file.',
-        'type' => 'varchar',
-        'length' => 255,
-        'not null' => TRUE,
-      ),
-      'md5'  => array(
-        'description' => "Md5 hash of the file's contents when last parsed.",
-        'type' => 'varchar',
-        'length' => 32,
-        'not null' => TRUE,
+    $schema['registry_file'] = array(
+      'description' => "Files parsed to build the registry.",
+      'fields' => array(
+        'filename'   => array(
+          'description' => 'Path to the file.',
+          'type' => 'varchar',
+          'length' => 255,
+          'not null' => TRUE,
+        ),
+        'md5'  => array(
+          'description' => "Md5 hash of the file's contents when last parsed.",
+          'type' => 'varchar',
+          'length' => 32,
+          'not null' => TRUE,
+        ),
       ),
-    ),
-    'primary key' => array('filename'),
-  );
+      'primary key' => array('filename'),
+    );
+  }
+  if (isset($registry_set)) {
+    $registry_done = $registry_set;
+  }
 
   $schema['sessions'] = array(
     'description' => "Drupal's session handlers read and write into the sessions table. Each record represents a user session, either anonymous or authenticated.",

