Skip to content

Commit

Permalink
Provide option for user to fail PTR if no results are uploaded (#19347)
Browse files Browse the repository at this point in the history
* Added files required for the change

* changed the versoin in task.loc.kson

* Updated the version

* updated the version

* updated generated files

* resolved build error

* changed task.loc.json

* changed task.loc.json

* Update task.locl.json

* resolved test failures

---------

Co-authored-by: Eswarnath Prudhivi (from Dev Box) <[email protected]>
Co-authored-by: v-mazayt <[email protected]>
  • Loading branch information
3 people authored Dec 15, 2023
1 parent cfee22e commit ee56363
Show file tree
Hide file tree
Showing 17 changed files with 106 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
"loc.input.help.mergeTestResults": "A test run is created for each results file. Check this option to merge results into a single test run. To optimize for better performance, results will be merged into a single run if there are more than 100 result files, irrespective of this option.",
"loc.input.label.failTaskOnFailedTests": "Fail if there are test failures",
"loc.input.help.failTaskOnFailedTests": "Fail the task if there are any test failures. Check this option to fail the task if test failures are detected in the result files.",
"loc.input.label.failTaskOnFailureToPublishResults": "Fail if there is failure in publishing test results",
"loc.input.help.failTaskOnFailureToPublishResults": "Fail if there is failure in publishing test results. Check this option to fail the task if publishing test results is failed partially.",
"loc.input.label.failTaskOnMissingResultsFile": "Fail if no result files are found",
"loc.input.help.failTaskOnMissingResultsFile": "Fail the task if no result files are found.",
"loc.input.label.testRunTitle": "Test run title",
Expand Down
3 changes: 2 additions & 1 deletion Tasks/PublishTestResultsV2/Tests/Constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ export const failTaskOnFailedTests = 'failTaskOnFailedTests';
export const proxyUrl = 'agent.proxyurl';
export const proxyUserName = 'agent.proxyusername';
export const proxyPassword = 'agent.proxypassword';
export const proxyByPassHosts = 'agent.proxybypasslist';
export const proxyByPassHosts = 'agent.proxybypasslist';
export const failTaskOnFailureToPublishResults = 'failTaskOnFailureToPublishResults';
9 changes: 7 additions & 2 deletions Tasks/PublishTestResultsV2/Tests/L0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ describe('PublishTestResults Suite', function() {
delete process.env[constants.listPackagesReturnCode];
delete process.env[constants.osType];
delete process.env[constants.failTaskOnFailedTests];
delete process.env[constants.failTaskOnFailureToPublishResults];

done();
});
Expand Down Expand Up @@ -60,6 +61,7 @@ describe('PublishTestResults Suite', function() {
process.env[constants.proxyUserName] = "1";
process.env[constants.proxyPassword] = "1";
process.env[constants.proxyByPassHosts] = undefined;
process.env[constants.failTaskOnFailureToPublishResults] = 'false';

// Start the run
tr.run();
Expand Down Expand Up @@ -96,6 +98,7 @@ describe('PublishTestResults Suite', function() {
process.env[constants.proxyUserName] = "1";
process.env[constants.proxyPassword] = "1";
process.env[constants.proxyByPassHosts] = undefined;
process.env[constants.failTaskOnFailureToPublishResults] = 'false';

// Start the run
tr.run();
Expand Down Expand Up @@ -132,6 +135,7 @@ describe('PublishTestResults Suite', function() {
process.env[constants.proxyUserName] = "1";
process.env[constants.proxyPassword] = "1";
process.env[constants.proxyByPassHosts] = undefined;
process.env[constants.failTaskOnFailureToPublishResults] = 'false';

// Start the run
tr.run();
Expand All @@ -142,7 +146,7 @@ describe('PublishTestResults Suite', function() {
assert.equal(tr.invokedToolCount, 1, `invoked tool count should be 1`);
assert(tr.stdOutContained(`TestResultsPublisher.exe`),
`Should have called TestResultsPublisher.exe first`);
assert(tr.stdOutContained(`vso[results.publish type=VSTest;mergeResults=false;publishRunAttachments=false;resultFiles=n-files0.xml;failTaskOnFailedTests=false;testRunSystem=VSTS - PTR;]`),
assert(tr.stdOutContained(`vso[results.publish type=VSTest;mergeResults=false;publishRunAttachments=false;resultFiles=n-files0.xml;failTaskOnFailedTests=false;failTaskOnFailureToPublishResults=false;testRunSystem=VSTS - PTR;]`),
`Should have published results through Command when feature flag is off`);

done();
Expand Down Expand Up @@ -172,6 +176,7 @@ describe('PublishTestResults Suite', function() {
process.env[constants.proxyUserName] = "1";
process.env[constants.proxyPassword] = "1";
process.env[constants.proxyByPassHosts] = undefined;
process.env[constants.failTaskOnFailureToPublishResults] = 'false';

// Start the run
tr.run();
Expand All @@ -182,7 +187,7 @@ describe('PublishTestResults Suite', function() {
assert.equal(tr.invokedToolCount, 1, `invoked tool count should be 1`);
assert(tr.stdOutContained(`TestResultsPublisher.exe`),
`Should have called TestResultsPublisher.exe first`);
assert(tr.stdout.indexOf(`vso[results.publish type=VSTest;mergeResults=false;publishRunAttachments=false;resultFiles=n-files0.xml;failTaskOnFailedTests=false;testRunSystem=VSTS - PTR;]`) < 0,
assert(tr.stdout.indexOf(`vso[results.publish type=VSTest;mergeResults=false;publishRunAttachments=false;resultFiles=n-files0.xml;failTaskOnFailedTests=false;failTaskOnFailureToPublishResults=false;testRunSystem=VSTS - PTR;]`) < 0,
`Command should not have been called when exe returns with exit code suggesting feature flag is on`);

done();
Expand Down
1 change: 1 addition & 0 deletions Tasks/PublishTestResultsV2/Tests/TestSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ tr.setInput('testRunTitle', process.env[constants.testRunTitle]);
tr.setInput('publishRunAttachments', process.env[constants.publishRunAttachments]);
tr.setInput('searchFolder', process.env[constants.searchFolder]);
tr.setInput('failTaskOnFailedTests', process.env[constants.failTaskOnFailedTests]);
tr.setInput('failTaskOnFailureToPublishResults', process.env[constants.failTaskOnFailureToPublishResults]);

const PublishExeToolPath = path.join(__dirname, '../modules', 'TestResultsPublisher.exe');
const newUuid = "1e1faf9e-d9e5-4054-b351-398ac75b62f5";
Expand Down
17 changes: 13 additions & 4 deletions Tasks/PublishTestResultsV2/publishtestresults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function isNullOrWhitespace(input: any) {
return input.replace(/\s/g, '').length < 1;
}

function publish(testRunner, resultFiles, mergeResults, failTaskOnFailedTests, platform, config, runTitle, publishRunAttachments, testRunSystem) {
function publish(testRunner, resultFiles, mergeResults, failTaskOnFailedTests, platform, config, runTitle, publishRunAttachments, testRunSystem , failTaskOnFailureToPublishResults) {
var properties = <{ [key: string]: string }>{};
properties['type'] = testRunner;

Expand All @@ -41,6 +41,9 @@ function publish(testRunner, resultFiles, mergeResults, failTaskOnFailedTests, p
if(failTaskOnFailedTests){
properties['failTaskOnFailedTests'] = failTaskOnFailedTests;
}
if(failTaskOnFailureToPublishResults){
properties['failTaskOnFailureToPublishResults'] = failTaskOnFailureToPublishResults;
}
properties['testRunSystem'] = testRunSystem;

tl.command('results.publish', properties, '');
Expand Down Expand Up @@ -73,6 +76,7 @@ async function run() {
const publishRunAttachments = tl.getInput('publishRunAttachments');
const failTaskOnFailedTests = tl.getInput('failTaskOnFailedTests');
const failTaskOnMissingResultsFile: boolean = tl.getBoolInput('failTaskOnMissingResultsFile');
const failTaskOnFailureToPublishResults = tl.getInput('failTaskOnFailureToPublishResults');
let searchFolder = tl.getInput('searchFolder');

tl.debug('testRunner: ' + testRunner);
Expand All @@ -84,6 +88,7 @@ async function run() {
tl.debug('publishRunAttachments: ' + publishRunAttachments);
tl.debug('failTaskOnFailedTests: ' + failTaskOnFailedTests);
tl.debug('failTaskOnMissingResultsFile: ' + failTaskOnMissingResultsFile);
tl.debug('failTaskOnFailureToPublishResults: ' + failTaskOnFailureToPublishResults);

if (isNullOrWhitespace(searchFolder)) {
searchFolder = tl.getVariable('System.DefaultWorkingDirectory');
Expand Down Expand Up @@ -114,6 +119,7 @@ async function run() {
ci.addToConsolidatedCi('platform', platform);
ci.addToConsolidatedCi('testResultsFilesCount', testResultsFilesCount);
ci.addToConsolidatedCi('failTaskOnMissingResultsFile', failTaskOnMissingResultsFile);
ci.addToConsolidatedCi('failTaskOnFailureToPublishResults', failTaskOnFailureToPublishResults);

const dotnetVersion = getDotNetVersion();
ci.addToConsolidatedCi('dotnetVersion', dotnetVersion);
Expand Down Expand Up @@ -146,7 +152,8 @@ async function run() {
testRunTitle,
publishRunAttachments,
testRunner,
TESTRUN_SYSTEM);
TESTRUN_SYSTEM,
failTaskOnFailureToPublishResults);
const exitCode = await testResultsPublisher.publishResultsThroughExe();
tl.debug("Exit code of TestResultsPublisher: " + exitCode);

Expand All @@ -159,7 +166,8 @@ async function run() {
config,
testRunTitle,
publishRunAttachments,
TESTRUN_SYSTEM);
TESTRUN_SYSTEM,
failTaskOnFailureToPublishResults);
} else if (exitCode === 40000) {
// The exe returns with exit code: 40000 if there are test failures found and failTaskOnFailedTests is true
ci.addToConsolidatedCi('failedTestsInRun', true);
Expand All @@ -179,7 +187,8 @@ async function run() {
config,
testRunTitle,
publishRunAttachments,
TESTRUN_SYSTEM);
TESTRUN_SYSTEM,
failTaskOnFailureToPublishResults);
}
}
tl.setResult(tl.TaskResult.Succeeded, '');
Expand Down
7 changes: 5 additions & 2 deletions Tasks/PublishTestResultsV2/publishtestresultstool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ let uuid = require('uuid');

export class TestResultsPublisher {
constructor(matchingTestResultsFiles: string[], mergeResults: string, failTaskOnFailedTests: string, platform: string, config: string,
testRunTitle: string, publishRunAttachments: string, testRunner: string, testRunSystem: string) {
testRunTitle: string, publishRunAttachments: string, testRunner: string, testRunSystem: string
,failTaskOnFailureToPublishResults: string) {

this.matchingTestResultsFiles = matchingTestResultsFiles.slice(0);
this.mergeResults = mergeResults;
Expand All @@ -20,6 +21,7 @@ export class TestResultsPublisher {
this.publishRunAttachments = publishRunAttachments;
this.testRunner = testRunner;
this.testRunSystem = testRunSystem;
this.failTaskOnFailureToPublishResults = failTaskOnFailureToPublishResults;
}

public async publishResultsThroughExe(): Promise<number> {
Expand Down Expand Up @@ -120,7 +122,7 @@ export class TestResultsPublisher {
envVars = this.addToProcessEnvVars(envVars, 'jobattempt', tl.getVariable('System.JobAttempt'));
envVars = this.addToProcessEnvVars(envVars, 'jobidentifier', tl.getVariable('System.JobIdentifier'));
envVars = this.addToProcessEnvVars(envVars, 'agenttempdirectory', tl.getVariable('Agent.TempDirectory'));

envVars = this.addToProcessEnvVars(envVars, 'failtaskonfailuretopublishresults', this.failTaskOnFailureToPublishResults);
// Setting proxy details
envVars = this.addToProcessEnvVars(envVars, "proxyurl", tl.getVariable('agent.proxyurl'));
envVars = this.addToProcessEnvVars(envVars, "proxyusername", tl.getVariable('agent.proxyusername'));
Expand Down Expand Up @@ -151,4 +153,5 @@ export class TestResultsPublisher {
private publishRunAttachments: string;
private testRunner: string;
private testRunSystem: string;
private failTaskOnFailureToPublishResults: string;
}
12 changes: 10 additions & 2 deletions Tasks/PublishTestResultsV2/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
"author": "Microsoft Corporation",
"version": {
"Major": 2,
"Minor": 231,
"Patch": 1
"Minor": 232,
"Patch": 0
},
"demands": [],
"releaseNotes": "<ul><li>NUnit3 support</li><li>Support for Minimatch files pattern</li></ul>",
Expand Down Expand Up @@ -81,6 +81,14 @@
"required": false,
"helpMarkDown": "Fail the task if there are any test failures. Check this option to fail the task if test failures are detected in the result files."
},
{
"name": "failTaskOnFailureToPublishResults",
"type": "boolean",
"label": "Fail if there is failure in publishing test results",
"defaultValue": false,
"required": false,
"helpMarkDown": "Fail if there is failure in publishing test results. Check this option to fail the task if publishing test results is failed partially."
},
{
"name": "failTaskOnMissingResultsFile",
"type": "boolean",
Expand Down
12 changes: 10 additions & 2 deletions Tasks/PublishTestResultsV2/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
"author": "Microsoft Corporation",
"version": {
"Major": 2,
"Minor": 231,
"Patch": 1
"Minor": 232,
"Patch": 0
},
"demands": [],
"releaseNotes": "ms-resource:loc.releaseNotes",
Expand Down Expand Up @@ -81,6 +81,14 @@
"required": false,
"helpMarkDown": "ms-resource:loc.input.help.failTaskOnFailedTests"
},
{
"name": "failTaskOnFailureToPublishResults",
"type": "boolean",
"label": "ms-resource:loc.input.label.failTaskOnFailureToPublishResults",
"defaultValue": false,
"required": false,
"helpMarkDown": "ms-resource:loc.input.help.failTaskOnFailureToPublishResults"
},
{
"name": "failTaskOnMissingResultsFile",
"type": "boolean",
Expand Down
4 changes: 2 additions & 2 deletions _generated/PublishTestResultsV2.versionmap.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Default|2.231.1
Node20_229_13|2.231.2
Default|2.232.0
Node20_229_13|2.232.1
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
"loc.input.help.mergeTestResults": "A test run is created for each results file. Check this option to merge results into a single test run. To optimize for better performance, results will be merged into a single run if there are more than 100 result files, irrespective of this option.",
"loc.input.label.failTaskOnFailedTests": "Fail if there are test failures",
"loc.input.help.failTaskOnFailedTests": "Fail the task if there are any test failures. Check this option to fail the task if test failures are detected in the result files.",
"loc.input.label.failTaskOnFailureToPublishResults": "Fail if there is failure in publishing test results",
"loc.input.help.failTaskOnFailureToPublishResults": "Fail if there is failure in publishing test results. Check this option to fail the task if publishing test results is failed partially.",
"loc.input.label.failTaskOnMissingResultsFile": "Fail if no result files are found",
"loc.input.help.failTaskOnMissingResultsFile": "Fail the task if no result files are found.",
"loc.input.label.testRunTitle": "Test run title",
Expand Down
3 changes: 2 additions & 1 deletion _generated/PublishTestResultsV2_Node20/Tests/Constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ export const failTaskOnFailedTests = 'failTaskOnFailedTests';
export const proxyUrl = 'agent.proxyurl';
export const proxyUserName = 'agent.proxyusername';
export const proxyPassword = 'agent.proxypassword';
export const proxyByPassHosts = 'agent.proxybypasslist';
export const proxyByPassHosts = 'agent.proxybypasslist';
export const failTaskOnFailureToPublishResults = 'failTaskOnFailureToPublishResults';
9 changes: 7 additions & 2 deletions _generated/PublishTestResultsV2_Node20/Tests/L0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ describe('PublishTestResults Suite', function() {
delete process.env[constants.listPackagesReturnCode];
delete process.env[constants.osType];
delete process.env[constants.failTaskOnFailedTests];
delete process.env[constants.failTaskOnFailureToPublishResults];

done();
});
Expand Down Expand Up @@ -60,6 +61,7 @@ describe('PublishTestResults Suite', function() {
process.env[constants.proxyUserName] = "1";
process.env[constants.proxyPassword] = "1";
process.env[constants.proxyByPassHosts] = undefined;
process.env[constants.failTaskOnFailureToPublishResults] = 'false';

// Start the run
tr.run();
Expand Down Expand Up @@ -96,6 +98,7 @@ describe('PublishTestResults Suite', function() {
process.env[constants.proxyUserName] = "1";
process.env[constants.proxyPassword] = "1";
process.env[constants.proxyByPassHosts] = undefined;
process.env[constants.failTaskOnFailureToPublishResults] = 'false';

// Start the run
tr.run();
Expand Down Expand Up @@ -132,6 +135,7 @@ describe('PublishTestResults Suite', function() {
process.env[constants.proxyUserName] = "1";
process.env[constants.proxyPassword] = "1";
process.env[constants.proxyByPassHosts] = undefined;
process.env[constants.failTaskOnFailureToPublishResults] = 'false';

// Start the run
tr.run();
Expand All @@ -142,7 +146,7 @@ describe('PublishTestResults Suite', function() {
assert.equal(tr.invokedToolCount, 1, `invoked tool count should be 1`);
assert(tr.stdOutContained(`TestResultsPublisher.exe`),
`Should have called TestResultsPublisher.exe first`);
assert(tr.stdOutContained(`vso[results.publish type=VSTest;mergeResults=false;publishRunAttachments=false;resultFiles=n-files0.xml;failTaskOnFailedTests=false;testRunSystem=VSTS - PTR;]`),
assert(tr.stdOutContained(`vso[results.publish type=VSTest;mergeResults=false;publishRunAttachments=false;resultFiles=n-files0.xml;failTaskOnFailedTests=false;failTaskOnFailureToPublishResults=false;testRunSystem=VSTS - PTR;]`),
`Should have published results through Command when feature flag is off`);

done();
Expand Down Expand Up @@ -172,6 +176,7 @@ describe('PublishTestResults Suite', function() {
process.env[constants.proxyUserName] = "1";
process.env[constants.proxyPassword] = "1";
process.env[constants.proxyByPassHosts] = undefined;
process.env[constants.failTaskOnFailureToPublishResults] = 'false';

// Start the run
tr.run();
Expand All @@ -182,7 +187,7 @@ describe('PublishTestResults Suite', function() {
assert.equal(tr.invokedToolCount, 1, `invoked tool count should be 1`);
assert(tr.stdOutContained(`TestResultsPublisher.exe`),
`Should have called TestResultsPublisher.exe first`);
assert(tr.stdout.indexOf(`vso[results.publish type=VSTest;mergeResults=false;publishRunAttachments=false;resultFiles=n-files0.xml;failTaskOnFailedTests=false;testRunSystem=VSTS - PTR;]`) < 0,
assert(tr.stdout.indexOf(`vso[results.publish type=VSTest;mergeResults=false;publishRunAttachments=false;resultFiles=n-files0.xml;failTaskOnFailedTests=false;failTaskOnFailureToPublishResults=false;testRunSystem=VSTS - PTR;]`) < 0,
`Command should not have been called when exe returns with exit code suggesting feature flag is on`);

done();
Expand Down
1 change: 1 addition & 0 deletions _generated/PublishTestResultsV2_Node20/Tests/TestSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ tr.setInput('testRunTitle', process.env[constants.testRunTitle]);
tr.setInput('publishRunAttachments', process.env[constants.publishRunAttachments]);
tr.setInput('searchFolder', process.env[constants.searchFolder]);
tr.setInput('failTaskOnFailedTests', process.env[constants.failTaskOnFailedTests]);
tr.setInput('failTaskOnFailureToPublishResults', process.env[constants.failTaskOnFailureToPublishResults]);

const PublishExeToolPath = path.join(__dirname, '../modules', 'TestResultsPublisher.exe');
const newUuid = "1e1faf9e-d9e5-4054-b351-398ac75b62f5";
Expand Down
Loading

0 comments on commit ee56363

Please sign in to comment.