(NFC) LoggingDetailTest - Improve reliability of test
authorTim Otten <totten@civicrm.org>
Wed, 2 Mar 2022 01:51:00 +0000 (17:51 -0800)
committerTim Otten <totten@civicrm.org>
Wed, 2 Mar 2022 01:51:00 +0000 (17:51 -0800)
Before
-----------------

If you run this test repeatedly, it may alternately pass and fail.  The
percentage of passes-vs-fails can vary widely (depending on the computer
where you execute).

To test this, I went to a deployment (on `test-3`) which had a fairly
high probability of failure (*failure in roughly 3/4 invocations*).

After
-----------------

On the same system, it passes consistently (*no failures after 15 invocations*).

tests/phpunit/CRM/Report/Form/Contact/LoggingDetailTest.php

index 0f812befb9795c3aceec3f6da24dd59871640832..67c7171994275ba3914a0e8ed8135b0ac7af6d97 100644 (file)
@@ -22,8 +22,14 @@ class CRM_Report_Form_Contact_LoggingDetailTest extends CiviReportTestCase {
 
   public function setUp(): void {
     parent::setUp();
+
+    // Setup logging. This may create a series of backfilled log records.
     $this->callAPISuccess('Setting', 'create', ['logging' => TRUE]);
     $this->quickCleanup($this->_tablesToTruncate);
+
+    // The test needs to create+read some log records. We want this to have a new/separate `log_conn_id`.
+    unset(\Civi::$statics['CRM_Utils_Request']['id']);
+    CRM_Core_DAO::init(CIVICRM_DSN);
   }
 
   public function tearDown(): void {