1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-10-05 04:01:49 +02:00

[ticket/17543] Optimize functional tests running time

PHPBB-17543
This commit is contained in:
rxu
2025-09-23 14:54:27 +07:00
parent 2baac73d33
commit 70c07d4302
11 changed files with 69 additions and 29 deletions

View File

@@ -39,7 +39,7 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c
protected static function setup_extensions()
{
return ['foo/bar', 'foo/foo'];
return self::$tests_count == self::$tests_number ? ['foo/bar', 'foo/foo'] : [];
}
protected function setUp(): void
@@ -51,8 +51,11 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c
protected function tearDown(): void
{
$this->uninstall_ext('foo/bar');
$this->uninstall_ext('foo/foo');
if (self::$tests_count == 1)
{
$this->uninstall_ext('foo/bar');
$this->uninstall_ext('foo/foo');
}
parent::tearDown();
}

View File

@@ -40,14 +40,17 @@ class phpbb_functional_extension_module_test extends phpbb_functional_test_case
protected function tearDown(): void
{
$this->uninstall_ext('foo/bar');
if (self::$tests_count == 1)
{
$this->uninstall_ext('foo/bar');
}
parent::tearDown();
}
protected static function setup_extensions()
{
return ['foo/bar'];
return self::$tests_count == self::$tests_number ? ['foo/bar'] : [];
}
public function test_acp()

View File

