Index: includes/bootstrap.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/bootstrap.inc,v
retrieving revision 1.340
diff -u -p -r1.340 bootstrap.inc
--- includes/bootstrap.inc	7 Jan 2010 04:54:18 -0000	1.340
+++ includes/bootstrap.inc	14 Jan 2010 15:53:53 -0000
@@ -1498,7 +1498,7 @@ function drupal_bootstrap($phase = NULL,
   static $final_phase;
   // Not drupal_static(), because it's impossible to roll back to an earlier
   // bootstrap state.
-  static $completed_phase = -1;
+  static $stored_phase = -1;
 
   // When not recursing, store the phase name so it's not forgotten while
   // recursing.
@@ -1508,8 +1508,15 @@ function drupal_bootstrap($phase = NULL,
   if (isset($phase)) {
     // Call a phase if it has not been called before and is below the requested
     // phase.
-    while ($phases && $phase > $completed_phase && $final_phase > $completed_phase) {
+    while ($phases && $phase > $stored_phase && $final_phase > $stored_phase) {
       $current_phase = array_shift($phases);
+
+      // This function is re-entrant. Only update the completed phase when the
+      // current call actually resulted in a progress in the bootstrap process.
+      if ($current_phase > $stored_phase) {
+        $stored_phase = $current_phase;
+      }
+
       switch ($current_phase) {
         case DRUPAL_BOOTSTRAP_CONFIGURATION:
           _drupal_bootstrap_configuration();
@@ -1545,14 +1552,9 @@ function drupal_bootstrap($phase = NULL,
           _drupal_bootstrap_full();
           break;
       }
-      // This function is reentrant. Only update the completed phase when the
-      // current call actually resulted in a progress in the bootstrap process.
-      if ($current_phase > $completed_phase) {
-        $completed_phase = $current_phase;
-      }
     }
   }
-  return $completed_phase;
+  return $stored_phase;
 }
 
 /**
Index: modules/simpletest/tests/bootstrap.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/simpletest/tests/bootstrap.test,v
retrieving revision 1.27
diff -u -p -r1.27 bootstrap.test
--- modules/simpletest/tests/bootstrap.test	5 Jan 2010 18:00:14 -0000	1.27
+++ modules/simpletest/tests/bootstrap.test	14 Jan 2010 15:53:54 -0000
@@ -413,3 +413,30 @@ class BootstrapResettableStaticTestCase 
     $this->assertEqual($var, 'foo', t('Variable was reset after second invocation of global reset.'));
   }
 }
+
+/**
+ * Test that drupal_get_bootstrap_phase() returns the current bootstrap phase.
+ */
+class BootstrapPhaseTestCase extends DrupalWebTestCase {
+
+  public static function getInfo() {
+    return array(
+      'name' => 'Bootstrap phase',
+      'description' => 'Tests that drupal_bootstrap_phase() returns the current phase .',
+      'group' => 'Bootstrap',
+    );
+  }
+
+  function setUp() {
+    parent::setUp('system_test');
+  }
+
+  /**
+   * Confirm that calling drupal_bootstrap_phase() during hook_init()
+   * returns DRUPAL_BOOTSTRAP_FULL
+   */
+  function testDrupalBootstrapPhase() {
+    $this->drupalGet('');
+    $this->assertText(t('Current bootstrap phase is @phase', array('@phase' => DRUPAL_BOOTSTRAP_FULL)), t('Bootstrap phase is returned correctly.'));
+  }
+}
Index: modules/simpletest/tests/system_test.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/simpletest/tests/system_test.module,v
retrieving revision 1.24
diff -u -p -r1.24 system_test.module
--- modules/simpletest/tests/system_test.module	8 Jan 2010 06:36:34 -0000	1.24
+++ modules/simpletest/tests/system_test.module	14 Jan 2010 15:53:54 -0000
@@ -192,6 +192,14 @@ function system_test_init() {
   if (variable_get('front_page_output', 0) && drupal_is_front_page()) {
     drupal_set_message(t('On front page.'));
   }
+
+  // Used by BootstrapPhaseTestCase to show the current bootstrap phase.
+  // Only show this when page caching is off to avoid interfering with the
+  // hook_boot() and hook_exit() test cases, since drupal_set_message()
+  // suppresses caching.
+  if (!variable_get('cache', FALSE)) {
+    drupal_set_message(t('Current bootstrap phase is @phase', array('@phase' => drupal_get_bootstrap_phase())));
+  }
 }
 
 /**
