Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Fix HTTP 500 error for testOverview + filters timeline (backport to 3.2) #2022

Merged
merged 3 commits into from
Feb 9, 2024
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
41 changes: 0 additions & 41 deletions app/cdash/app/Controller/Api/Timeline.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ public function getResponse()
{
$this->filterdata = json_decode(request()->input('filterdata'), true);
$page = htmlentities($this->filterdata['pageId']);
$this->filterSQL = generate_filterdata_sql($this->filterdata);
$this->generateColorMap();

$this->project->Fill();
Expand All @@ -70,8 +69,6 @@ public function getResponse()
switch ($page) {
case 'buildProperties.php':
return $this->chartForBuildProperties();
case 'index.php':
return $this->chartForIndex();
case 'testOverview.php':
return $this->chartForTestOverview();
case 'viewBuildGroup.php':
Expand Down Expand Up @@ -141,43 +138,6 @@ private function chartForBuildProperties()
return $this->getTimelineChartData($stmt);
}

private function chartForIndex()
{
$this->defectTypes = [
[
'name' => 'builderrors',
'prettyname' => 'Errors',
],
[
'name' => 'testfailed',
'prettyname' => 'Test Failures',
]
];

// Query for defects on expected builds only.
$stmt = $this->db->prepare("
SELECT b.id, b.starttime, b.builderrors, b.buildwarnings, b.testfailed
FROM build b
JOIN build2group b2g ON b2g.buildid = b.id
JOIN build2grouprule b2gr ON
b2g.groupid = b2gr.groupid AND b2gr.buildtype = b.type AND
b2gr.buildname = b.name AND b2gr.siteid = b.siteid
WHERE b.projectid = :projectid AND b.parentid IN (0, -1)
AND b2gr.expected = 1
$this->filterSQL
ORDER BY starttime");
if (!pdo_execute($stmt, [':projectid' => $this->project->Id])) {
abort(500, 'Failed to load results');
}
$response = $this->getTimelineChartData($stmt);
$response['colors'] = [
$this->colors[self::CLEAN],
$this->colors[self::FAILURE],
$this->colors[self::ERROR]
];
return $response;
}

private function chartForTestOverview()
{
$this->defectTypes = [
Expand All @@ -199,7 +159,6 @@ private function chartForTestOverview()
SELECT b.id, b.starttime, b.testfailed, b.testnotrun, b.testpassed
FROM build b
WHERE b.projectid = :projectid AND b.parentid IN (0, -1)
$this->filterSQL
ORDER BY starttime");
if (!pdo_execute($stmt, [':projectid' => $this->project->Id])) {
abort(500, 'Failed to load results');
Expand Down
84 changes: 1 addition & 83 deletions app/cdash/tests/test_timeline.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,9 @@ public function testTimeline()
$this->toggle_expected($client, $build, 1);

// Now that we have an expected build, validate timeline data on relevant pages.
$pages_to_check = ['index.php', 'testOverview.php', 'viewBuildGroup.php'];
$pages_to_check = ['testOverview.php', 'viewBuildGroup.php'];

$answer_key = [
'index.php' => [
'Test Failures' => 1
],
'testOverview.php' => [
'Failing Tests' => 1,
'Not Run Tests' => 1,
Expand All @@ -107,85 +104,6 @@ public function testTimeline()
$this->toggle_expected($client, $build, 0);
}

public function testTimelineWithFilters()
{
// Find the three builds we will use for this test case.
$builds = [];
$this->get($this->url . '/api/v1/index.php?project=InsightExample&date=2010-07-07');
$content = $this->getBrowser()->getContent();
$jsonobj = json_decode($content, true);
foreach ($jsonobj['buildgroups'] as $buildgroup_response) {
foreach ($buildgroup_response['builds'] as $build_response) {
$build = new Build();
$build->Id = $build_response['id'];
$build->FillFromId($build->Id);
$builds[] = $build;
}
}
$num_builds = count($builds);
if ($num_builds != 3) {
$this->fail("Expected 3 builds, found $num_builds");
}

// Login as admin.
$client = $this->getGuzzleClient();

// Mark these builds as expected.
foreach ($builds as $build) {
$this->toggle_expected($client, $build, 1);
}

// Validate timeline with filters.
$filterdata_arr = [
'hasdateclause' => 0,
'filtercombine' => 'and',
'filtercount' => 1,
'limit' => 0,
'filters' => [
[
'field' => 'buildname',
'compare' => 63,
'value' => 'vs'
]
],
];

$pages_to_check = ['index.php', 'testOverview.php', 'viewBuildGroup.php'];

$answer_key = [
'index.php' => [
'Errors' => 1,
'Test Failures' => 2
],
'testOverview.php' => [
'Failing Tests' => 2,
'Not Run Tests' => 2,
'Passing Tests' => 2
],
'viewBuildGroup.php' => [
'Errors' => 1,
'Test Failures' => 2
],
];

foreach ($pages_to_check as $page) {
$filterdata_arr['pageId'] = $page;
$filterdata = json_encode($filterdata_arr);
$extra_param = $page == 'viewBuildGroup.php' ? '&buildgroup=Nightly' : '';
$this->get($this->url . "/api/v1/timeline.php?date=2010-07-07&filterdata=$filterdata&project=InsightExample$extra_param");
$content = $this->getBrowser()->getContent();
$jsonobj = json_decode($content, true);

$this->validateExtent(1278464400000, 1278550800000, $jsonobj);
$this->validatePage($answer_key, $page, 1278464400000, $jsonobj);
}

// Revert back to unexpected.
foreach ($builds as $build) {
$this->toggle_expected($client, $build, 0);
}
}

private function validateExtent($start, $end, $jsonobj)
{
if ($jsonobj['extentstart'] != $start) {
Expand Down
14 changes: 2 additions & 12 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -2835,15 +2835,15 @@ parameters:

-
message: "#^Access to an undefined property CDash\\\\Controller\\\\Api\\\\Timeline\\:\\:\\$colors\\.$#"
count: 12
count: 9
path: app/cdash/app/Controller/Api/Timeline.php

-
message: """
#^Call to deprecated function pdo_execute\\(\\)\\:
v2\\.5\\.0 01/22/2018$#
"""
count: 4
count: 3
path: app/cdash/app/Controller/Api/Timeline.php

-
Expand All @@ -2866,11 +2866,6 @@ parameters:
count: 1
path: app/cdash/app/Controller/Api/Timeline.php

-
message: "#^Method CDash\\\\Controller\\\\Api\\\\Timeline\\:\\:chartForIndex\\(\\) has no return type specified\\.$#"
count: 1
path: app/cdash/app/Controller/Api/Timeline.php

-
message: "#^Method CDash\\\\Controller\\\\Api\\\\Timeline\\:\\:chartForTestOverview\\(\\) has no return type specified\\.$#"
count: 1
Expand Down Expand Up @@ -25343,11 +25338,6 @@ parameters:
count: 1
path: app/cdash/tests/test_timeline.php

-
message: "#^Method TimelineTestCase\\:\\:testTimelineWithFilters\\(\\) has no return type specified\\.$#"
count: 1
path: app/cdash/tests/test_timeline.php

-
message: "#^Method TimelineTestCase\\:\\:toggle_expected\\(\\) has no return type specified\\.$#"
count: 1
Expand Down