Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix regression bug when paging datasets. #1299

Merged
merged 1 commit into from
May 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions classes/DataWarehouse/Data/TimeseriesDataset.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ public function getDatasets($limit, $offset, $summarize)
}

$this->query->addWhereAndJoin($spaceGroup->getId(), 'IN', $seriesIds);
} else {
// this happens when the offset is greater than the number of series. This
// can occur when muliple datasets with different numbers of series
// are plotted on the same chart.
return array();
}

$statement = $this->query->getRawStatement();
Expand Down
66 changes: 64 additions & 2 deletions tests/regression/lib/Controllers/MetricExplorerChartsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,66 @@ private function getDimensionValues($helper, $realm, $dimension)
return $response[0]['data'];
}

/**
* Tests the scenario where multiple datasets are plotted but they have different
* number of dataseries and the paging has paged past the max of one of the series.
*/
public function testChartPaging()
{
$helper = new \TestHarness\XdmodTestHelper();
$helper->authenticate('cd');

$requestData = $this->getChartRequest(
array(
array('realm' => 'Jobs', 'group_by' => 'username', 'metric' => 'total_cpu_hours'),
array('realm' => 'Jobs', 'group_by' => 'none', 'metric' => 'total_cpu_hours'),
),
array(
'start' => '4',
'showRemainder' => 'false'
)
);

$expected = array (
'total' => '55',
'series_data' => array(
array('name' => 'aytinis [<span style="color:#1199ff">CPU Hours: Total</span>]', 'y' => 10091.8844, 'percentage' => null),
array('name' => 'sarwa [<span style="color:#1199ff">CPU Hours: Total</span>]', 'y' => 6955.7733, 'percentage' => null),
array('name' => 'crane [<span style="color:#1199ff">CPU Hours: Total</span>]', 'y' => 6839.52, 'percentage' => null),
array('name' => 'duswa [<span style="color:#1199ff">CPU Hours: Total</span>]', 'y' => 5701.5467, 'percentage' => null)
)
);

$response = $helper->post('controllers/metric_explorer.php', null, $requestData);

$this->assertEquals(200, $response[1]['http_code']);

$chartData = json_decode($response[0]);
$this->assertNotNull($chartData);

if ($expected === null) {
$this->output($chartData);
$this->markTestSkipped();
return;
}

$this->assertEquals($expected['total'], $chartData->totalCount);

$series = $chartData->data[0]->series;
$this->assertCount(count($expected['series_data']), $series);

$sdata = reset($expected['series_data']);

foreach ($series as $s) {
$this->assertEquals($sdata['name'], $s->name);
$this->assertEquals($sdata['y'], $s->data[0]->y, '', 1.0E-6);
$this->assertEquals($sdata['percentage'], $s->data[0]->percentage);
$sdata = next($expected['series_data']);
}

$helper->logout();
}

/**
* @dataProvider remainderChartProvider
*/
Expand Down Expand Up @@ -182,6 +242,8 @@ public function getChartRequest($data_settings, $global_settings = null)
);

$testdate = isset($global_settings['date']) ? $global_settings['date'] : '2016-12-31';
$startOffset = isset($global_settings['start']) ? $global_settings['start'] : '0';
$showRemainder = isset($global_settings['showRemainder']) ? $global_settings['showRemainder'] : 'true';

$chartSettings = array(
'show_title' => 'y',
Expand All @@ -193,8 +255,8 @@ public function getChartRequest($data_settings, $global_settings = null)
'title' => 'Metric Explorer Test Chart',
'show_filters' => 'true',
'show_warnings' => 'true',
'show_remainder' => 'true',
'start' => '0',
'show_remainder' => $showRemainder,
'start' => $startOffset,
'limit' => '4',
'timeframe_label' => 'User Defined',
'operation' => 'get_data',
Expand Down