diff -u b/core/modules/system/lib/Drupal/system/Tests/System/ShutdownFunctionsTest.php b/core/modules/system/lib/Drupal/system/Tests/System/ShutdownFunctionsTest.php --- b/core/modules/system/lib/Drupal/system/Tests/System/ShutdownFunctionsTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/System/ShutdownFunctionsTest.php @@ -36,13 +36,19 @@ $arg1 = $this->randomName(); $arg2 = $this->randomName(); $this->drupalGet('system-test/shutdown-functions/' . $arg1 . '/' . $arg2); - $this->assertEqual(\Drupal::state()->get('_system_test_first_shutdown_function'), array($arg1, $arg2)); - $this->assertEqual(\Drupal::state()->get('_system_test_second_shutdown_function'), array($arg1, $arg2)); // If using PHP-FPM then fastcgi_finish_request() will have been fired - // preventing further output to the browser. + // returning the response before shutdown functions have fired. // @see \Drupal\system_test\Controller\SystemTestController::shutdownFunctions() - if (strpos($this->drupalGetContent(), 'The function fastcgi_finish_request exists when serving the request.') === FALSE) { + $server_using_fastcgi = strpos($this->drupalGetContent(), 'The function fastcgi_finish_request exists when serving the request.'); + if ($server_using_fastcgi) { + // We need to wait to ensure that the shutdown functions have fired. + sleep(1); + } + $this->assertEqual(\Drupal::state()->get('_system_test_first_shutdown_function'), array($arg1, $arg2)); + $this->assertEqual(\Drupal::state()->get('_system_test_second_shutdown_function'), array($arg1, $arg2)); + + if (!$server_using_fastcgi) { // Make sure exceptions displayed through // \Drupal\Core\Utility\Error::renderExceptionSafe() are correctly // escaped.