@@ -46,15 +46,18 @@ class phpbb_functional_extension_template_event_order_test extends phpbb_functio
protected function tearDown(): void
{
$this->uninstall_ext('foo/bar');
$this->uninstall_ext('foo/foo');
if (self::$tests_count == 1)
{
$this->uninstall_ext('foo/bar');
$this->uninstall_ext('foo/foo');
}
parent::tearDown();
}
protected static function setup_extensions()
{
return ['foo/bar', 'foo/foo'];
return self::$tests_count == self::$tests_number ? ['foo/bar', 'foo/foo'] : [];
}
/**
@@ -84,7 +87,7 @@ class phpbb_functional_extension_template_event_order_test extends phpbb_functio
$crawler = self::request('GET', 'index.php');
$quick_links_menu = $crawler->filter('ul[role="menu"]')->eq(0);
$quick_links_menu_nodes_count = (int) $quick_links_menu->filter('li')->count();
// Ensure foo/foo template event goes before foo/bar one
// Ensure foo/bar template event goes before foo/foo one
$this->assertStringContainsString('FOO_BAR_QUICK_LINK', $quick_links_menu->filter('li')->eq($quick_links_menu_nodes_count - 4)->filter('span')->text());
$this->assertStringContainsString('FOO_FOO_QUICK_LINK', $quick_links_menu->filter('li')->eq($quick_links_menu_nodes_count - 3)->filter('span')->text());
}

View File

@@ -208,7 +208,7 @@ class phpbb_functional_mcp_main_test extends phpbb_functional_test_case
// Create replies. Flood control was disabled above
for ($i = 1; $i <= 15; $i++)
{
sleep(1);
usleep(100000);
$post_text = "This is reply number $i to the Test Topic 4 to test moderation actions from MCP/View topic page.";
$post[$i] = $this->create_post(2, $post[0]['topic_id'], 'Re: Test Topic 4', $post_text);
$crawler = self::request('GET', "viewtopic.php?p={$post[$i]['post_id']}&sid={$this->sid}#p{$post[$i]['post_id']}");

View File

@@ -24,7 +24,10 @@ class phpbb_functional_metadata_manager_test extends phpbb_functional_test_case
protected function tearDown(): void
{
$this->uninstall_ext('foo/bar');
if (self::$tests_count == 1)
{
$this->uninstall_ext('foo/bar');
}
parent::tearDown();
}
@@ -55,7 +58,7 @@ class phpbb_functional_metadata_manager_test extends phpbb_functional_test_case
protected static function setup_extensions()
{
return ['foo/bar'];
return self::$tests_count == self::$tests_number ? ['foo/bar'] : [];
}
public function test_extensions_list()

View File

@@ -133,7 +133,7 @@ class phpbb_functional_prune_shadow_topic_test extends phpbb_functional_test_cas
self::request('GET', "app.php/cron/cron.task.core.prune_shadow_topics?f={$this->data['forums']['Prune Shadow']}&sid={$this->sid}", array(), false);
// Try to ensure that the cron can actually run before we start to wait for it
sleep(1);
usleep(100000);
$cron_lock = new \phpbb\lock\db('cron_lock', new \phpbb\config\db($this->db, new \phpbb\cache\driver\dummy(), 'phpbb_config'), $this->db);
while (!$cron_lock->acquire())
{

View File

@@ -137,8 +137,6 @@ abstract class phpbb_functional_search_base extends phpbb_functional_test_case
$this->login();
$this->admin_login();
$this->create_search_index('phpbb\\search\\backend\\fulltext_native');
$post = $this->create_topic(2, 'Test Topic 1 foosubject', 'This is a test topic posted by the barsearch testing framework.');
$topic_multiple_results_count1 = $this->create_topic(2, 'Test Topic for multiple search results', 'This is a test topic posted to test multiple results count.');
$this->create_post(2, $topic_multiple_results_count1['topic_id'], 'Re: Test Topic for multiple search results', 'This is a test post 2 posted to test multiple results count.');

View File

@@ -20,6 +20,17 @@ class phpbb_functional_search_mysql_test extends phpbb_functional_search_base
{
protected $search_backend = 'phpbb\search\backend\fulltext_mysql';
protected function setUp(): void
{
$sql_layer = substr(self::$config['dbms'], strlen('phpbb\\db\\driver\\'));
if ($sql_layer !== 'mysqli') // MySQL search backend runs on MySQL/MariaDB only
{
$this->markTestSkipped($sql_layer . ': MySQL search is not supported');
}
parent::setUp();
}
protected function create_search_index($backend = null)
{
parent::create_search_index($backend);

View File

@@ -20,4 +20,14 @@ class phpbb_functional_search_postgres_test extends phpbb_functional_search_base
{
protected $search_backend = 'phpbb\search\backend\fulltext_postgres';
protected function setUp(): void
{
$sql_layer = substr(self::$config['dbms'], strlen('phpbb\\db\\driver\\'));
if ($sql_layer !== 'postgres') // PostgreSQL search backend runs on PostgreSQL only
{
$this->markTestSkipped($sql_layer . ': PostgreSQL search is not supported');
}
parent::setUp();
}
}

View File

@@ -20,6 +20,17 @@ class phpbb_functional_search_sphinx_test extends phpbb_functional_search_base
{
protected $search_backend = 'phpbb\search\backend\fulltext_sphinx';
protected function setUp(): void
{
$sql_layer = substr(self::$config['dbms'], strlen('phpbb\\db\\driver\\'));
if ($sql_layer !== 'mysqli') // Sphinx search backend runs on MySQL/MariaDB only so far
{
$this->markTestSkipped($sql_layer . ': Sphinx search is not supported');
}
parent::setUp();
}
protected function create_search_index($backend = null)
{
parent::create_search_index($backend);
@@ -35,16 +46,4 @@ class phpbb_functional_search_sphinx_test extends phpbb_functional_search_base
exec('sudo -S service sphinxsearch start', $output, $retval); // Attempt to start sphinxsearch service again
}
}
public function test_search_backend()
{
if ($this->db->sql_layer != 'mysqli') // Sphinx test runs on MySQL/MariaDB only so far
{
$this->markTestIncomplete('Sphinx Tests are not supported');
}
else
{
parent::test_search_backend();
}
}
}

View File

@@ -48,6 +48,8 @@ class phpbb_functional_test_case extends phpbb_test_case
protected static $config = array();
protected static $already_installed = false;
protected static $tests_count = 0;
protected static $tests_number = 0;
static public function setUpBeforeClass(): void
{
@@ -73,6 +75,12 @@ class phpbb_functional_test_case extends phpbb_test_case
self::install_board();
self::$already_installed = true;
}
self::$tests_number = self::$tests_count = count(array_filter(get_class_methods(static::class), function($val)
{
return str_starts_with($val, 'test_');
})
);
}
/**
@@ -143,7 +151,9 @@ class phpbb_functional_test_case extends phpbb_test_case
{
parent::tearDown();
if ($this->db instanceof \phpbb\db\driver\driver_interface)
self::$tests_count--;
if (self::$tests_count === 0 && $this->db instanceof \phpbb\db\driver\driver_interface)
{
// Unset ci_tests_no_lock_posting from config
$sql = 'DELETE FROM ' . CONFIG_TABLE . "
@@ -234,7 +244,7 @@ class phpbb_functional_test_case extends phpbb_test_case
{
$dbms = self::$config['dbms'];
$this->db = new $dbms();
$this->db->sql_connect(self::$config['dbhost'], self::$config['dbuser'], self::$config['dbpasswd'], self::$config['dbname'], self::$config['dbport']);
$this->db->sql_connect(self::$config['dbhost'], self::$config['dbuser'], self::$config['dbpasswd'], self::$config['dbname'], self::$config['dbport'], true);
}
return $this->db;
}