Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Commit

Permalink
Merge pull request #282 from Microsoft/users/nigurr/FixTestResultPubl…
Browse files Browse the repository at this point in the history
…ishCompat

Fix compat issues with old Test Results publish task with new agent
  • Loading branch information
Nitin Gurram committed Apr 12, 2016
2 parents 2462da3 + 3261b61 commit 91e63b8
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 30 deletions.
52 changes: 40 additions & 12 deletions src/agent/commands/results.publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,10 @@ export class ResultsPublishCommand implements cm.IAsyncCommand {
var publishRunAttachments: boolean = (this.command.properties['publishRunAttachments'] === "true");
var resultFilesPath = this.command.properties['resultFiles'];
var mergeResults: boolean = (this.command.properties['mergeResults'] === 'true');
var fileNumber: string = this.command.properties['fileNumber'];
var oldResultFilePath: string = this.command.message;
var command = this.command;

var testRunContext: trp.TestRunContext = {
requestedFor: this.executionContext.variables["build.requestedFor"],
buildId: this.executionContext.variables["build.buildId"],
releaseEnvironmentUri: this.executionContext.variables["release.environmentUri"],
releaseUri: this.executionContext.variables["release.releaseUri"],
platform: platform,
config: config,
runTitle: runTitle,
fileNumber: "1",
publishRunAttachments: publishRunAttachments
};

var reader;
if (resultType == "junit") {
reader = new trr.JUnitResultReader(this.command);
Expand All @@ -65,6 +55,44 @@ export class ResultsPublishCommand implements cm.IAsyncCommand {
this.command.warning("Test results of format '" + resultType + "'' are not supported on this build agent");
}

//start - This logic is purely exisiting for keeping the compat with old tasks
if (oldResultFilePath && oldResultFilePath != '') {
var testRunContext: trp.TestRunContext = {
requestedFor: this.executionContext.variables["build.requestedFor"],
buildId: this.executionContext.variables["build.buildId"],
releaseEnvironmentUri: this.executionContext.variables["release.environmentUri"],
releaseUri: this.executionContext.variables["release.releaseUri"],
platform: platform,
config: config,
runTitle: runTitle,
fileNumber: fileNumber,
publishRunAttachments: publishRunAttachments
};

var testRunPublisher = new trp.TestRunPublisher(this.executionContext.service, command, teamProject, testRunContext, reader);
testRunPublisher.publishTestRun(oldResultFilePath).then(function(createdTestRun) {
defer.resolve(null);
})
.fail((err) => {
this.command.warning("Failed to publish test results: " + err.message);
defer.resolve(null);
});
return defer.promise;
}
//end

var testRunContext: trp.TestRunContext = {
requestedFor: this.executionContext.variables["build.requestedFor"],
buildId: this.executionContext.variables["build.buildId"],
releaseEnvironmentUri: this.executionContext.variables["release.environmentUri"],
releaseUri: this.executionContext.variables["release.releaseUri"],
platform: platform,
config: config,
runTitle: runTitle,
fileNumber: "1",
publishRunAttachments: publishRunAttachments
};

if (reader != null && resultFilesPath) {
var testRunPublisher = new trp.TestRunPublisher(this.executionContext.service, command, teamProject, testRunContext, reader);
var resultFiles = resultFilesPath.split(",");
Expand Down
2 changes: 1 addition & 1 deletion src/test/publishcodecoveragetests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import path = require('path');
import fm = require('./lib/feedback');
import tec = require('./lib/testExecutionContext');
import ccp = require('../agent/codecoveragepublisher');
import cpc = require('../agent/commands/codecoverage.publish')
import cpc = require('../agent/commands/codecoverage.publish');
import csr = require('../agent/codecoveragesummaryreader');
import cm = require('../agent/common');
import ifm = require('../agent/interfaces');
Expand Down
57 changes: 40 additions & 17 deletions src/test/publishertests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,17 @@ import trr = require('../agent/testresultreader');
import cm = require('../agent/common');
import ifm = require('../agent/interfaces');
import testifm = require('vso-node-api/interfaces/TestInterfaces');
import tc = require('./lib/testcommand');
import rp = require('../agent/commands/results.publish');
import tec = require('./lib/testExecutionContext');

var jobInf = require('./lib/testJobInfo');

function resultFile(filename: string) {
return path.resolve(__dirname, 'testresults', filename);
}

describe('PublisherTests', function () {
describe('PublisherTests', function() {
const runContext: trp.TestRunContext = {
requestedFor: "userx",
buildId: "21",
Expand All @@ -43,6 +48,8 @@ describe('PublisherTests', function () {
const resultsFileNUnit2 = resultFile('nunitresults.1.xml');
const resultsFileXUnit = resultFile('xunitresults.xml');
const resultsFileXUnit2 = resultFile('xunitresults.1.xml');
var junitFilePath = path.resolve(__dirname, './testresults/junitresults1.xml');
var testExecutionContext;

it('results.publish : JUnit results file', () => {
const feedbackChannel = new fm.TestFeedbackChannel();
Expand All @@ -60,15 +67,15 @@ describe('PublisherTests', function () {
assert(feedbackChannel.jobsCompletedSuccessfully(), 'ResultPublish Task Failed! Details : ' + feedbackChannel.getRecordsString());
});
});

it('results.publish : JUnit results file with a suite and no cases', () => {
const feedbackChannel = new fm.TestFeedbackChannel();
const testRunPublisher = new trp.TestRunPublisher(feedbackChannel, null, "teamProject", runContext, readerJUnit);
return testRunPublisher.publishTestRun(resultsFileJUnitNoTestCases).then(createdTestRun => {
assert(feedbackChannel.jobsCompletedSuccessfully(), 'ResultPublish Task Failed! Details : ' + feedbackChannel.getRecordsString());
});
});

it('results.publish : JUnit results file with no suites', () => {
const feedbackChannel = new fm.TestFeedbackChannel();
const testRunPublisher = new trp.TestRunPublisher(feedbackChannel, null, "teamProject", runContext, readerJUnit);
Expand All @@ -82,7 +89,7 @@ describe('PublisherTests', function () {
const feedbackChannel = new fm.TestFeedbackChannel();
const testRunPublisher = new trp.TestRunPublisher(feedbackChannel, null, "teamProject", runContext, readerNUnit);

return testRunPublisher.publishTestRun(resultsFileNUnit).then(createdTestRun =>{
return testRunPublisher.publishTestRun(resultsFileNUnit).then(createdTestRun => {
assert(feedbackChannel.jobsCompletedSuccessfully(), 'ResultPublish Task Failed! Details : ' + feedbackChannel.getRecordsString());
});
});
Expand All @@ -95,7 +102,7 @@ describe('PublisherTests', function () {
assert(feedbackChannel.jobsCompletedSuccessfully(), 'ResultPublish Task Failed! Details : ' + feedbackChannel.getRecordsString());
});
});

it('results.publish : error handling for end test run', () => {
const feedbackChannel = new fm.TestFeedbackChannel();
const testRunPublisher = new trp.TestRunPublisher(feedbackChannel, null, "teamProject", runContext, readerJUnit);
Expand All @@ -107,26 +114,26 @@ describe('PublisherTests', function () {

// error handling/propagation from end test run
return testRunPublisher.endTestRun(testRun.id, testRun.resultsFile)
.then(createdTestRun => assert(false, 'ResultPublish Task did not fail as expected'))
.catch(err => {
assert(err.message == "Too bad - endTestRun failed", 'ResultPublish Task error message does not match expected - ' + err.message);
});
.then(createdTestRun => assert(false, 'ResultPublish Task did not fail as expected'))
.catch(err => {
assert(err.message == "Too bad - endTestRun failed", 'ResultPublish Task error message does not match expected - ' + err.message);
});
});

it('results.publish : error handling for reading results', () => {
const feedbackChannel = new fm.TestFeedbackChannel();
const testRunPublisher = new trp.TestRunPublisher(feedbackChannel, null, "teamProject", runContext, readerJUnit);

// error handling/propagation from parsing failures of junit/nunit files
var resultsFile = path.resolve(__dirname, './testresults/junit_bad.xml');
return testRunPublisher.publishTestRun(resultsFile)
.then(createdTestRun => {
assert(!feedbackChannel.jobsCompletedSuccessfully(), 'ResultPublish Task Failed! Details : ' + feedbackChannel.getRecordsString());
})
.catch(err => {
assert(err.message == "Unmatched closing tag: XYZXYZuite\nLine: 13\nColumn: 16\nChar: >",
.then(createdTestRun => {
assert(!feedbackChannel.jobsCompletedSuccessfully(), 'ResultPublish Task Failed! Details : ' + feedbackChannel.getRecordsString());
})
.catch(err => {
assert(err.message == "Unmatched closing tag: XYZXYZuite\nLine: 13\nColumn: 16\nChar: >",
'ResultPublish Task Failed as expected! Details : ' + err.message);
});
});
});

it('results.publish : JUnit reader sanity check without run title', () => {
Expand Down Expand Up @@ -318,7 +325,7 @@ describe('PublisherTests', function () {
assert(feedbackChannel.jobsCompletedSuccessfully(), 'ResultPublish Task Failed! Details : ' + feedbackChannel.getRecordsString());
});
})

it('results.publish : JUnit results file with merge support with one invalid xml file', () => {
const feedbackChannel = new fm.TestFeedbackChannel();
const testRunPublisher = new trp.TestRunPublisher(feedbackChannel, null, "teamProject", runContext, readerXUnit);
Expand All @@ -327,4 +334,20 @@ describe('PublisherTests', function () {
assert(feedbackChannel.jobsCompletedSuccessfully(), 'ResultPublish Task Failed! Details : ' + feedbackChannel.getRecordsString());
});
})

it('results.publish : Publish Test Results with old task compat', () => {
var properties: { [name: string]: string } = { "type": "junit", "platform": "platform", "config": "config", "runTitle": "Test Title", "publishRunAttachments": "true", "fileNumber": "1" };
var message = junitFilePath;
var command: cm.ITaskCommand = new tc.TestCommand(null, properties, message);
testExecutionContext = new tec.TestExecutionContext(new jobInf.TestJobInfo({}));
testExecutionContext.variables['system.teamProject'] = "teamProject";
var testResultsPublisher = new rp.ResultsPublishCommand(testExecutionContext, command);

testResultsPublisher.runCommandAsync().then(function(result) {
assert(testExecutionContext.service.jobsCompletedSuccessfully());
},
function(err) {
assert(false, 'Publish Test Results failed for old tasks: ' + testExecutionContext.service.getRecordsString())
});
})
});

0 comments on commit 91e63b8

Please sign in to comment.