From 1ec41f04573b8bd46c8f7d83fb3d3a84b1934c7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maur=C3=ADcio=20Meneghini=20Fauth?= Date: Sun, 27 Jul 2025 13:46:26 -0300 Subject: [PATCH] Refactor unit tests for Engines\Innodb::getPageBufferpool() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: MaurĂ­cio Meneghini Fauth --- src/Engines/Innodb.php | 28 ++--- tests/unit/Engines/InnodbTest.php | 198 ++++++++++++++++++++---------- tests/unit/Stubs/DbiDummy.php | 21 ---- 3 files changed, 147 insertions(+), 100 deletions(-) diff --git a/src/Engines/Innodb.php b/src/Engines/Innodb.php index 7b1a538196..46675a633b 100644 --- a/src/Engines/Innodb.php +++ b/src/Engines/Innodb.php @@ -154,30 +154,30 @@ class Innodb extends StorageEngine . ' ' . "\n" . ' ' . __('Pages containing data') . '' . "\n" . ' ' - . Util::formatNumber($status['Innodb_buffer_pool_pages_data'], 0) . "\n" + . Util::formatNumber($status['Innodb_buffer_pool_pages_data'], 0) . '' . "\n" . ' ' . "\n" . ' ' . "\n" . ' ' . __('Pages to be flushed') . '' . "\n" . ' ' - . Util::formatNumber($status['Innodb_buffer_pool_pages_flushed'], 0) . "\n" + . Util::formatNumber($status['Innodb_buffer_pool_pages_flushed'], 0) . '' . "\n" . ' ' . "\n" . ' ' . "\n" . ' ' . __('Busy pages') . '' . "\n" . ' ' - . Util::formatNumber($status['Innodb_buffer_pool_pages_misc'], 0) . "\n" + . Util::formatNumber($status['Innodb_buffer_pool_pages_misc'], 0) . '' . "\n" - . ' '; + . ' ' . "\n"; // not present at least since MySQL 5.1.40 if (isset($status['Innodb_buffer_pool_pages_latched'])) { - $output .= ' ' - . ' ' . __('Latched pages') . '' + $output .= ' ' . "\n" + . ' ' . __('Latched pages') . '' . "\n" . ' ' . Util::formatNumber($status['Innodb_buffer_pool_pages_latched'], 0) - . '' - . ' '; + . '' . "\n" + . ' ' . "\n"; } $output .= ' ' . "\n" @@ -190,25 +190,25 @@ class Innodb extends StorageEngine . ' ' . "\n" . ' ' . __('Read requests') . '' . "\n" . ' ' - . Util::formatNumber($status['Innodb_buffer_pool_read_requests'], 0) . "\n" + . Util::formatNumber($status['Innodb_buffer_pool_read_requests'], 0) . '' . "\n" . ' ' . "\n" . ' ' . "\n" . ' ' . __('Write requests') . '' . "\n" . ' ' - . Util::formatNumber($status['Innodb_buffer_pool_write_requests'], 0) . "\n" + . Util::formatNumber($status['Innodb_buffer_pool_write_requests'], 0) . '' . "\n" . ' ' . "\n" . ' ' . "\n" . ' ' . __('Read misses') . '' . "\n" . ' ' - . Util::formatNumber($status['Innodb_buffer_pool_reads'], 0) . "\n" + . Util::formatNumber($status['Innodb_buffer_pool_reads'], 0) . '' . "\n" . ' ' . "\n" . ' ' . "\n" . ' ' . __('Write waits') . '' . "\n" . ' ' - . Util::formatNumber($status['Innodb_buffer_pool_wait_free'], 0) . "\n" + . Util::formatNumber($status['Innodb_buffer_pool_wait_free'], 0) . '' . "\n" . ' ' . "\n" . ' ' . "\n" @@ -223,7 +223,7 @@ class Innodb extends StorageEngine 3, 2, ), - ) . ' %') . "\n" + ) . ' %') . '' . "\n" . ' ' . "\n" . ' ' . "\n" @@ -238,7 +238,7 @@ class Innodb extends StorageEngine 3, 2, ), - ) . ' %') . "\n" + ) . ' %') . '' . "\n" . ' ' . "\n" . ' ' . "\n" diff --git a/tests/unit/Engines/InnodbTest.php b/tests/unit/Engines/InnodbTest.php index a7a6b927a9..af82d0665b 100644 --- a/tests/unit/Engines/InnodbTest.php +++ b/tests/unit/Engines/InnodbTest.php @@ -8,6 +8,7 @@ use PhpMyAdmin\Dbal\DatabaseInterface; use PhpMyAdmin\Engines\Innodb; use PhpMyAdmin\Tests\AbstractTestCase; use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; use function __; @@ -126,86 +127,153 @@ class InnodbTest extends AbstractTestCase } /** - * Test for getPageBufferpool + * @param list $variables + * @param list $usageTableRows + * @param list $activityTableRows */ - public function testGetPageBufferpool(): void - { - self::assertSame( - '' . "\n" . + #[DataProvider('pageBufferPoolProvider')] + public function testGetPageBufferPool( + array $variables, + string $totalPages, + string $totalBytes, + array $usageTableRows, + array $activityTableRows, + ): void { + $dbiDummy = $this->createDbiDummy(); + $dbiDummy->addResult( + 'SHOW STATUS WHERE Variable_name LIKE \'Innodb\\_buffer\\_pool\\_%\'' + . ' OR Variable_name = \'Innodb_page_size\';', + $variables, + ); + DatabaseInterface::$instance = $this->createDatabaseInterface($dbiDummy); + + $pageBufferPool = (new Innodb('innodb'))->getPageBufferpool(); + $dbiDummy->assertAllQueriesConsumed(); + + $expected = '
' . "\n" . ' ' . "\n" . ' ' . "\n" . ' ' . "\n" . ' ' . "\n" . ' ' . "\n" . ' ' . "\n" . - ' ' . "\n" . - ' ' . "\n" . - ' ' . "\n" . - ' ' . "\n" . - ' ' . "\n" . - ' ' . "\n" . - ' ' . "\n" . - ' ' . "\n" . - ' ' . "\n" . - ' ' . "\n" . - ' ' . "\n" . - ' ' . "\n" . - ' ' . "\n" . - ' ' . "\n" . - ' ' . "\n" . - ' ' . "\n" . - ' ' . "\n" . - ' ' . "\n" . - ' ' . "\n" . - ' ' . "\n" . - ' ' . "\n" . + ' ' . "\n"; + + foreach ($usageTableRows as $tableRow) { + $expected .= ' ' . "\n" . + ' ' . "\n" . + ' ' . "\n" . + ' ' . "\n"; + } + + $expected .= ' ' . "\n" . '
' . "\n" . ' Buffer Pool Usage' . "\n" . '
' . "\n" . - ' Total: 4,096 pages / 65,536 KiB' . "\n" . + ' Total: ' . $totalPages . ' pages / ' . $totalBytes . "\n" . '
Free pages0
Dirty pages0
Pages containing data0' . "\n" . - '
Pages to be flushed0' . "\n" . - '
Busy pages0' . "\n" . - '
' . $tableRow[0] . '' . $tableRow[1] . '
' . "\n\n" . '' . "\n" . ' ' . "\n" . - ' ' . "\n" . - ' ' . "\n" . - ' ' . "\n" . - ' ' . "\n" . - ' ' . "\n" . - ' ' . "\n" . - ' ' . "\n" . - ' ' . "\n" . - ' ' . "\n" . - ' ' . "\n" . - ' ' . "\n" . - ' ' . "\n" . - ' ' . "\n" . - ' ' . "\n" . - ' ' . "\n" . - ' ' . "\n" . - ' ' . "\n" . - ' ' . "\n" . - ' ' . "\n" . - ' ' . "\n" . - ' ' . "\n" . - ' ' . "\n" . - ' ' . "\n" . - ' ' . "\n" . - ' ' . "\n" . - ' ' . "\n" . - '
' . "\n" . ' Buffer Pool Activity' . "\n" . '
Read requests64' . "\n" . - '
Write requests64' . "\n" . - '
Read misses32' . "\n" . - '
Write waits0' . "\n" . - '
Read misses in %50 %' . "\n" . - '
Write waits in %0 %' . "\n" . - '
' . "\n", - $this->object->getPageBufferpool(), - ); + ' ' . "\n"; + + foreach ($activityTableRows as $tableRow) { + $expected .= ' ' . "\n" . + ' ' . $tableRow[0] . '' . "\n" . + ' ' . $tableRow[1] . '' . "\n" . + ' ' . "\n"; + } + + $expected .= ' ' . "\n" . '' . "\n"; + + self::assertSame($expected, $pageBufferPool); + } + + /** + * @return iterable, + * string, + * string, + * list, + * list + * }> + */ + public static function pageBufferPoolProvider(): iterable + { + yield [ + [ + ['Innodb_buffer_pool_pages_data', '0'], + ['Innodb_buffer_pool_pages_dirty', '0'], + ['Innodb_buffer_pool_pages_flushed', '0'], + ['Innodb_buffer_pool_pages_free', '0'], + ['Innodb_buffer_pool_pages_misc', '0'], + ['Innodb_buffer_pool_pages_total', '4096'], + ['Innodb_buffer_pool_read_ahead_rnd', '0'], + ['Innodb_buffer_pool_read_ahead', '0'], + ['Innodb_buffer_pool_read_ahead_evicted', '0'], + ['Innodb_buffer_pool_read_requests', '64'], + ['Innodb_buffer_pool_reads', '32'], + ['Innodb_buffer_pool_wait_free', '0'], + ['Innodb_buffer_pool_write_requests', '64'], + ['Innodb_page_size', '16384'], + ], + '4,096', + '65,536 KiB', + [ + ['Free pages', '0'], + ['Dirty pages', '0'], + ['Pages containing data', '0'], + ['Pages to be flushed', '0'], + ['Busy pages', '0'], + ], + [ + ['Read requests', '64'], + ['Write requests', '64'], + ['Read misses', '32'], + ['Write waits', '0'], + ['Read misses in %', '50 %'], + ['Write waits in %', '0 %'], + ], + ]; + + yield [ + [ + ['Innodb_buffer_pool_pages_data', '0'], + ['Innodb_buffer_pool_pages_dirty', '0'], + ['Innodb_buffer_pool_pages_flushed', '0'], + ['Innodb_buffer_pool_pages_free', '0'], + ['Innodb_buffer_pool_pages_latched', '0'], + ['Innodb_buffer_pool_pages_misc', '0'], + ['Innodb_buffer_pool_pages_total', '4096'], + ['Innodb_buffer_pool_read_ahead_rnd', '0'], + ['Innodb_buffer_pool_read_ahead', '0'], + ['Innodb_buffer_pool_read_ahead_evicted', '0'], + ['Innodb_buffer_pool_read_requests', '0'], + ['Innodb_buffer_pool_reads', '32'], + ['Innodb_buffer_pool_wait_free', '0'], + ['Innodb_buffer_pool_write_requests', '0'], + ['Innodb_page_size', '16384'], + ], + '4,096', + '65,536 KiB', + [ + ['Free pages', '0'], + ['Dirty pages', '0'], + ['Pages containing data', '0'], + ['Pages to be flushed', '0'], + ['Busy pages', '0'], + ['Latched pages', '0'], + ], + [ + ['Read requests', '0'], + ['Write requests', '0'], + ['Read misses', '32'], + ['Write waits', '0'], + ['Read misses in %', '---'], + ['Write waits in %', '---'], + ], + ]; } /** diff --git a/tests/unit/Stubs/DbiDummy.php b/tests/unit/Stubs/DbiDummy.php index 15ff21fc0a..9bf85f8821 100644 --- a/tests/unit/Stubs/DbiDummy.php +++ b/tests/unit/Stubs/DbiDummy.php @@ -400,27 +400,6 @@ class DbiDummy implements DbiExtension ['Pbxt', 'NO', 'Pbxt storage engine'], ], ], - [ - 'query' => 'SHOW STATUS WHERE Variable_name' - . ' LIKE \'Innodb\\_buffer\\_pool\\_%\'' - . ' OR Variable_name = \'Innodb_page_size\';', - 'result' => [ - ['Innodb_buffer_pool_pages_data', 0], - ['Innodb_buffer_pool_pages_dirty', 0], - ['Innodb_buffer_pool_pages_flushed', 0], - ['Innodb_buffer_pool_pages_free', 0], - ['Innodb_buffer_pool_pages_misc', 0], - ['Innodb_buffer_pool_pages_total', 4096], - ['Innodb_buffer_pool_read_ahead_rnd', 0], - ['Innodb_buffer_pool_read_ahead', 0], - ['Innodb_buffer_pool_read_ahead_evicted', 0], - ['Innodb_buffer_pool_read_requests', 64], - ['Innodb_buffer_pool_reads', 32], - ['Innodb_buffer_pool_wait_free', 0], - ['Innodb_buffer_pool_write_requests', 64], - ['Innodb_page_size', 16384], - ], - ], ['query' => 'SHOW ENGINE INNODB STATUS;', 'result' => false], ['query' => 'SELECT @@innodb_version;', 'result' => [['1.1.8']]], ['query' => 'SELECT @@disabled_storage_engines', 'result' => [['']]],