mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-24 06:20:56 +01:00
Added a conduit call to update arc unit results for a postponed test.
Summary: It was not possible before to update arc unit results for a postponed test. This change makes it possible. Also the number of postponed tests are shown in differential. Let me know if this looks too Facebook specific. Test Plan: Tested the conduit call manually from Conduit Console and updated test results for a diff that had 20 postponed tests. Reviewed By: jungejason Reviewers: epriestley, jungejason Commenters: epriestley CC: slawekbiel, aran, tuomaspelkonen, jungejason, epriestley Differential Revision: 416
This commit is contained in:
parent
2e8990e9e0
commit
2521621074
10 changed files with 227 additions and 17 deletions
|
@ -97,6 +97,7 @@ phutil_register_library_map(array(
|
|||
'ConduitAPI_differential_setdiffproperty_Method' => 'applications/conduit/method/differential/setdiffproperty',
|
||||
'ConduitAPI_differential_updaterevision_Method' => 'applications/conduit/method/differential/updaterevision',
|
||||
'ConduitAPI_differential_updatetaskrevisionassoc_Method' => 'applications/conduit/method/differential/updatetaskrevisionassoc',
|
||||
'ConduitAPI_differential_updateunitresults_Method' => 'applications/conduit/method/differential/updateunitresults',
|
||||
'ConduitAPI_diffusion_getcommits_Method' => 'applications/conduit/method/diffusion/getcommits',
|
||||
'ConduitAPI_diffusion_getrecentcommitsbypath_Method' => 'applications/conduit/method/diffusion/getrecentcommitsbypath',
|
||||
'ConduitAPI_file_download_Method' => 'applications/conduit/method/file/download',
|
||||
|
@ -170,6 +171,7 @@ phutil_register_library_map(array(
|
|||
'DifferentialSubscribeController' => 'applications/differential/controller/subscribe',
|
||||
'DifferentialTasksAttacher' => 'applications/differential/tasks',
|
||||
'DifferentialUnitStatus' => 'applications/differential/constants/unitstatus',
|
||||
'DifferentialUnitTestResult' => 'applications/differential/constants/unittestresult',
|
||||
'DifferentialViewTime' => 'applications/differential/storage/viewtime',
|
||||
'DiffusionBranchInformation' => 'applications/diffusion/data/branch',
|
||||
'DiffusionBranchQuery' => 'applications/diffusion/query/branch/base',
|
||||
|
@ -610,6 +612,7 @@ phutil_register_library_map(array(
|
|||
'ConduitAPI_differential_setdiffproperty_Method' => 'ConduitAPIMethod',
|
||||
'ConduitAPI_differential_updaterevision_Method' => 'ConduitAPIMethod',
|
||||
'ConduitAPI_differential_updatetaskrevisionassoc_Method' => 'ConduitAPIMethod',
|
||||
'ConduitAPI_differential_updateunitresults_Method' => 'ConduitAPIMethod',
|
||||
'ConduitAPI_diffusion_getcommits_Method' => 'ConduitAPIMethod',
|
||||
'ConduitAPI_diffusion_getrecentcommitsbypath_Method' => 'ConduitAPIMethod',
|
||||
'ConduitAPI_file_download_Method' => 'ConduitAPIMethod',
|
||||
|
|
|
@ -134,6 +134,9 @@ class ConduitAPI_differential_creatediff_Method extends ConduitAPIMethod {
|
|||
case 'fail':
|
||||
$diff->setUnitStatus(DifferentialUnitStatus::UNIT_FAIL);
|
||||
break;
|
||||
case 'postponed':
|
||||
$diff->setUnitStatus(DifferentialUnitStatus::UNIT_POSTPONED);
|
||||
break;
|
||||
case 'none':
|
||||
default:
|
||||
$diff->setUnitStatus(DifferentialUnitStatus::UNIT_NONE);
|
||||
|
|
|
@ -0,0 +1,129 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* Copyright 2011 Facebook, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
class ConduitAPI_differential_updateunitresults_Method
|
||||
extends ConduitAPIMethod {
|
||||
|
||||
public function getMethodDescription() {
|
||||
return "Update arc unit results for a postponed test.";
|
||||
}
|
||||
|
||||
public function defineParamTypes() {
|
||||
return array(
|
||||
'diff_id' => 'required diff_id',
|
||||
'file' => 'required string',
|
||||
'name' => 'required string',
|
||||
'result' => 'required string',
|
||||
'message' => 'required string',
|
||||
);
|
||||
}
|
||||
|
||||
public function defineReturnType() {
|
||||
return 'void';
|
||||
}
|
||||
|
||||
public function defineErrorTypes() {
|
||||
return array(
|
||||
'ERR_BAD_DIFF' => 'Bad diff ID.',
|
||||
'ERR_NO_RESULTS' => 'Could not find the postponed test',
|
||||
'ERR_BAD_FILE' => 'No results for given file',
|
||||
);
|
||||
}
|
||||
|
||||
protected function execute(ConduitAPIRequest $request) {
|
||||
|
||||
$diff_id = $request->getValue('diff_id');
|
||||
if (!$diff_id) {
|
||||
throw new ConduitException('ERR_BAD_DIFF');
|
||||
}
|
||||
|
||||
$file = $request->getValue('file');
|
||||
$name = $request->getValue('name');
|
||||
$message = $request->getValue('message');
|
||||
$result = $request->getValue('result');
|
||||
|
||||
$diff_property = id(new DifferentialDiffProperty())->loadOneWhere(
|
||||
'diffID = %d AND name = %s',
|
||||
$diff_id,
|
||||
'arc:unit'
|
||||
);
|
||||
|
||||
if (!$diff_property) {
|
||||
throw new ConduitException('ERR_NO_RESULTS');
|
||||
}
|
||||
|
||||
$diff = id(new DifferentialDiff())->load($diff_id);
|
||||
$unit_results = $diff_property->getData();
|
||||
$postponed_count = 0;
|
||||
$unit_status = null;
|
||||
|
||||
foreach ($unit_results as &$unit_result) {
|
||||
// Update the results for the test that has the same path.
|
||||
if (($unit_result['name'] === $file ||
|
||||
$unit_result['name'] === $diff->getSourcePath().$file) &&
|
||||
$unit_result['result'] ===
|
||||
DifferentialUnitTestResult::RESULT_POSTPONED) {
|
||||
$unit_result['name'] = $name;
|
||||
$unit_result['result'] = $result;
|
||||
$unit_result['userdata'] = $message;
|
||||
$unit_status = $result;
|
||||
break;
|
||||
}
|
||||
}
|
||||
unset($unit_result);
|
||||
|
||||
if (!$unit_status) {
|
||||
throw new ConduitException('ERR_BAD_FILE');
|
||||
}
|
||||
|
||||
$diff_property->setData($unit_results);
|
||||
$diff_property->save();
|
||||
|
||||
foreach ($unit_results as $unit_result) {
|
||||
if ($unit_result['result'] ==
|
||||
DifferentialUnitTestResult::RESULT_POSTPONED) {
|
||||
$postponed_count++;
|
||||
}
|
||||
}
|
||||
|
||||
$status_codes =
|
||||
array(
|
||||
DifferentialUnitTestResult::RESULT_PASS =>
|
||||
DifferentialUnitStatus::UNIT_OKAY,
|
||||
DifferentialUnitTestResult::RESULT_UNSOUND =>
|
||||
DifferentialUnitStatus::UNIT_WARN,
|
||||
DifferentialUnitTestResult::RESULT_FAIL =>
|
||||
DifferentialUnitStatus::UNIT_FAIL,
|
||||
DifferentialUnitTestResult::RESULT_SKIP =>
|
||||
DifferentialUnitStatus::UNIT_SKIP,
|
||||
DifferentialUnitTestResult::RESULT_POSTPONED =>
|
||||
DifferentialUnitStatus::UNIT_POSTPONED);
|
||||
|
||||
if ($diff->getUnitStatus() == DifferentialUnitStatus::UNIT_POSTPONED) {
|
||||
if ($postponed_count == 0 ||
|
||||
$unit_status != DifferentialUnitTestResult::RESULT_PASS) {
|
||||
$diff->setUnitStatus(
|
||||
idx($status_codes, $unit_status, DifferentialUnitStatus::UNIT_NONE));
|
||||
$diff->save();
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is automatically generated. Lint this module to rebuild it.
|
||||
* @generated
|
||||
*/
|
||||
|
||||
|
||||
|
||||
phutil_require_module('phabricator', 'applications/conduit/method/base');
|
||||
phutil_require_module('phabricator', 'applications/conduit/protocol/exception');
|
||||
phutil_require_module('phabricator', 'applications/differential/constants/unitstatus');
|
||||
phutil_require_module('phabricator', 'applications/differential/constants/unittestresult');
|
||||
phutil_require_module('phabricator', 'applications/differential/storage/diff');
|
||||
phutil_require_module('phabricator', 'applications/differential/storage/diffproperty');
|
||||
|
||||
phutil_require_module('phutil', 'utils');
|
||||
|
||||
|
||||
phutil_require_source('ConduitAPI_differential_updateunitresults_Method.php');
|
|
@ -23,5 +23,6 @@ final class DifferentialUnitStatus {
|
|||
const UNIT_WARN = 2;
|
||||
const UNIT_FAIL = 3;
|
||||
const UNIT_SKIP = 4;
|
||||
const UNIT_POSTPONED = 5;
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* Copyright 2011 Facebook, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
final class DifferentialUnitTestResult {
|
||||
|
||||
const RESULT_PASS = 'pass';
|
||||
const RESULT_FAIL = 'fail';
|
||||
const RESULT_SKIP = 'skip';
|
||||
const RESULT_BROKEN = 'broken';
|
||||
const RESULT_UNSOUND = 'unsound';
|
||||
const RESULT_POSTPONED = 'postponed';
|
||||
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is automatically generated. Lint this module to rebuild it.
|
||||
* @generated
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
phutil_require_source('DifferentialUnitTestResult.php');
|
|
@ -373,6 +373,7 @@ class DifferentialRevisionViewController extends DifferentialController {
|
|||
$ustar = DifferentialRevisionUpdateHistoryView::renderDiffUnitStar($diff);
|
||||
$umsg = DifferentialRevisionUpdateHistoryView::getDiffUnitMessage($diff);
|
||||
|
||||
$postponed_count = 0;
|
||||
$udata = idx($diff_properties, 'arc:unit');
|
||||
$utail = null;
|
||||
if ($udata) {
|
||||
|
@ -380,29 +381,40 @@ class DifferentialRevisionViewController extends DifferentialController {
|
|||
foreach ($udata as $test) {
|
||||
$name = phutil_escape_html(idx($test, 'name'));
|
||||
$result = phutil_escape_html(idx($test, 'result'));
|
||||
$userdata = phutil_escape_html(idx($test, 'userdata'));
|
||||
if (strlen($userdata) > 256) {
|
||||
$userdata = substr($userdata, 0, 256).'...';
|
||||
}
|
||||
$userdata = str_replace("\n", '<br />', $userdata);
|
||||
$unit_messages[] =
|
||||
'<tr>'.
|
||||
|
||||
if ($result != DifferentialUnitTestResult::RESULT_POSTPONED &&
|
||||
$result != DifferentialUnitTestResult::RESULT_PASS) {
|
||||
$userdata = phutil_escape_html(idx($test, 'userdata'));
|
||||
if (strlen($userdata) > 256) {
|
||||
$userdata = substr($userdata, 0, 256).'...';
|
||||
}
|
||||
$userdata = str_replace("\n", '<br />', $userdata);
|
||||
$unit_messages[] =
|
||||
'<tr>'.
|
||||
'<th>'.$name.'</th>'.
|
||||
'<th class="unit-test-result">'.
|
||||
'<div class="result-'.$result.'">'.
|
||||
strtoupper($result).
|
||||
'</div>'.
|
||||
'<div class="result-'.$result.'">'.
|
||||
strtoupper($result).
|
||||
'</div>'.
|
||||
'</th>'.
|
||||
'<td>'.$userdata.'</td>'.
|
||||
'</tr>';
|
||||
}
|
||||
'</tr>';
|
||||
|
||||
$utail =
|
||||
'<div class="differential-unit-block">'.
|
||||
'<table class="differential-unit-table">'.
|
||||
$utail =
|
||||
'<div class="differential-unit-block">'.
|
||||
'<table class="differential-unit-table">'.
|
||||
implode("\n", $unit_messages).
|
||||
'</table>'.
|
||||
'</div>';
|
||||
'</table>'.
|
||||
'</div>';
|
||||
} else if ($result == DifferentialUnitTestResult::RESULT_POSTPONED) {
|
||||
$postponed_count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($postponed_count > 0 &&
|
||||
$diff->getUnitStatus() == DifferentialUnitStatus::UNIT_POSTPONED) {
|
||||
$umsg = $postponed_count.' '.$umsg;
|
||||
}
|
||||
|
||||
$properties['Unit'] = $ustar.' '.$umsg.$utail;
|
||||
|
|
|
@ -9,6 +9,8 @@
|
|||
phutil_require_module('phabricator', 'aphront/response/404');
|
||||
phutil_require_module('phabricator', 'applications/differential/constants/action');
|
||||
phutil_require_module('phabricator', 'applications/differential/constants/revisionstatus');
|
||||
phutil_require_module('phabricator', 'applications/differential/constants/unitstatus');
|
||||
phutil_require_module('phabricator', 'applications/differential/constants/unittestresult');
|
||||
phutil_require_module('phabricator', 'applications/differential/controller/base');
|
||||
phutil_require_module('phabricator', 'applications/differential/parser/changeset');
|
||||
phutil_require_module('phabricator', 'applications/differential/storage/changeset');
|
||||
|
|
|
@ -235,6 +235,7 @@ final class DifferentialRevisionUpdateHistoryView extends AphrontView {
|
|||
DifferentialUnitStatus::UNIT_WARN => self::STAR_WARN,
|
||||
DifferentialUnitStatus::UNIT_FAIL => self::STAR_FAIL,
|
||||
DifferentialUnitStatus::UNIT_SKIP => self::STAR_SKIP,
|
||||
DifferentialUnitStatus::UNIT_POSTPONED => self::STAR_SKIP,
|
||||
);
|
||||
|
||||
$star = idx($map, $diff->getUnitStatus(), self::STAR_FAIL);
|
||||
|
@ -270,6 +271,8 @@ final class DifferentialRevisionUpdateHistoryView extends AphrontView {
|
|||
return 'Unit Test Errors';
|
||||
case DifferentialUnitStatus::UNIT_SKIP:
|
||||
return 'Unit Tests Skipped';
|
||||
case DifferentialUnitStatus::UNIT_POSTPONED:
|
||||
return 'Unit Tests Postponed';
|
||||
}
|
||||
return '???';
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue