Issue #3291949 by alexpott, daffie: Improve the MySQL transaction isolation warning

(cherry picked from commit 90f0da7baf)
merge-requests/2498/head
catch 2022-07-10 17:33:48 +09:00
parent cd46ba5787
commit 0e72178047
2 changed files with 18 additions and 17 deletions

View File

@ -28,16 +28,14 @@ function mysql_requirements($phase) {
$isolation_level = $connection->query($query)->fetchField();
if ($isolation_level !== 'READ-COMMITTED') {
$requirements['mysql_transaction_level'] = [
'title' => t('Database Isolation Level'),
'severity' => REQUIREMENT_WARNING,
'value' => t('Transaction Isolation Level: @value', ['@value' => $isolation_level]),
'description' => t('For the best performance and to minimize locking issues, the READ-COMMITTED transaction isolation level is <a href=":performance_doc">recommended</a>.', [
':performance_doc' => 'https://www.drupal.org/docs/system-requirements/setting-the-mysql-transaction-isolation-level',
]),
];
}
$requirements['mysql_transaction_level'] = [
'title' => t('Database Isolation Level'),
'severity' => $isolation_level === 'READ-COMMITTED' ? REQUIREMENT_OK : REQUIREMENT_WARNING,
'value' => $isolation_level,
'description' => t('For the best performance and to minimize locking issues, the READ-COMMITTED transaction isolation level is recommended. See the <a href=":performance_doc">setting MySQL transaction isolation level</a> page for more information.', [
':performance_doc' => 'https://www.drupal.org/docs/system-requirements/setting-the-mysql-transaction-isolation-level',
]),
];
}
}

View File

@ -45,28 +45,31 @@ class RequirementsTest extends BrowserTestBase {
]);
$this->drupalLogin($admin_user);
// Change the isolation level to force the warning message.
// Set the isolation level to a level that produces a warning.
$this->writeIsolationLevelSettings('REPEATABLE READ');
// Check if the warning message is being displayed.
// Check the message is not a warning.
$this->drupalGet('admin/reports/status');
$elements = $this->xpath('//details[@class="system-status-report__entry"]//div[contains(text(), :text)]', [
':text' => 'For the best performance and to minimize locking issues, the READ-COMMITTED',
]);
$this->assertCount(1, $elements);
$this->assertStringStartsWith('Transaction Isolation Level', $elements[0]->getParent()->getText());
$this->assertStringStartsWith('REPEATABLE-READ', $elements[0]->getParent()->getText());
// Ensure it is a warning.
$this->assertStringContainsString('warning', $elements[0]->getParent()->getParent()->find('css', 'summary')->getAttribute('class'));
// Rollback the isolation level to read committed.
$this->writeIsolationLevelSettings('READ COMMITTED');
// Check if the warning message is gone.
// Check the message is not a warning.
$this->drupalGet('admin/reports/status');
$this->assertSession()->pageTextNotContains('Database Isolation Level');
$elements = $this->xpath('//details[@class="system-status-report__entry"]//div[contains(text(), :text)]', [
':text' => 'For the best performance and to minimize locking issues, the READ-COMMITTED',
]);
$this->assertCount(0, $elements);
$this->assertCount(1, $elements);
$this->assertStringStartsWith('READ-COMMITTED', $elements[0]->getParent()->getText());
// Ensure it is a not a warning.
$this->assertStringNotContainsString('warning', $elements[0]->getParent()->getParent()->find('css', 'summary')->getAttribute('class'));
}
/**