From a160f2e2124aed36721bcd6948485459efeebb85 Mon Sep 17 00:00:00 2001 From: Anne-Cath Date: Mon, 24 Jun 2024 14:55:17 +0200 Subject: [PATCH] =?UTF-8?q?N=C2=B04342=20-=20Improve=20generic=20bulk=20de?= =?UTF-8?q?letion=20function=20with=20memory=20limit=20handling=20-=20add?= =?UTF-8?q?=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../unitary-tests/core/MetaModelTest.php | 26 ++++++++++++++----- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/tests/php-unit-tests/unitary-tests/core/MetaModelTest.php b/tests/php-unit-tests/unitary-tests/core/MetaModelTest.php index 95252bf31..d70637454 100644 --- a/tests/php-unit-tests/unitary-tests/core/MetaModelTest.php +++ b/tests/php-unit-tests/unitary-tests/core/MetaModelTest.php @@ -462,12 +462,13 @@ class MetaModelTest extends ItopDataTestCase * @return void * @throws CoreException * @throws \OQLException + * @dataProvider PurgeDataProvider + * */ - public function testPurgeData(){ - // Set max_chunk_size to 2 (default 1000) to test chunk deletion with only 10 items + public function testPurgeData( $iMaxChunkSize, $iNbQueriesExpected){ + // Set max_chunk_size to $iMaxChunkSize (default 1000) to test chunk deletion with only 10 items $oConfig = MetaModel::GetConfig(); - $oConfig->Set('purge_data.max_chunk_size', 2); - MetaModel::SetConfig($oConfig); + $oConfig->Set('purge_data.max_chunk_size', $iMaxChunkSize); $aPkPerson = []; for ($i=0; $i < 10; $i++) { @@ -476,12 +477,23 @@ class MetaModelTest extends ItopDataTestCase $aPkPerson[] = $oPerson->GetKey(); } - $sDeleteOQL = 'SELECT '.$sClass.' WHERE id IN ('.implode(',', $aPkPerson).')'; - $oFilter = DBObjectSearch::FromOQL($sDeleteOQL); + $oFilter = DBObjectSearch::FromOQL('SELECT '.$sClass.' WHERE id IN ('.implode(',', $aPkPerson).')'); + $iNbDelete = 0; + + $this->assertDBQueryCount($iNbQueriesExpected, function() use ($oFilter, &$iNbDelete) { + $iNbDelete = MetaModel::PurgeData($oFilter); + } ); - $iNbDelete = MetaModel::PurgeData($oFilter); $this->assertEquals($iNbDelete, 10, 'MetaModel::PurgeData must delete 10 objects per batch of 2 items'); } + + public function PurgeDataProvider(){ + return [ + 'Purge 10 items with a max_chunk_size of 2 should be perfomed in 5 steps + an additional query to verify that the job is complete' => [2, 16], + 'Purge 10 items with a max_chunk_size of 3 should be perfomed in 4 steps' => [3, 12], + 'Purge 10 items with a max_chunk_size of 1000 (default value) should be perfomed in 1 step' => [1000, 3], + ]; + } } abstract class Wizzard