Skip to content
Snippets Groups Projects
Commit 1b584005 authored by catch's avatar catch
Browse files

Issue #2157053 by alexpott, twistor, dawehner, sun: Ensure...

Issue #2157053 by alexpott, twistor, dawehner, sun: Ensure register_shutdown_function() works with php-fpm (blocks testbot php-fpm).
parent 580dd44a
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
......@@ -2585,12 +2585,16 @@ function _drupal_shutdown_function() {
}
}
catch (Exception $exception) {
// If we are displaying errors, then do so with no possibility of a further
// uncaught exception being thrown.
require_once __DIR__ . '/errors.inc';
if (error_displayable()) {
print '<h1>Uncaught exception thrown in shutdown function.</h1>';
print '<p>' . Error::renderExceptionSafe($exception) . '</p><hr />';
// If using PHP-FPM then fastcgi_finish_request() will have been fired
// preventing further output to the browser.
if (!function_exists('fastcgi_finish_request')) {
// If we are displaying errors, then do so with no possibility of a
// further uncaught exception being thrown.
require_once __DIR__ . '/errors.inc';
if (error_displayable()) {
print '<h1>Uncaught exception thrown in shutdown function.</h1>';
print '<p>' . Error::renderExceptionSafe($exception) . '</p><hr />';
}
}
error_log($exception);
}
......
......@@ -36,11 +36,23 @@ function testShutdownFunctions() {
$arg1 = $this->randomName();
$arg2 = $this->randomName();
$this->drupalGet('system-test/shutdown-functions/' . $arg1 . '/' . $arg2);
$this->assertText(t('First shutdown function, arg1 : @arg1, arg2: @arg2', array('@arg1' => $arg1, '@arg2' => $arg2)));
$this->assertText(t('Second shutdown function, arg1 : @arg1, arg2: @arg2', array('@arg1' => $arg1, '@arg2' => $arg2)));
// Make sure exceptions displayed through
// \Drupal\Core\Utility\Error::renderExceptionSafe() are correctly escaped.
$this->assertRaw('Drupal is &lt;blink&gt;awesome&lt;/blink&gt;.');
// If using PHP-FPM then fastcgi_finish_request() will have been fired
// returning the response before shutdown functions have fired.
// @see \Drupal\system_test\Controller\SystemTestController::shutdownFunctions()
$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.
$this->assertRaw('Drupal is &lt;blink&gt;awesome&lt;/blink&gt;.');
}
}
}
......@@ -68,6 +68,14 @@ public function setHeader() {
*/
public function shutdownFunctions($arg1, $arg2) {
system_test_page_shutdown_functions($arg1, $arg2);
// If using PHP-FPM then fastcgi_finish_request() will have been fired
// preventing further output to the browser which means that the escaping of
// the exception message can not be tested.
// @see _drupal_shutdown_function()
// @see \Drupal\system\Tests\System\ShutdownFunctionsTest
if (function_exists('fastcgi_finish_request')) {
return 'The function fastcgi_finish_request exists when serving the request.';
}
}
}
......@@ -140,9 +140,8 @@ function system_test_page_shutdown_functions($arg1, $arg2) {
* Dummy shutdown function which registers another shutdown function.
*/
function _system_test_first_shutdown_function($arg1, $arg2) {
// Output something, page has already been printed and the session stored
// so we can't use drupal_set_message.
print t('First shutdown function, arg1 : @arg1, arg2: @arg2', array('@arg1' => $arg1, '@arg2' => $arg2));
// Set something to ensure that this function got called.
\Drupal::state()->set('_system_test_first_shutdown_function', array($arg1, $arg2));
drupal_register_shutdown_function('_system_test_second_shutdown_function', $arg1, $arg2);
}
......@@ -150,14 +149,13 @@ function _system_test_first_shutdown_function($arg1, $arg2) {
* Dummy shutdown function.
*/
function _system_test_second_shutdown_function($arg1, $arg2) {
// Output something, page has already been printed and the session stored
// so we can't use drupal_set_message.
print t('Second shutdown function, arg1 : @arg1, arg2: @arg2', array('@arg1' => $arg1, '@arg2' => $arg2));
// Set something to ensure that this function got called.
\Drupal::state()->set('_system_test_second_shutdown_function', array($arg1, $arg2));
// Throw an exception with an HTML tag. Since this is called in a shutdown
// function, it will not bubble up to the default exception handler but will
// be caught in _drupal_shutdown_function() and be displayed through
// \Drupal\Core\Utility\Error::renderExceptionSafe().
// \Drupal\Core\Utility\Error::renderExceptionSafe() if possible.
throw new Exception('Drupal is <blink>awesome</blink>.');
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment