From ecc6efe8f0bae616f5ffae4cd68ed6ab6764091d Mon Sep 17 00:00:00 2001 From: Aaron Weeden Date: Fri, 20 Oct 2023 12:48:41 -0400 Subject: [PATCH 1/5] Refactor integration test namespaces. --- tests/integration/README.md | 4 ++ .../bootstrap.php | 0 .../DashboardAppKernelTest.php | 4 +- .../phpunit.xml.dist | 0 .../runtests.sh | 0 .../scripts/bootstrap.sh | 0 .../scripts/validate.sh | 0 tests/integration_tests/README.md | 7 --- tests/unit/README.md | 3 -- tests/unit/bootstrap.php | 44 +++++++++++++++++-- 10 files changed, 48 insertions(+), 14 deletions(-) create mode 100644 tests/integration/README.md rename tests/{integration_tests => integration}/bootstrap.php (100%) rename tests/{integration_tests => integration}/lib/REST/internal_dashboard/DashboardAppKernelTest.php (94%) rename tests/{integration_tests => integration}/phpunit.xml.dist (100%) rename tests/{integration_tests => integration}/runtests.sh (100%) rename tests/{integration_tests => integration}/scripts/bootstrap.sh (100%) rename tests/{integration_tests => integration}/scripts/validate.sh (100%) delete mode 100644 tests/integration_tests/README.md diff --git a/tests/integration/README.md b/tests/integration/README.md new file mode 100644 index 00000000..0e498d3a --- /dev/null +++ b/tests/integration/README.md @@ -0,0 +1,4 @@ +The integration test framework is designed to be used to run tests against +an installed and working XDMoD instance. + +Run the tests with ./runtests.sh diff --git a/tests/integration_tests/bootstrap.php b/tests/integration/bootstrap.php similarity index 100% rename from tests/integration_tests/bootstrap.php rename to tests/integration/bootstrap.php diff --git a/tests/integration_tests/lib/REST/internal_dashboard/DashboardAppKernelTest.php b/tests/integration/lib/REST/internal_dashboard/DashboardAppKernelTest.php similarity index 94% rename from tests/integration_tests/lib/REST/internal_dashboard/DashboardAppKernelTest.php rename to tests/integration/lib/REST/internal_dashboard/DashboardAppKernelTest.php index e7a9f17e..29594f42 100644 --- a/tests/integration_tests/lib/REST/internal_dashboard/DashboardAppKernelTest.php +++ b/tests/integration/lib/REST/internal_dashboard/DashboardAppKernelTest.php @@ -2,12 +2,14 @@ namespace IntegrationTests\REST\internal_dashboard; +use IntegrationTests\TestHarness\XdmodTestHelper; + class DashboardAppKernelTest extends \PHPUnit_Framework_TestCase { public function __construct() { $xdmodConfig = array( "decodetextasjson" => true ); - $this->xdmodhelper = new \TestHarness\XdmodTestHelper($xdmodConfig); + $this->xdmodhelper = new XdmodTestHelper($xdmodConfig); $this->endpoint = 'rest/v0.1/akrr/'; $this->xdmodhelper->authenticate("mgr"); diff --git a/tests/integration_tests/phpunit.xml.dist b/tests/integration/phpunit.xml.dist similarity index 100% rename from tests/integration_tests/phpunit.xml.dist rename to tests/integration/phpunit.xml.dist diff --git a/tests/integration_tests/runtests.sh b/tests/integration/runtests.sh similarity index 100% rename from tests/integration_tests/runtests.sh rename to tests/integration/runtests.sh diff --git a/tests/integration_tests/scripts/bootstrap.sh b/tests/integration/scripts/bootstrap.sh similarity index 100% rename from tests/integration_tests/scripts/bootstrap.sh rename to tests/integration/scripts/bootstrap.sh diff --git a/tests/integration_tests/scripts/validate.sh b/tests/integration/scripts/validate.sh similarity index 100% rename from tests/integration_tests/scripts/validate.sh rename to tests/integration/scripts/validate.sh diff --git a/tests/integration_tests/README.md b/tests/integration_tests/README.md deleted file mode 100644 index 8ea333d7..00000000 --- a/tests/integration_tests/README.md +++ /dev/null @@ -1,7 +0,0 @@ -The integration test framework is designed to be used to run tests against -an installed and working XDMoD instance. - -The test harness in the xdmod repository must be configured correctly as -per the instructions in the readme file: xdmod/open_xdmod/modules/xdmod/integration_tests/README.md - -Run the tests with ./runtests.sh diff --git a/tests/unit/README.md b/tests/unit/README.md index 8ea333d7..0e498d3a 100644 --- a/tests/unit/README.md +++ b/tests/unit/README.md @@ -1,7 +1,4 @@ The integration test framework is designed to be used to run tests against an installed and working XDMoD instance. -The test harness in the xdmod repository must be configured correctly as -per the instructions in the readme file: xdmod/open_xdmod/modules/xdmod/integration_tests/README.md - Run the tests with ./runtests.sh diff --git a/tests/unit/bootstrap.php b/tests/unit/bootstrap.php index 0ff6fc40..ede8efc6 100644 --- a/tests/unit/bootstrap.php +++ b/tests/unit/bootstrap.php @@ -5,9 +5,47 @@ // Autoloader for main framework test classes. spl_autoload_register( function ($className) use ($dir) { - $classPath - = $dir - . '/../../../xdmod/open_xdmod/modules/xdmod/integration_tests/lib/' + // Replace the UnitTests namespace prefix with the path to the unit + // tests lib directory. + $classPath = preg_replace( + '/UnitTests\\\\?/', + "$dir/lib/", + $className + ); + // Replace the IntegrationTests namespace prefix with the path to the + // integration tests lib directory. + $classPath = preg_replace( + '/IntegrationTests\\\\?/', + "$dir/../integration/lib/", + $classPath + ); + // Replace namespace separators with directory separators. + $classPath = str_replace('\\', '/', $classPath) . '.php'; + if (is_readable($classPath)) { + return require_once $classPath; + } + // Replace the UnitTests namespace prefix with the path to the main + // unit tests lib directory. + $classPath = preg_replace( + '/UnitTests\\\\?/', + "$dir/../../../xdmod/tests/unit/lib/", + $className + ); + // Replace the IntegrationTests namespace prefix with the path to + // the main integration tests lib directory. + $classPath = preg_replace( + '/IntegrationTests\\\\?/', + "$dir/../../../xdmod/tests/integration/lib/", + $classPath + ); + // Replace namespace separators with directory separators. + $classPath = str_replace('\\', '/', $classPath) . '.php'; + if (is_readable($classPath)) { + return require_once $classPath; + } + // Autoload the AppKernels module classes + $classPath = ( + "$dir/../../classes/" . str_replace('\\', '/', $className) . '.php'; From 8549448fe65aa7dcb79e4d3858819f5c1c96a4c3 Mon Sep 17 00:00:00 2001 From: Aaron Weeden Date: Fri, 20 Oct 2023 12:50:48 -0400 Subject: [PATCH 2/5] Refactor unit test namespaces. --- tests/unit/{ => lib}/AppKernelDbTest.php | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) rename tests/unit/{ => lib}/AppKernelDbTest.php (97%) diff --git a/tests/unit/AppKernelDbTest.php b/tests/unit/lib/AppKernelDbTest.php similarity index 97% rename from tests/unit/AppKernelDbTest.php rename to tests/unit/lib/AppKernelDbTest.php index 565f93ea..920354de 100644 --- a/tests/unit/AppKernelDbTest.php +++ b/tests/unit/lib/AppKernelDbTest.php @@ -1,11 +1,12 @@ getDB(); $db_ak_id = $db->query( @@ -43,7 +44,7 @@ public function processingUnitProvider() $proc_unit_node_1to4 = array_slice($proc_unit_node_1to32, 0, 3); $proc_unit_node_2to8 = array_slice($proc_unit_node_1to32, 1, 3); - $ak_db = new \AppKernel\AppKernelDb(); + $ak_db = new AppKernelDb(); $metrics_id = intval( $ak_db->getDB()->query( 'SELECT metric_id FROM mod_appkernel.metric WHERE name="Wall Clock Time"' @@ -75,7 +76,7 @@ public function processingUnitProvider() */ public function testProcessingUnit($start_date, $end_date, array $resource_ids, array $metrics, $expected) { - $ak_db = new \AppKernel\AppKernelDb(); + $ak_db = new AppKernelDb(); $actual = $ak_db->getProcessingUnits($start_date, $end_date, $resource_ids, $metrics); if ($expected === null) { @@ -245,7 +246,7 @@ public function testGetUniqueAppKernels( $n_expected = null, $expected = null ) { - $ak_db = new \AppKernel\AppKernelDb(); + $ak_db = new AppKernelDb(); $actual = $ak_db->getUniqueAppKernels($resource_ids, $node_counts, $core_counts); if ($expected === null && $n_expected === null) { @@ -284,7 +285,7 @@ public function testGetUniqueAppKernels( public function getMetricsProvider() { - $ak_db = new \AppKernel\AppKernelDb(); + $ak_db = new AppKernelDb(); $db = $ak_db->getDB(); # Get metric id $ak_exec_exists_id = intval( @@ -356,7 +357,7 @@ public function testGetMetrics( $n_expected = null, $expected = null ) { - $ak_db = new \AppKernel\AppKernelDb(); + $ak_db = new AppKernelDb(); $actual = $ak_db->getMetrics($ak_def_id, $start_date, $end_date, $resource_ids, $pu_counts); if ($n_expected === null && $expected !== null) { @@ -434,7 +435,7 @@ public function loadAppKernelInstancesProvider() */ public function testLoadAppKernelInstances($ak_def_id, $resource_id, $n_expected = null, $expected = null) { - $ak_db = new \AppKernel\AppKernelDb(); + $ak_db = new AppKernelDb(); $actual = $ak_db->loadAppKernelInstances($ak_def_id, $resource_id); $db = $ak_db->getDB(); @@ -472,7 +473,7 @@ public function testLoadAppKernelInstances($ak_def_id, $resource_id, $n_expected public function testNewControlRegions() { - $ak_db = new \AppKernel\AppKernelDb(); + $ak_db = new AppKernelDb(); // update initial control for 5 points $ak_db->newControlRegions( From e424df4cb5f381c004e95960cfef39e6ef3261e3 Mon Sep 17 00:00:00 2001 From: Aaron Weeden Date: Fri, 20 Oct 2023 12:53:11 -0400 Subject: [PATCH 3/5] Make test `bootstrap.php` files consistent. --- tests/integration/bootstrap.php | 42 ++++++++++++++++++++++++++------- tests/unit/bootstrap.php | 10 ++++---- 2 files changed, 38 insertions(+), 14 deletions(-) diff --git a/tests/integration/bootstrap.php b/tests/integration/bootstrap.php index 7e09b614..9536daa2 100644 --- a/tests/integration/bootstrap.php +++ b/tests/integration/bootstrap.php @@ -2,19 +2,45 @@ $dir = __DIR__; -// Autoloader for main framework test classes. +// Autoloader for test classes. spl_autoload_register( function ($className) use ($dir) { - $classPath - = $dir - . '/../../../xdmod/open_xdmod/modules/xdmod/integration_tests/lib/' + // Replace the IntegrationTests namespace prefix with the path to the + // integration tests lib directory. + $classPath = preg_replace( + '/IntegrationTests\\\\?/', + "$dir/lib/", + $className + ); + // Replace namespace separators with directory separators. + $classPath = str_replace('\\', '/', $classPath) . '.php'; + if (is_readable($classPath)) { + return require_once $classPath; + } + // Replace the IntegrationTests namespace prefix with the path to + // the main integration tests lib directory. + $classPath = preg_replace( + '/IntegrationTests\\\\?/', + "$dir/../../../xdmod/tests/integration/lib/", + $className + ); + // Replace namespace separators with directory separators. + $classPath = str_replace('\\', '/', $classPath) . '.php'; + if (is_readable($classPath)) { + return require_once $classPath; + } + // Autoload the AppKernels module classes + $classPath = ( + "$dir/../../classes/" . str_replace('\\', '/', $className) - . '.php'; - + . '.php' + ); if (is_readable($classPath)) { return require_once $classPath; - } else { - return false; } + return false; } ); + +// Autoloader for XDMoD classes. +require_once __DIR__ . '/../../../xdmod/configuration/linker.php'; diff --git a/tests/unit/bootstrap.php b/tests/unit/bootstrap.php index ede8efc6..9a3a4ee9 100644 --- a/tests/unit/bootstrap.php +++ b/tests/unit/bootstrap.php @@ -2,7 +2,7 @@ $dir = __DIR__; -// Autoloader for main framework test classes. +// Autoloader for test classes. spl_autoload_register( function ($className) use ($dir) { // Replace the UnitTests namespace prefix with the path to the unit @@ -47,16 +47,14 @@ function ($className) use ($dir) { $classPath = ( "$dir/../../classes/" . str_replace('\\', '/', $className) - . '.php'; - + . '.php' + ); if (is_readable($classPath)) { return require_once $classPath; - } else { - return false; } + return false; } ); // Autoloader for XDMoD classes. -// require_once __DIR__ . '/../../configuration/linker.php'; require_once '/usr/share/xdmod/configuration/linker.php'; From da31f956f4272dc4fb296c6ccb8a2b7ed5e9901e Mon Sep 17 00:00:00 2001 From: Aaron Weeden Date: Fri, 8 Dec 2023 13:13:49 -0500 Subject: [PATCH 4/5] Remove printerClass from PHPUnit config so that --debug works properly. --- tests/integration/phpunit.xml.dist | 1 - tests/unit/phpunit.xml.dist | 1 - 2 files changed, 2 deletions(-) diff --git a/tests/integration/phpunit.xml.dist b/tests/integration/phpunit.xml.dist index 578d81b6..50b04a1a 100644 --- a/tests/integration/phpunit.xml.dist +++ b/tests/integration/phpunit.xml.dist @@ -10,7 +10,6 @@ convertWarningsToExceptions="true" forceCoversAnnotation="false" mapTestClassNameToCoveredClassName="false" - printerClass="PHPUnit_TextUI_ResultPrinter" processIsolation="false" stopOnError="false" stopOnFailure="false" diff --git a/tests/unit/phpunit.xml.dist b/tests/unit/phpunit.xml.dist index 578d81b6..50b04a1a 100644 --- a/tests/unit/phpunit.xml.dist +++ b/tests/unit/phpunit.xml.dist @@ -10,7 +10,6 @@ convertWarningsToExceptions="true" forceCoversAnnotation="false" mapTestClassNameToCoveredClassName="false" - printerClass="PHPUnit_TextUI_ResultPrinter" processIsolation="false" stopOnError="false" stopOnFailure="false" From cb23c4d30b19ef14c5b754b5e7dc50c53599d995 Mon Sep 17 00:00:00 2001 From: Aaron Weeden Date: Fri, 8 Dec 2023 14:30:53 -0500 Subject: [PATCH 5/5] Update integration test expected results. --- .../DashboardAppKernelTest.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/integration/lib/REST/internal_dashboard/DashboardAppKernelTest.php b/tests/integration/lib/REST/internal_dashboard/DashboardAppKernelTest.php index 29594f42..954b0096 100644 --- a/tests/integration/lib/REST/internal_dashboard/DashboardAppKernelTest.php +++ b/tests/integration/lib/REST/internal_dashboard/DashboardAppKernelTest.php @@ -22,8 +22,8 @@ private function validateAkrrResourceEntries($searchparams) $result = $this->xdmodhelper->get($this->endpoint . 'resources', $searchparams); $this->assertEquals(200, $result[1]['http_code']); - $this->assertArrayHasKey('success', $result[0]); - $this->assertEquals($result[0]['success'], true); + $this->assertArrayHasKey('status', $result[0]); + $this->assertEquals($result[0]['status'], 'success'); $data = $result[0]['data']; foreach ($data as $item) { @@ -47,15 +47,15 @@ private function validateAkrrKernelEntries($searchparams) $result = $this->xdmodhelper->get($this->endpoint . 'kernels', $searchparams); $this->assertEquals(200, $result[1]['http_code']); - $this->assertArrayHasKey('message', $result[0]); - $this->assertEquals($result[0]['message'], 'success'); + $this->assertArrayHasKey('status', $result[0]); + $this->assertEquals($result[0]['status'], 'success'); $data = $result[0]['data']; foreach ($data as $item) { - $this->assertArrayHasKey('nodes_list', $data[0]); - $this->assertArrayHasKey('name', $data[0]); - $this->assertArrayHasKey('enabled', $data[0]); - $this->assertArrayHasKey('id', $data[0]); + $this->assertArrayHasKey('nodes_list', $item); + $this->assertArrayHasKey('name', $item); + $this->assertArrayHasKey('enabled', $item); + $this->assertArrayHasKey('id', $item); } return $data;