From d29a2b1e0f95e72146a34b1f8d70927065ee27ed Mon Sep 17 00:00:00 2001 From: hltaylor26 <79609783+hltaylor26@users.noreply.github.com> Date: Thu, 24 Feb 2022 09:51:42 -0500 Subject: [PATCH] Add integration test for new endpoints added in efficiency controller provider. (#314) --- .../lib/REST/Efficiency/EfficiencyTest.php | 394 ++++++++++++++++++ 1 file changed, 394 insertions(+) create mode 100644 tests/integration_tests/lib/REST/Efficiency/EfficiencyTest.php diff --git a/tests/integration_tests/lib/REST/Efficiency/EfficiencyTest.php b/tests/integration_tests/lib/REST/Efficiency/EfficiencyTest.php new file mode 100644 index 00000000..d392ee3d --- /dev/null +++ b/tests/integration_tests/lib/REST/Efficiency/EfficiencyTest.php @@ -0,0 +1,394 @@ +authenticate($user); + } + } + } + + public static function tearDownAfterClass() + { + foreach (self::$helpers as $helper) { + $helper->logout(); + } + } + + /*** + * Returns an array of analytics that are currently available for vieweing in the efficiency tab. + * Needs modification if analytics are changed, added, or removed. + */ + private static function getAnalytics() { + return array( + "CPU Usage", + "GPU Usage", + "Homogeneity", + "Memory Usage", + "Short Job Count", + "Wall Time Accuracy" + ); + } + + + /*** + * This test intentionally checks the current analytics available for the efficiency tab. + * If more analytics are added/modified, this test must be updated. + */ + public function testAnalytics() + { + foreach (array('pub', 'cd', 'usr') as $role) { + $response = self::$helpers[$role]->get(self::ENDPOINT . 'analytics'); + + $this->assertEquals(200, $response[1]['http_code']); + + $this->assertArrayHasKey('success', $response[0]); + $this->assertTrue($response[0]['success']); + + $analytics = array(); + foreach ($response[0]['data'] as $analyticType){ + $analytic = $analyticType['analytics']; + foreach($analytic as $key => $value){ + $analytics[] = $value['analytic']; + } + } + + sort($analytics); + + $this->assertEquals(self::getAnalytics(), $analytics); + } + } + + /*** + * Generate valid parameters for checking the scatter plot endpoint for CPU Usage data. + */ + protected function getScatterPlotDataParameters($configOverrides = array()) + { + $config = array( + 'realm' => 'SUPREMM', + 'group_by' => 'person', + 'statistics' => array('avg_percent_cpu_idle', 'wall_time'), + 'aggregation_unit' => 'day', + 'start_date' => '2016-12-01', + 'end_date' => '2017-01-01', + 'order_by' => array( + 'field' => 'avg_percent_cpu_idle', + 'dirn' => 'asc' + ) + ); + + $config = array_merge($config, $configOverrides); + + return array( + 'start' => 0, + 'limit' => 10, + 'config' => json_encode($config) + ); + } + + public function scatterPlotDataAccessUsers() + { + $params = $this->getScatterPlotDataParameters(); + $inputs = array(); + + $inputs[] = array('cd', $params, 4, 0); + $inputs[] = array('usr', $params, 1, 4); + + return $inputs; + } + + /** + * @dataProvider scatterPlotDataAccessUsers + */ + public function testCPUUsageScatterPlotEndpoint($usr, $params, $result_count, $hidden_data_count) + { + $response = self::$helpers[$usr]->get(self::ENDPOINT . 'scatterPlot/CPU%20Usage', $params); + + $this->assertEquals(200, $response[1]['http_code']); + $this->assertArrayHasKey('success', $response[0]); + $this->assertTrue($response[0]['success']); + + $this->assertCount($result_count, $response[0]['results'][0]['results']); + $this->assertCount($hidden_data_count, $response[0]['results'][0]['hiddenData']); + } + + public function testCPUUsageScatterPlotEndpointWithFilter() + { + $params = $this->getScatterPlotDataParameters(array('filters' => array('queue' => array("chapti")))); + $response = self::$helpers['cd']->get(self::ENDPOINT . 'scatterPlot/CPU%20Usage', $params); + + $this->assertEquals(200, $response[1]['http_code']); + $this->assertArrayHasKey('success', $response[0]); + $this->assertTrue($response[0]['success']); + + $this->assertCount(3, $response[0]['results'][0]['results']); + $this->assertCount(0, $response[0]['results'][0]['hiddenData']); + } + + public function testCPUUsageScatterPlotEndpointPub() + { + $params = $this->getScatterPlotDataParameters(); + $response = self::$helpers['pub']->get(self::ENDPOINT . 'scatterPlot/CPU%20Usage', $params); + + $this->assertEquals(401, $response[1]['http_code']); + $this->assertArrayHasKey('success', $response[0]); + $this->assertFalse($response[0]['success']); + } + + public function scatterPlotDataMalformedRequest() + { + $inputs = array(); + + $inputs[] = array('cd', array('start' => 0, 'limit' => 10)); + $inputs[] = array('cd', array('start' => 0, 'limit' => 10, 'config' => '')); + $inputs[] = array('cd', array('start' => 0, 'limit' => 10, 'config' => '{"realm": "SUPREMM"}')); + $inputs[] = array('cd', array('start' => 0, 'limit' => 10, 'config' => 'not json data')); + $inputs[] = array('cd', array('start' => 'smart', 'limit' => 'asdf', 'config' => '{"realm": "SUPREMM"}')); + + return $inputs; + } + + /** + * @dataProvider scatterPlotDataMalformedRequest + */ + public function testCPUUsageScatterPlotEndpointMalformedRequest($usr, $params) + { + $response = self::$helpers[$usr]->get(self::ENDPOINT . 'scatterPlot/CPU%20Usage', $params); + $this->assertEquals(400, $response[1]['http_code']); + $this->assertFalse($response[0]['success']); + } + + /*** + * Generate valid parameters for checking the drilldown endpoint for CPU Usage for Whimbrel user. + */ + protected function getDrillDownDataParameters($paramsOverrides = array()) + { + $params = array ( + 'show_title' => 'y', + 'title' => 'Test CPU Usage', + 'timeseries' => false, + 'aggregation_unit' => 'day', + 'start_date' => '2012-02-10', + 'end_date' => '2022-02-10', + 'global_filters' => array( + 'data' => array( + array( + 'dimension_id' => 'person', + 'id' => 'person=114', + 'realms' => array('SUPREMM'), + 'value_id' => '114', + 'value_name' => 'Whimbrel', + 'checked' => true + ) + ), + 'total' => 1 + ), + 'show_filters' => true, + 'show_warnings' => true, + 'show_remainder' => false, + 'start' => '0', + 'limit' => '200', + 'timeframe_label' => 'User Defined', + 'operation' => 'get_data', + 'data_series' => array( + array( + 'id' => 0.41070416068466, + 'metric' => 'wall_time', + 'category' => 'SUPREMM', + 'realm' => 'SUPREMM', + 'group_by' => 'cpuuser', + 'x_axis' => true, + 'log_scale' => false, + 'has_std_err' => false, + 'std_err' => false, + 'value_labels' => false, + 'display_type' => 'column', + 'line_type' => 'Solid', + 'line_width' => 2, + 'combine_type' => 'side', + 'sort_type' => 'none', + 'filters' => array ( + 'data' => array (), + 'total' => 0, + ), + 'ignore_global' => false, + 'long_legend' => false, + 'trend_line' => false, + 'color' => 'auto', + 'shadow' => false, + 'visibility' => null, + 'z_index' => 0, + 'enabled' => true, + ) + ), + 'swap_xy' => 'false', + 'share_y_axis' => 'false', + 'hide_tooltip' => 'false', + 'show_guide_lines' => true, + 'scale' => '1', + 'format' => 'hc_jsonstore', + 'legend_type' => 'off', + 'controller_module' => 'metric_explorer' + ); + + $params = array_merge($params, $paramsOverrides); + + $params['global_filters'] = urlencode(json_encode($params['global_filters'])); + $params['data_series'] = urlencode(json_encode($params['data_series'])); + + return $params; + } + + public function drilldownDataUsers() + { + $params = $this->getDrillDownDataParameters(); + $inputs = array(); + + $inputs[] = array('cd', $params, 4); + $inputs[] = array('usr', $params, 4); + + return $inputs; + } + + /** + * @dataProvider drilldownDataUsers + */ + public function testCPUUsageDrilldownPlot($usr, $params, $seriesCount) + { + $response = self::$helpers[$usr]->get(self::ENDPOINT . 'histogram/cpuuser', $params); + $this->assertEquals(200, $response[1]['http_code']); + + $this->assertArrayHasKey('success', $response[0]); + $this->assertTrue($response[0]['success']); + + $this->assertCount($seriesCount, $response[0]['data'][0]['series'][0]['data']); + } + + public function testCPUUsageDrilldownPlotWithFilter() + { + $params = $this->getDrillDownDataParameters(array( + 'global_filters' => array( + 'data' => array( + array( + 'dimension_id' => 'person', + 'id' => 'person=114', + 'realms' => array('SUPREMM'), + 'value_id' => '114', + 'value_name' => 'Whimbrel', + 'checked' => true + ), + array( + 'dimension_id' => 'queue', + 'id' => 'queue=chapti', + 'realms' => array('SUPREMM'), + 'value_id' => 'chapti', + 'value_name' => 'chapti', + 'checked' => true + ) + ), + 'total' => 2) + ) + ); + + $response = self::$helpers['cd']->get(self::ENDPOINT . 'histogram/cpuuser', $params); + + $this->assertEquals(200, $response[1]['http_code']); + $this->assertArrayHasKey('success', $response[0]); + $this->assertTrue($response[0]['success']); + + $this->assertCount(4, $response[0]['data'][0]['series'][0]['data']); + } + + public function drilldownDataMalformedRequest() + { + $inputs = array(); + + $inputs[] = array('cd', 400, array('')); + $inputs[] = array('cd', 400, array('not json data')); + $inputs[] = array('cd', 400, array('{"realm": "SUPREMM"}')); + + $params = $this->getDrillDownDataParameters(array( + 'global_filters' => array( + 'data' => array( + array( + 'dimension_id' => 'person', + 'id' => 'person=14', + 'realms' => array('SUPREMM'), + 'value_id' => '14', + 'value_name' => 'Dunlin', + 'checked' => true + ) + ), + 'total' => 1) + ) + ); + $inputs[] = array('usr', 200, $params); + + $params = $this->getDrillDownDataParameters(array('data_series' => array('metric' => 'wall_time'))); + $inputs[] = array('cd', 500, $params); + + $params = $this->getDrillDownDataParameters(array('data_series' => array( + array( + 'id' => 0.41070416068466, + 'metric' => '', + 'category' => 'SUPREMM', + 'realm' => 'SUPREMM', + 'group_by' => 'cpuuser', + 'x_axis' => true, + 'log_scale' => false, + 'has_std_err' => false, + 'std_err' => false, + 'value_labels' => false, + 'display_type' => 'column', + 'line_type' => 'Solid', + 'line_width' => 2, + 'combine_type' => 'side', + 'sort_type' => 'none', + 'filters' => array ( + 'data' => array (), + 'total' => 0, + ), + 'ignore_global' => false, + 'long_legend' => false, + 'trend_line' => false, + 'color' => 'auto', + 'shadow' => false, + 'visibility' => null, + 'z_index' => 0, + 'enabled' => true, + ) + ))); + $inputs[] = array('cd', 200, $params); + + return $inputs; + } + + /** + * @dataProvider drilldownDataMalformedRequest + */ + public function testCPUUsageDrillownEndpointMalformedRequest($usr, $http_code, $params) + { + $response = self::$helpers[$usr]->get(self::ENDPOINT . 'histogram/cpuuser', $params); + $this->assertEquals($http_code, $response[1]['http_code']); + $resdata = $response[0]; + + if ($http_code == 200) { + $this->assertArrayHasKey('success', $resdata); + $this->assertTrue($resdata['success']); + $this->assertCount(0, $response[0]['data'][0]['series']); + } else { + $this->assertArrayHasKey('success', $resdata); + $this->assertFalse($resdata['success']); + } + } +}