Skip to content

Commit

Permalink
Users/ranjanar/logs errorstream bugs (#4089)
Browse files Browse the repository at this point in the history
* Input logs and the error stream redirection for vstest.console.exe

* Removing extra spaces

* Made the info logs localizable.. And Removed failOnStderr..

* CR commets
  • Loading branch information
RanjanarMS authored Apr 24, 2017
1 parent 3b65a44 commit a669bb2
Show file tree
Hide file tree
Showing 8 changed files with 217 additions and 94 deletions.
20 changes: 19 additions & 1 deletion Tasks/VsTest/Strings/resources.resjson/en-US/resources.resjson
Original file line number Diff line number Diff line change
Expand Up @@ -89,5 +89,23 @@
"loc.messages.overrideNotSupported": "Overriding test run parameters is supported only with runsettings file. This option will be ignored.",
"loc.messages.vs2013NotSupportedInDta": "Running tests using Visual Studio 2013 with multi-agent phase settings is not supported.",
"loc.messages.configureDtaAgentFailed": "Configuring the test agent with the server failed even after %d retries with error %s",
"loc.messages.otherConsoleOptionsNotSupported": "Other console options is not supported when using the multi-agent phase setting. This option will be ignored."
"loc.messages.otherConsoleOptionsNotSupported": "Other console options is not supported when using the multi-agent phase setting. This option will be ignored.",
"loc.messages.distributedTestWorkflow": "In distributed testing flow....",
"loc.messages.dtaNumberOfAgents": "Distributed test execution, number of agents in phase : %s",
"loc.messages.testSelectorInput": "Test selector : %s",
"loc.messages.searchFolderInput": "Search folder : %s",
"loc.messages.testFilterCriteriaInput": "Test filter criteria : %s",
"loc.messages.runSettingsFileInput": "Run settings file : %s",
"loc.messages.runInParallelInput": "Run in parallel : %s",
"loc.messages.runInIsolationInput": "Run in isolation : %s",
"loc.messages.pathToCustomAdaptersInput": "Path to custom adapters : %s",
"loc.messages.otherConsoleOptionsInput": "Other console options : %s",
"loc.messages.codeCoverageInput": "Code coverage enabled : %s",
"loc.messages.testPlanInput": "Test plan Id : %s",
"loc.messages.testplanConfigInput": "Test plan configuration Id : %s",
"loc.messages.testSuiteSelected": "Test suite Id selected: %s",
"loc.messages.testAssemblyFilterInput": "Test assembly filter : %s",
"loc.messages.vsVersionSelected": "VisualStudio version selected for test execution : %s",
"loc.messages.runTestsLocally": "Run the tests locally using %s....",
"loc.messages.vstestLocationSpecified": "%s, specified location : %s"
}
53 changes: 25 additions & 28 deletions Tasks/VsTest/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import * as fs from 'fs';
import * as tl from 'vsts-task-lib/task';
import * as tr from 'vsts-task-lib/toolrunner';
import * as path from 'path';
import * as Q from 'q';
import * as models from './models';
import * as os from 'os';

import tl = require('vsts-task-lib/task');
import tr = require('vsts-task-lib/toolrunner');
import path = require('path');
import Q = require('q');
import models = require('./models')

var os = require('os');
var uuid = require('node-uuid');
var xml2js = require('xml2js');
var parser = new xml2js.Parser();
var builder = new xml2js.Builder();
const uuid = require('node-uuid');
const xml2js = require('xml2js');
const parser = new xml2js.Parser();
const builder = new xml2js.Builder();

