From 239c51bb5383e771e6f0462ed5d3d5049edf3128 Mon Sep 17 00:00:00 2001 From: odain Date: Tue, 3 Oct 2023 10:09:26 +0200 Subject: [PATCH] ci enhancement: complete tearDown to cleanup transactions and cmdb changes properly --- tests/php-unit-tests/ItopDataTestCase.php | 2 ++ tests/php-unit-tests/ItopTestCase.php | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/php-unit-tests/ItopDataTestCase.php b/tests/php-unit-tests/ItopDataTestCase.php index d28fb40a5..ff6396cba 100644 --- a/tests/php-unit-tests/ItopDataTestCase.php +++ b/tests/php-unit-tests/ItopDataTestCase.php @@ -136,6 +136,8 @@ class ItopDataTestCase extends ItopTestCase } } + CMDBObject::SetCurrentChange(null); + parent::tearDown(); } diff --git a/tests/php-unit-tests/ItopTestCase.php b/tests/php-unit-tests/ItopTestCase.php index 1a2b25db3..70ad46593 100644 --- a/tests/php-unit-tests/ItopTestCase.php +++ b/tests/php-unit-tests/ItopTestCase.php @@ -68,6 +68,10 @@ class ItopTestCase extends TestCase if (CMDBSource::IsInsideTransaction()) { // Nested transactions were opened but not finished ! + // Rollback to avoid side effects on next tests + while (CMDBSource::IsInsideTransaction()) { + CMDBSource::Query('ROLLBACK'); + } throw new MySQLTransactionNotClosedException('Some DB transactions were opened but not closed ! Fix the code by adding ROLLBACK or COMMIT statements !', []); } } @@ -312,4 +316,4 @@ class ItopTestCase extends TestCase } closedir($dir); } -} \ No newline at end of file +}