Mercurial > hg > cmmr2012-drupal-site
annotate core/modules/dblog/tests/src/Functional/ConnectionFailureTest.php @ 0:c75dbcec494b
Initial commit from drush-created site
author | Chris Cannam |
---|---|
date | Thu, 05 Jul 2018 14:24:15 +0000 |
parents | |
children |
rev | line source |
---|---|
Chris@0 | 1 <?php |
Chris@0 | 2 |
Chris@0 | 3 namespace Drupal\Tests\dblog\Functional; |
Chris@0 | 4 |
Chris@0 | 5 use Drupal\Core\Database\Database; |
Chris@0 | 6 use Drupal\Tests\BrowserTestBase; |
Chris@0 | 7 |
Chris@0 | 8 /** |
Chris@0 | 9 * Tests logging of connection failures. |
Chris@0 | 10 * |
Chris@0 | 11 * @group dblog |
Chris@0 | 12 */ |
Chris@0 | 13 class ConnectionFailureTest extends BrowserTestBase { |
Chris@0 | 14 |
Chris@0 | 15 public static $modules = ['dblog']; |
Chris@0 | 16 |
Chris@0 | 17 /** |
Chris@0 | 18 * Tests logging of connection failures. |
Chris@0 | 19 */ |
Chris@0 | 20 public function testConnectionFailureLogging() { |
Chris@0 | 21 $logger = \Drupal::service('logger.factory'); |
Chris@0 | 22 |
Chris@0 | 23 // MySQL errors like "1153 - Got a packet bigger than 'max_allowed_packet' |
Chris@0 | 24 // bytes" or "1100 - Table 'xyz' was not locked with LOCK TABLES" lead to a |
Chris@0 | 25 // database connection unusable for further requests. All further request |
Chris@0 | 26 // will result in an "2006 - MySQL server had gone away" error. As a |
Chris@0 | 27 // consequence it's impossible to use this connection to log the causing |
Chris@0 | 28 // initial error itself. Using Database::closeConnection() we simulate such |
Chris@0 | 29 // a corrupted connection. In this case dblog has to establish a different |
Chris@0 | 30 // connection by itself to be able to write the log entry. |
Chris@0 | 31 Database::closeConnection(); |
Chris@0 | 32 |
Chris@0 | 33 // Create a log entry. |
Chris@0 | 34 $logger->get('php')->error('testConnectionFailureLogging'); |
Chris@0 | 35 |
Chris@0 | 36 // Re-establish the default database connection. |
Chris@0 | 37 Database::getConnection(); |
Chris@0 | 38 |
Chris@0 | 39 $wid = db_query("SELECT MAX(wid) FROM {watchdog} WHERE message = 'testConnectionFailureLogging'")->fetchField(); |
Chris@0 | 40 $this->assertTrue($wid, 'Watchdog entry has been stored in database.'); |
Chris@0 | 41 } |
Chris@0 | 42 |
Chris@0 | 43 } |