export class Constants {
public static vsTestVersionString = 'version';
Expand Down Expand Up @@ -47,14 +47,13 @@ export class Helper{
}

public static getXmlContents(filePath: string): Q.Promise<any> {
var defer=Q.defer<any>();
Helper.readFileContents(filePath, "utf-8")
const defer = Q.defer<any>();
Helper.readFileContents(filePath, 'utf-8')
.then(function (xmlContents) {
parser.parseString(xmlContents, function (err, result) {
if (err) {
defer.resolve(null);
}
else{
} else {
defer.resolve(result);
}
});
Expand All @@ -66,25 +65,24 @@ export class Helper{
}

public static saveToFile(fileContents: string, extension: string): Q.Promise<string> {
var defer = Q.defer<string>();
var tempFile = path.join(os.tmpdir(), uuid.v1() + extension);
const defer = Q.defer<string>();
const tempFile = path.join(os.tmpdir(), uuid.v1() + extension);
fs.writeFile(tempFile, fileContents, function (err) {
if (err) {
defer.reject(err);
}
tl.debug("Temporary file created at " + tempFile);
tl.debug('Temporary file created at ' + tempFile);
defer.resolve(tempFile);
});
return defer.promise;
}

public static readFileContents(filePath: string, encoding: string): Q.Promise<string> {
var defer = Q.defer<string>();
const defer = Q.defer<string>();
fs.readFile(filePath, encoding, (err, data) => {
if (err) {
defer.reject(new Error('Could not read file (' + filePath + '): ' + err.message));
}
else {
} else {
defer.resolve(data);
}
});
Expand All @@ -96,8 +94,8 @@ export class Helper{
}

public static writeXmlFile(result: any, settingsFile: string, fileExt: string): Q.Promise<string> {
var defer = Q.defer<string>();
var runSettingsForTestImpact = builder.buildObject(result);
const defer = Q.defer<string>();
const runSettingsForTestImpact = builder.buildObject(result);
Helper.saveToFile(runSettingsForTestImpact, fileExt)
.then(function (fileName) {
defer.resolve(fileName);
Expand All @@ -109,13 +107,12 @@ export class Helper{
return defer.promise;
}

public static getVSVersion(versionNum: number)
{
public static getVSVersion(versionNum: number) {
switch (versionNum) {
case 12: return "2013";
case 14: return "2015";
case 15: return "2017";
default: return "selected";
case 12: return '2013';
case 14: return '2015';
case 15: return '2017';
default: return 'selected';
}
}
}
33 changes: 33 additions & 0 deletions Tasks/VsTest/outputstream.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import * as stream from 'stream';
import * as os from 'os';
import * as tl from 'vsts-task-lib/task';

export class StringErrorWritable extends stream.Writable {
private value: string = '';

constructor(options: any) {
super(options);
}

_write(data: any, encoding: string, callback: Function): void {
this.value += data;

let errorString: string = data.toString();
let n = errorString.indexOf(os.EOL);
while (n > -1) {
const line = errorString.substring(0, n);
tl.error(line);

// the rest of the string ...
errorString = errorString.substring(n + os.EOL.length);
n = errorString.indexOf(os.EOL);
}
if (callback) {
callback();
}
}

toString(): string {
return this.value;
}
};
7 changes: 3 additions & 4 deletions Tasks/VsTest/runvstest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,15 @@ try {

if ((parallelExecution && parallelExecution.toLowerCase() === 'multimachine')
|| testType.toLowerCase() === 'testplan' || testType.toLowerCase() === 'testrun') {
tl.debug('Going to the DTA Flow..');
tl.debug('***********************');

tl._writeLine(tl.loc('distributedTestWorkflow'));
tl._writeLine('======================================================');
const dtaTestConfig = taskInputParser.getDistributedTestConfigurations();
tl._writeLine('======================================================');

const test = new distributedTest.DistributedTest(dtaTestConfig);
test.runDistributedTest();
} else {
tl.debug('Run the tests locally using vstest.console.exe....');
tl.debug('**************************************************');
localTest.startTest();
}
} catch (error) {
Expand Down
23 changes: 21 additions & 2 deletions Tasks/VsTest/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"version": {
"Major": 2,
"Minor": 0,
"Patch": 30
"Patch": 32
},
"demands": [
"vstest"
Expand Down Expand Up @@ -377,6 +377,25 @@
"overrideNotSupported": "Overriding test run parameters is supported only with runsettings file. This option will be ignored.",
"vs2013NotSupportedInDta": "Running tests using Visual Studio 2013 with multi-agent phase settings is not supported.",
"configureDtaAgentFailed": "Configuring the test agent with the server failed even after %d retries with error %s",
"otherConsoleOptionsNotSupported": "Other console options is not supported when using the multi-agent phase setting. This option will be ignored."
"otherConsoleOptionsNotSupported": "Other console options is not supported when using the multi-agent phase setting. This option will be ignored.",
"distributedTestWorkflow": "In distributed testing flow....",
"dtaNumberOfAgents": "Distributed test execution, number of agents in phase : %s",
"testSelectorInput": "Test selector : %s",
"searchFolderInput": "Search folder : %s",
"testFilterCriteriaInput": "Test filter criteria : %s",
"runSettingsFileInput": "Run settings file : %s",
"runInParallelInput":"Run in parallel : %s",
"runInIsolationInput":"Run in isolation : %s",
"pathToCustomAdaptersInput": "Path to custom adapters : %s",
"otherConsoleOptionsInput": "Other console options : %s",
"codeCoverageInput": "Code coverage enabled : %s",
"testPlanInput": "Test plan Id : %s",
"testplanConfigInput": "Test plan configuration Id : %s",
"testSuiteSelected": "Test suite Id selected: %s",
"testAssemblyFilterInput": "Test assembly filter : %s",
"vsVersionSelected": "VisualStudio version selected for test execution : %s",
"runTestsLocally": "Run the tests locally using %s....",
"vstestLocationSpecified": "%s, specified location : %s"

}
}
22 changes: 20 additions & 2 deletions Tasks/VsTest/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"version": {
"Major": 2,
"Minor": 0,
"Patch": 30
"Patch": 32
},
"demands": [
"vstest"
Expand Down Expand Up @@ -377,6 +377,24 @@
"overrideNotSupported": "ms-resource:loc.messages.overrideNotSupported",
"vs2013NotSupportedInDta": "ms-resource:loc.messages.vs2013NotSupportedInDta",
"configureDtaAgentFailed": "ms-resource:loc.messages.configureDtaAgentFailed",
"otherConsoleOptionsNotSupported": "ms-resource:loc.messages.otherConsoleOptionsNotSupported"
"otherConsoleOptionsNotSupported": "ms-resource:loc.messages.otherConsoleOptionsNotSupported",
"distributedTestWorkflow": "ms-resource:loc.messages.distributedTestWorkflow",
"dtaNumberOfAgents": "ms-resource:loc.messages.dtaNumberOfAgents",
"testSelectorInput": "ms-resource:loc.messages.testSelectorInput",
"searchFolderInput": "ms-resource:loc.messages.searchFolderInput",
"testFilterCriteriaInput": "ms-resource:loc.messages.testFilterCriteriaInput",
"runSettingsFileInput": "ms-resource:loc.messages.runSettingsFileInput",
"runInParallelInput": "ms-resource:loc.messages.runInParallelInput",
"runInIsolationInput": "ms-resource:loc.messages.runInIsolationInput",
"pathToCustomAdaptersInput": "ms-resource:loc.messages.pathToCustomAdaptersInput",
"otherConsoleOptionsInput": "ms-resource:loc.messages.otherConsoleOptionsInput",
"codeCoverageInput": "ms-resource:loc.messages.codeCoverageInput",
"testPlanInput": "ms-resource:loc.messages.testPlanInput",
"testplanConfigInput": "ms-resource:loc.messages.testplanConfigInput",
"testSuiteSelected": "ms-resource:loc.messages.testSuiteSelected",
"testAssemblyFilterInput": "ms-resource:loc.messages.testAssemblyFilterInput",
"vsVersionSelected": "ms-resource:loc.messages.vsVersionSelected",
"runTestsLocally": "ms-resource:loc.messages.runTestsLocally",
"vstestLocationSpecified": "ms-resource:loc.messages.vstestLocationSpecified"
}
}
50 changes: 39 additions & 11 deletions Tasks/VsTest/taskinputparser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ export function getDistributedTestConfigurations(): models.DtaTestConfigurations
if (!isNaN(totalJobsInPhase)) {
dtaConfiguration.numberOfAgentsInPhase = totalJobsInPhase;
}
tl._writeLine(tl.loc('dtaNumberOfAgents', dtaConfiguration.numberOfAgentsInPhase));

dtaConfiguration.onDemandTestRunId = tl.getInput('tcmTestRun');

dtaConfiguration.dtaEnvironment = initDtaEnvironment();

return dtaConfiguration;
}

Expand Down Expand Up @@ -94,30 +94,58 @@ function getDtaInstanceId(): number {
}

function initTestConfigurations(testConfiguration: models.TestConfigurations) {
testConfiguration.pathtoCustomTestAdapters = tl.getInput('pathtoCustomTestAdapters');
testConfiguration.sourceFilter = tl.getDelimitedInput('testAssemblyVer2', '\n', true);
testConfiguration.testDropLocation = tl.getInput('searchFolder');
testConfiguration.testSelection = tl.getInput('testSelector');
tl._writeLine(tl.loc('testSelectorInput', testConfiguration.testSelection));

testConfiguration.testDropLocation = tl.getInput('searchFolder');
tl._writeLine(tl.loc('searchFolderInput', testConfiguration.testDropLocation));

testConfiguration.testcaseFilter = tl.getInput('testFiltercriteria');
tl._writeLine(tl.loc('testFilterCriteriaInput', testConfiguration.testcaseFilter));

testConfiguration.settingsFile = tl.getPathInput('runSettingsFile');
tl._writeLine(tl.loc('runSettingsFileInput', testConfiguration.settingsFile));

testConfiguration.overrideTestrunParameters = tl.getInput('overrideTestrunParameters');
testConfiguration.buildConfig = tl.getInput('configuration');
testConfiguration.buildPlatform = tl.getInput('platform');
testConfiguration.testRunTitle = tl.getInput('testRunTitle');

testConfiguration.runInParallel = tl.getBoolInput('runInParallel');
tl._writeLine(tl.loc('runInParallelInput', testConfiguration.runInParallel));

testConfiguration.runTestsInIsolation = tl.getBoolInput('runTestsInIsolation');
tl._writeLine(tl.loc('runInIsolationInput', testConfiguration.runTestsInIsolation));

testConfiguration.tiaConfig = getTiaConfiguration();
testConfiguration.testSelection = tl.getInput('testSelector');

testConfiguration.pathtoCustomTestAdapters = tl.getInput('pathtoCustomTestAdapters');
tl._writeLine(tl.loc('pathToCustomAdaptersInput', testConfiguration.pathtoCustomTestAdapters));

testConfiguration.otherConsoleOptions = tl.getInput('otherConsoleOptions');
tl._writeLine(tl.loc('otherConsoleOptionsInput', testConfiguration.otherConsoleOptions));

testConfiguration.codeCoverageEnabled = tl.getBoolInput('codeCoverageEnabled');
tl._writeLine(tl.loc('codeCoverageInput', testConfiguration.codeCoverageEnabled));

testConfiguration.buildConfig = tl.getInput('configuration');
testConfiguration.buildPlatform = tl.getInput('platform');
testConfiguration.testRunTitle = tl.getInput('testRunTitle');

if (testConfiguration.testSelection.toLowerCase() === 'testplan') {
testConfiguration.testplan = parseInt(tl.getInput('testPlan'));
tl._writeLine(tl.loc('testPlanInput', testConfiguration.testplan));

testConfiguration.testPlanConfigId = parseInt(tl.getInput('testConfiguration'));
tl._writeLine(tl.loc('testplanConfigInput', testConfiguration.testPlanConfigId));

const testSuiteStrings = tl.getDelimitedInput('testSuite', ',', true);
testConfiguration.testSuites = new Array<number>();
testSuiteStrings.forEach(element => {
testConfiguration.testSuites.push(parseInt(element));
const testSuiteId = parseInt(element);
tl._writeLine(tl.loc('testSuiteSelected', testSuiteId));
testConfiguration.testSuites.push(testSuiteId);
});
} else {
testConfiguration.sourceFilter = tl.getDelimitedInput('testAssemblyVer2', '\n', true);
tl._writeLine(tl.loc('testAssemblyFilterInput', testConfiguration.sourceFilter));
}

testConfiguration.vsTestLocationMethod = tl.getInput('vstestLocationMethod');
Expand All @@ -127,17 +155,17 @@ function initTestConfigurations(testConfiguration: models.TestConfigurations) {
tl._writeLine('vsTestVersion is null or empty');
throw new Error('vsTestVersion is null or empty');
}
tl._writeLine(tl.loc('vsVersionSelected', testConfiguration.vsTestVersion));
} else {
testConfiguration.vsTestLocation = tl.getInput('vsTestLocation');
tl._writeLine(tl.loc('vstestLocationSpecified', 'vstest.console.exe', testConfiguration.vsTestLocation));
}

// only to facilitate the writing of unit tests
testConfiguration.vs15HelperPath = tl.getVariable('vs15Helper');
if (!testConfiguration.vs15HelperPath) {
testConfiguration.vs15HelperPath = path.join(__dirname, 'vs15Helper.ps1');
}

testConfiguration.codeCoverageEnabled = tl.getBoolInput('codeCoverageEnabled');
}

function getTiaConfiguration() : models.TiaConfiguration {
Expand Down
Loading

0 comments on commit a669bb2

Please sign in to comment.