From 70c07d4302935756c8523cd211f2b6043a4b8932 Mon Sep 17 00:00:00 2001 From: rxu Date: Tue, 23 Sep 2025 14:54:27 +0700 Subject: [PATCH] [ticket/17543] Optimize functional tests running time PHPBB-17543 --- .../functional/extension_controller_test.php | 9 +++++--- tests/functional/extension_module_test.php | 7 ++++-- .../extension_template_event_order_test.php | 11 +++++---- tests/functional/mcp/mcp_main_test.php | 2 +- tests/functional/metadata_manager_test.php | 7 ++++-- tests/functional/prune_shadow_topic_test.php | 2 +- tests/functional/search/base.php | 2 -- tests/functional/search/mysql_test.php | 11 +++++++++ tests/functional/search/postgres_test.php | 10 ++++++++ tests/functional/search/sphinx_test.php | 23 +++++++++---------- .../phpbb_functional_test_case.php | 14 +++++++++-- 11 files changed, 69 insertions(+), 29 deletions(-) diff --git a/tests/functional/extension_controller_test.php b/tests/functional/extension_controller_test.php index 4cc5e2d2a9..451565c186 100644 --- a/tests/functional/extension_controller_test.php +++ b/tests/functional/extension_controller_test.php @@ -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(); } diff --git a/tests/functional/extension_module_test.php b/tests/functional/extension_module_test.php index 08ec7e5012..cc7f5b1605 100644 --- a/tests/functional/extension_module_test.php +++ b/tests/functional/extension_module_test.php @@ -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() diff --git a/tests/functional/extension_template_event_order_test.php b/tests/functional/extension_template_event_order_test.php index 197efce746..596f46ca3e 100644 --- a/tests/functional/extension_template_event_order_test.php +++ b/tests/functional/extension_template_event_order_test.php @@ -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()); } diff --git a/tests/functional/mcp/mcp_main_test.php b/tests/functional/mcp/mcp_main_test.php index 7f092e1f00..4d5bfc1e0a 100644 --- a/tests/functional/mcp/mcp_main_test.php +++ b/tests/functional/mcp/mcp_main_test.php @@ -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']}"); diff --git a/tests/functional/metadata_manager_test.php b/tests/functional/metadata_manager_test.php index 206a72b2eb..f74252d7df 100644 --- a/tests/functional/metadata_manager_test.php +++ b/tests/functional/metadata_manager_test.php @@ -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() diff --git a/tests/functional/prune_shadow_topic_test.php b/tests/functional/prune_shadow_topic_test.php index 698acc7550..366ddf0af6 100644 --- a/tests/functional/prune_shadow_topic_test.php +++ b/tests/functional/prune_shadow_topic_test.php @@ -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()) { diff --git a/tests/functional/search/base.php b/tests/functional/search/base.php index 53b251b208..ddf2e7564f 100644 --- a/tests/functional/search/base.php +++ b/tests/functional/search/base.php @@ -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.'); diff --git a/tests/functional/search/mysql_test.php b/tests/functional/search/mysql_test.php index 50b2d6487b..a4aaef3ab0 100644 --- a/tests/functional/search/mysql_test.php +++ b/tests/functional/search/mysql_test.php @@ -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); diff --git a/tests/functional/search/postgres_test.php b/tests/functional/search/postgres_test.php index 4389705d66..6851a29e80 100644 --- a/tests/functional/search/postgres_test.php +++ b/tests/functional/search/postgres_test.php @@ -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(); + } } diff --git a/tests/functional/search/sphinx_test.php b/tests/functional/search/sphinx_test.php index e72228f387..01ccd1bb7f 100644 --- a/tests/functional/search/sphinx_test.php +++ b/tests/functional/search/sphinx_test.php @@ -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(); - } - } } diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 9e7e0e4679..dfdb62c7e5 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -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; }