Page MenuHomeIn-Portal Phabricator

INP-1889 - Don't use DB Load Balancer during PHPUnit Testing
AcceptedPublic

Authored by alex on Nov 25 2024, 10:19 AM.

Details

Reviewers
erik
Test Plan
  1. in the Database:
    • execute the ALTER TABLE MailingLists ENGINE = InnoDB; (add your table prefix as needed) database query
  2. in the IDE:
    • open the /system/config.php file for editing
    • append this to end of the file:
$_CONFIG['Databases'] = array(
    array(
	'DBHost' => $_CONFIG['Database']['DBHost'],
	'DBUser' => $_CONFIG['Database']['DBUser'],
	'DBUserPassword' => $_CONFIG['Database']['DBUserPassword'],
	'DBLoad' => 1,
	'DBMaxLag' => 15,
    ),
);
  • save changes
  • open the SampleUnitTest PHP class (somewhere inside /modules/custom/tests folder)
  • add this code to that PHP class:
public function testDatabaseTransactions()
{
    $this->Conn->Query('TRUNCATE TABLE ' . TABLE_PREFIX . 'MailingLists');

    $count_sql = '	SELECT COUNT(*)
		    FROM ' . TABLE_PREFIX . 'MailingLists';
    $mailing_list_count_before = $this->Conn->GetOne($count_sql);

    $this->assertEquals(0, $mailing_list_count_before);

    $this->Conn->Query('begin');

    $this->Conn->doInsert(array('Subject' => 'test'), TABLE_PREFIX . 'MailingLists');

    $mailing_list_count_in_transaction = $this->Conn->GetOne($count_sql);
    $this->assertEquals(1, $mailing_list_count_in_transaction);

    $this->Conn->Query('rollback');

    $mailing_list_count_after_rollback = $this->Conn->GetOne($count_sql);
    $this->assertEquals(0, $mailing_list_count_after_rollback);
}
    • save changes
  1. in CLI:
    • run the vendor/bin/phpunit -c tools/build/inc/custom_phpunit.xml --filter testDatabaseTransactions command (prefix that command with a needed php binary version, e.g. php56)
    • confirm, that test passed

Diff Detail

Repository
rINP In-Portal
Branch
/in-portal/branches/5.2.x
Lint
Lint OK
Unit
No Unit Test Coverage
Build Status
Buildable 1345
Build 1345: arc lint + arc unit

Event Timeline

alex created this revision.Nov 25 2024, 10:19 AM
alex requested review of this revision.Nov 25 2024, 10:19 AM
erik requested changes to this revision.Thu, Dec 19, 10:52 AM

There happens error, due to this line in the AbstractBrowserTestCase.php

$cache = require_once WRITEABLE . '/mink_config.php';

when in place of this line writing $cache = {array from mink_config.php'} - all tests passed fine.

This revision now requires changes to proceed.Thu, Dec 19, 10:52 AM
erik accepted this revision.Thu, Dec 19, 12:42 PM
This revision is now accepted and ready to land.Thu, Dec 19, 12:42 PM
erik added a comment.Thu, Dec 19, 12:48 PM

Error fixed after svn update and clear memory cache.