From 1ced3a1f92e49debc44ef50fd54011b625d0887d Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Sun, 19 Mar 2023 15:52:08 -0700 Subject: [PATCH] CiviUnitTestCase - Allow relaxed enforcement on older DBMS --- tests/phpunit/CiviTest/CiviUnitTestCase.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/tests/phpunit/CiviTest/CiviUnitTestCase.php b/tests/phpunit/CiviTest/CiviUnitTestCase.php index 4e05b093cd..41f670d88b 100644 --- a/tests/phpunit/CiviTest/CiviUnitTestCase.php +++ b/tests/phpunit/CiviTest/CiviUnitTestCase.php @@ -453,8 +453,15 @@ class CiviUnitTestCase extends PHPUnit\Framework\TestCase { $this->quickCleanup($tablesToTruncate); $this->createDomainContacts(); } - $releasedLocks = CRM_Core_DAO::singleValueQuery('SELECT RELEASE_ALL_LOCKS()'); - $this->assertEquals(0, $releasedLocks, "The test should not leave any dangling locks. Found $releasedLocks"); + + // If a test leaks an extraneous hold on a lock, then we want that test to fail (rather than + // proceeding and causing spooky effects on other tests). + $dbVer = CRM_Utils_SQL::getDatabaseVersion(); + if (!preg_match('/maria/i', $dbVer) || version_compare($dbVer, '10.5.2', '>=')) { + // Supported by MySQL 5.7+ or MariaDB 10.5.2+. These provide some herd immunity. + $releasedLocks = CRM_Core_DAO::singleValueQuery('SELECT RELEASE_ALL_LOCKS()'); + $this->assertEquals(0, $releasedLocks, "The test should not leave any dangling locks. Found $releasedLocks"); + } $this->cleanTempDirs(); $this->unsetExtensionSystem(); -- 2.25.1