Commit 45663e48 authored by catch's avatar catch
Browse files

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

(cherry picked from commit 90f0da7b)
parent bc8b4067
Loading
Loading
Loading
Loading
+8 −10
Original line number Diff line number Diff line
@@ -28,18 +28,16 @@ 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>.', [
        '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',
        ]),
      ];
    }
  }
  }

  return $requirements;
}
+10 −7
Original line number Diff line number Diff line
@@ -45,28 +45,31 @@ public function testIsolationLevelWarningNotDisplaying() {
    ]);
    $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'));
  }

  /**