Index: modules/simpletest/drupal_web_test_case.php
===================================================================
RCS file: /cvs/drupal/drupal/modules/simpletest/drupal_web_test_case.php,v
retrieving revision 1.9
diff -u -r1.9 drupal_web_test_case.php
--- modules/simpletest/drupal_web_test_case.php	26 May 2008 17:36:08 -0000	1.9
+++ modules/simpletest/drupal_web_test_case.php	27 May 2008 19:23:39 -0000
@@ -16,7 +16,8 @@
   protected $cookie_file = NULL;
   // Overwrite this any time to supply cURL options as necessary,
   // DrupalTestCase itself never sets this but always obeys whats set.
-  protected $curl_options         = array();
+  protected $curl_options = array();
+  protected $db_prefix_original;
   protected $original_file_directory;
 
   /**
@@ -356,20 +357,35 @@
    */
   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);
     include_once './includes/install.inc';
     drupal_install_system();
+
+    // Add the specified modules to the list of modules in the default profile.
     $modules = array_unique(array_merge(func_get_args(), drupal_verify_profile('default', 'en')));
     drupal_install_modules($modules);
+
+    // Store the list of modules for use in subsequent drupalModuleEnable calls.
     $this->_modules = drupal_map_assoc($modules);
     $this->_modules['system'] = 'system';
+
+    // Run defualt profile tasks.
     $task = 'profile';
     default_profile_tasks($task, '');
+
+    // Rebuild caches.
     menu_rebuild();
     actions_synchronize();
     _drupal_flush_css_js();
+    $this->refreshVariables();
+
+    // Restore necessary variables.
     variable_set('install_profile', 'default');
     variable_set('install_task', 'profile-finished');
     variable_set('clean_url', $clean_url_original);
@@ -378,10 +394,29 @@
     $this->original_file_directory = file_directory_path();
     variable_set('file_directory_path', file_directory_path() . '/' . $db_prefix);
     file_check_directory(file_directory_path(), TRUE); // Create the files directory.
+
     parent::setUp();
   }
 
   /**
+   * Refresh the in-memory set of variables. Useful after a page request is made
+   * that changes a variable in a different thread.
+   *
+   * In other words calling a settings page with $this->drupalPost() with a changed
+   * value would update a variable to reflect that change, but in the thread that
+   * made the call (thread running the test) the changed variable would not be
+   * picked up.
+   *
+   * This method clears the variables cache and loads a fresh copy from the database
+   * to ensure that the most up-to-date set of variables is loaded.
+   */
+  function refreshVariables() {
+    global $conf;
+    cache_clear_all('variables', 'cache');
+    $conf = variable_init();
+  }
+
+  /**
    * Delete created files and temporary files directory, delete the tables created by setUp(),
    * and reset the database prefix.
    */
@@ -392,13 +427,20 @@
       simpletest_clean_temporary_directory(file_directory_path());
       variable_set('file_directory_path', $this->original_file_directory);
 
+      // Remove all prefixed tables (all the tables in the schema).
       $schema = drupal_get_schema(NULL, TRUE);
       $ret = array();
       foreach ($schema as $name => $table) {
         db_drop_table($ret, $name);
       }
+
+      // Return the database prefix to the original.
       $db_prefix = $this->db_prefix_original;
+
+      // Ensure that the internal logged in variable is reset.
       $this->_logged_in = FALSE;
+
+      // Close the CURL handler.
       $this->curlClose();
     }
     parent::tearDown();
@@ -510,7 +552,9 @@
     // We re-using a CURL connection here.  If that connection still has certain
     // options set, it might change the GET into a POST.  Make sure we clear out
     // previous options.
-    return $this->curlExec(array(CURLOPT_URL => url($path, $options), CURLOPT_POST => FALSE, CURLOPT_POSTFIELDS => array()));
+    $out = $this->curlExec(array(CURLOPT_URL => url($path, $options), CURLOPT_POST => FALSE, CURLOPT_POSTFIELDS => array()));
+    $this->refreshVariables(); // Ensure that any changes to variables in the other thread are picked up.
+    return $out;
   }
 
   /**
@@ -579,7 +623,9 @@
             }
             $post = implode('&', $post);
           }
-          return $this->curlExec(array(CURLOPT_URL => $action, CURLOPT_POSTFIELDS => $post, CURLOPT_POST => TRUE));
+          $out = $this->curlExec(array(CURLOPT_URL => $action, CURLOPT_POSTFIELDS => $post, CURLOPT_POST => TRUE));
+          $this->refreshVariables(); // Ensure that any changes to variables in the other thread are picked up.
+          return $out;
         }
       }
       // We have not found a form which contained all fields of $edit.
Index: modules/contact/contact.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/contact/contact.test,v
retrieving revision 1.2
diff -u -r1.2 contact.test
--- modules/contact/contact.test	25 Apr 2008 18:26:01 -0000	1.2
+++ modules/contact/contact.test	27 May 2008 19:23:38 -0000
@@ -36,8 +36,6 @@
     $this->drupalPost('admin/build/contact/settings', $edit, t('Save configuration'));
     $this->assertText(t('The configuration options have been saved.'), t('Setting successfully saved.'));
 
-    $this->reloadVariables();
-
     // Delete old categories to ensure that new categories are used.
     $this->deleteCategories();
 
@@ -127,7 +125,6 @@
 
     // Reload variables.
     $this->drupalLogout();
-    $this->reloadVariables();
 
     // Create web users and attempt to use personal contact forms with default set to true.
     $web_user1 = $this->drupalCreateUser(array());
@@ -156,7 +153,6 @@
 
     // Reload variables.
     $this->drupalLogout();
-    $this->reloadVariables();
 
     // Create web users and attempt to use personal contact forms with default set to false.
     $web_user3 = $this->drupalCreateUser(array());
@@ -252,15 +248,4 @@
     $this->drupalPost('admin/user/permissions', $edit, t('Save permissions'));
     $this->assertText(t('The changes have been saved.'), t(' [permission] Saved changes.'));
   }
-
-  /**
-   * Reload variables table.
-   */
-  function reloadVariables() {
-    global $conf;
-
-    cache_clear_all('variables', 'cache');
-    $conf = variable_init();
-    $this->assertTrue($conf, t('Variables reloaded.'));
-  }
 }
Index: modules/dblog/dblog.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/dblog/dblog.test,v
retrieving revision 1.3
diff -u -r1.3 dblog.test
--- modules/dblog/dblog.test	26 May 2008 17:31:59 -0000	1.3
+++ modules/dblog/dblog.test	27 May 2008 19:23:39 -0000
@@ -55,8 +55,7 @@
     $edit['dblog_row_limit'] = $row_limit;
     $this->drupalPost('admin/settings/logging/dblog', $edit, t('Save configuration'));
     $this->assertResponse(200);
-    // Reload variable cache (since the global $conf array was changed in another "process" when the settings page above was posted).
-    $this->reloadVariables();
+
     // Check row limit variable.
     $current_limit = variable_get('dblog_row_limit', 1000);
     $this->assertTrue($current_limit == $row_limit, t('[Cache] Row limit variable of @count equals row limit of @limit', array('@count' => $current_limit, '@limit' => $row_limit)));
@@ -356,15 +355,4 @@
     }
     return $content;
   }
-
-  /**
-   * Reload variables table.
-   */
-  private function reloadVariables() {
-    global $conf;
-
-    cache_clear_all('variables', 'cache');
-    $conf = variable_init();
-    $this->assertTrue($conf, t('Variables reloaded'));
-  }
 }
