Index: includes/install.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/install.inc,v
retrieving revision 1.90
diff -u -p -r1.90 install.inc
--- includes/install.inc	12 May 2009 18:08:42 -0000	1.90
+++ includes/install.inc	15 May 2009 20:29:29 -0000
@@ -491,10 +491,8 @@ function drupal_verify_profile($profile,
  *
  * @param $module_list
  *   The modules to install.
- * @param $disable_modules_installed_hook
- *   Normally just testing wants to set this to TRUE.
  */
-function drupal_install_modules($module_list = array(), $disable_modules_installed_hook = FALSE) {
+function drupal_install_modules($module_list = array()) {
   $files = module_rebuild_cache();
   $module_list = array_flip(array_values($module_list));
   do {
@@ -514,7 +512,7 @@ function drupal_install_modules($module_
   asort($module_list);
   $module_list = array_keys($module_list);
   $modules_installed = array_filter($module_list, '_drupal_install_module');
-  if (!$disable_modules_installed_hook && !empty($modules_installed)) {
+  if (!empty($modules_installed)) {
     module_invoke_all('modules_installed', $modules_installed);
   }
   module_enable($module_list);
Index: includes/registry.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/registry.inc,v
retrieving revision 1.15
diff -u -p -r1.15 registry.inc
--- includes/registry.inc	10 May 2009 16:46:23 -0000	1.15
+++ includes/registry.inc	15 May 2009 20:29:29 -0000
@@ -37,6 +37,12 @@ function _registry_rebuild() {
   require_once DRUPAL_ROOT . '/includes/database/select.inc';
   require_once DRUPAL_ROOT . '/includes/database/' . $driver . '/query.inc';
 
+  // When running in SimpleTest mode, we preload the child registry using what
+  // we already know from the parent registry.
+  if (class_exists('DrupalWebTestCase', FALSE) && ($instance = DrupalWebTestCase::currentlyRunning())) {
+    $instance->preloadRegistry();
+  }
+
   // Reset the resources cache.
   _registry_get_resource_name();
 
Index: modules/simpletest/drupal_web_test_case.php
===================================================================
RCS file: /cvs/drupal/drupal/modules/simpletest/drupal_web_test_case.php,v
retrieving revision 1.103
diff -u -p -r1.103 drupal_web_test_case.php
--- modules/simpletest/drupal_web_test_case.php	3 May 2009 20:01:11 -0000	1.103
+++ modules/simpletest/drupal_web_test_case.php	15 May 2009 20:29:29 -0000
@@ -99,6 +99,17 @@ class DrupalWebTestCase {
   protected $originalUser = NULL;
 
   /**
+   * The instance of the currently running DrupalWebTestCase.
+   */
+  protected static $this_instance = NULL;
+
+  /**
+   * Indicate to DrupalWebTestCase::preloadRegistry() that it is safe to
+   * preload the registry of the child site with information from the parent site.
+   */
+  protected $canPreloadRegistry = FALSE;
+
+  /**
    * Current results of this test case.
    *
    * @var Array
@@ -126,6 +137,12 @@ class DrupalWebTestCase {
    */
   protected $httpauth_credentials = NULL;
 
+  /**
+   * Get the currently running DrupalWebTestCase, if any.
+   */
+  public static function currentlyRunning() {
+    return self::$this_instance;
+  }
 
   /**
    * Constructor for DrupalWebTestCase.
@@ -867,15 +884,24 @@ class DrupalWebTestCase {
     // Generate temporary prefixed database to ensure that tests have a clean starting point.
     $db_prefix = Database::getConnection()->prefixTables('{simpletest' . mt_rand(1000, 1000000) . '}');
 
+    // Register this instance as the currently running one.
+    self::$this_instance = $this;
+
     include_once DRUPAL_ROOT . '/includes/install.inc';
     drupal_install_system();
 
-    $this->preloadRegistry();
+    // It is now useful to preload the child registry site with information
+    // from the parent registry.
+    $this->canPreloadRegistry = TRUE;
 
     // 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, TRUE);
+    drupal_install_modules($modules);
+
+    // At this point, we don't want that latter calls to registry_rebuild use
+    // preloading, because it would be inefficient.
+    $this->canPreloadRegistry = FALSE;
 
     // Because the schema is static cached, we need to flush
     // it between each run. If we don't, then it will contain
@@ -914,13 +940,17 @@ class DrupalWebTestCase {
   }
 
   /**
-   * This method is called by DrupalWebTestCase::setUp, and preloads the
+   * This method is called by _registry_rebuild(), and preloads the
    * registry from the testing site to cut down on the time it takes to
    * setup a clean environment for the current test run.
    */
-  protected function preloadRegistry() {
-    db_query('INSERT INTO {registry} SELECT * FROM ' . $this->originalPrefix . 'registry');
-    db_query('INSERT INTO {registry_file} SELECT * FROM ' . $this->originalPrefix . 'registry_file');
+  public function preloadRegistry() {
+    if ($this->canPreloadRegistry) {
+      db_delete('registry')->execute();
+      db_delete('registry_file')->execute();
+      db_query('INSERT INTO {registry} SELECT * FROM ' . $this->originalPrefix . 'registry');
+      db_query('INSERT INTO {registry_file} SELECT * FROM ' . $this->originalPrefix . 'registry_file');
+    }
   }
 
   /**
