Skip to content

Commit

Permalink
Enabling test plan flow for DTA and VSTest
Browse files Browse the repository at this point in the history
Porting ps script execution fix
  • Loading branch information
kaadhina committed Feb 8, 2017
1 parent 210a710 commit 4fad9cb
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 20 deletions.
19 changes: 10 additions & 9 deletions Tasks/VsTest/distributedTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class DistributedTest {

try {
const agentId = await ta.TestAgent.createAgent(this.dtaTestConfig.dtaEnvironment, 3);
this.dtaPid = this.startDtaExecutionHost(agentId);
this.dtaPid = await this.startDtaExecutionHost(agentId);
await this.startDtaTestRun();
try {
// TODO: ranjanar: fixasap : This dangerous - Note that the PID only uniquely identifies your child process
Expand All @@ -42,7 +42,7 @@ export class DistributedTest {
}
}

private startDtaExecutionHost(agentId: any): number {
private async startDtaExecutionHost(agentId: any) {
tl.rmRF(this.dtaTestConfig.dtaEnvironment.dtaHostLogFilePath, true);
const envVars: { [key: string]: string; } = process.env;
utils.Helper.addToProcessEnvVars(envVars, 'DTA.AccessToken', this.dtaTestConfig.dtaEnvironment.patToken);
Expand All @@ -54,11 +54,15 @@ export class DistributedTest {
this.dtaTestConfig.vsTestVersion = '15.0';
}
utils.Helper.addToProcessEnvVars(envVars, 'DTA.TestPlatformVersion', this.dtaTestConfig.vsTestVersion);
versionFinder.locateTestWindow(this.dtaTestConfig)
.then (function (exeInfo) {

tl.debug("Adding env var DTA.TestWindow.Path = " + exeInfo.location);
utils.Helper.addToProcessEnvVars(envVars, 'DTA.TestWindow.Path', exeInfo.location);
var exeInfo = await versionFinder.locateTestWindow(this.dtaTestConfig);
if(exeInfo) {
tl.debug("Adding env var DTA.TestWindow.Path = " + exeInfo.location);
utils.Helper.addToProcessEnvVars(envVars, 'DTA.TestWindow.Path', exeInfo.location);
} else {
tl.error(tl.loc('VstestNotFound', this.dtaTestConfig.vsTestVersion));

This comment has been minimized.

Copy link
@RanjanarMS

RanjanarMS Feb 8, 2017

Member

We will proceed further in this case?

}


// We are logging everything to a DTAExecutionHost.exe.log file and reading it at the end and adding to the build task debug logs
// So we are not redirecting the IO streams from the DTAExecutionHost.exe process
Expand All @@ -68,9 +72,6 @@ export class DistributedTest {
const proc = ps.spawn(path.join(__dirname, 'Modules/DTAExecutionHost.exe'), [], { env: envVars, stdio: 'ignore' });
tl.debug('DtaExecutionHost is executing with the process : ' + proc.pid);
return proc.pid;
});
tl.error(tl.loc('VstestNotFound'));
return 0;
}

private async startDtaTestRun() {
Expand Down
8 changes: 4 additions & 4 deletions Tasks/VsTest/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ export interface TestConfigurations {
runInParallel: boolean;
runTestsInIsolation: boolean;
vs15HelperPath: string;
testSelection: string; // "testPlan" as selection string
testplan: number;
testSuites: number[];
testPlanConfigId: number;
}

export interface DtaTestConfigurations extends TestConfigurations {
onDemandTestRunId: string;
testConfigurationMapping: string; // TODO : What is this?
testSelection: string; // "testPlan" as selection string
testplan: number;
testSuites: number[];
testPlanConfigId: number;
customSlicingenabled: boolean;
dtaEnvironment: DtaEnvironment;
}
Expand Down
23 changes: 22 additions & 1 deletion Tasks/VsTest/runvstest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,15 @@ try {
if (parallelExecution && parallelExecution.toLowerCase() === 'multimachine' || testType.toLowerCase() === 'testplan' || testType.toLowerCase() === 'testrun') {
tl.debug('Going to the DTA Flow..');
tl.debug('***********************');
const dtaTestConfig = taskInputParser.getDistributedTestConfigurations();

var dtaTestConfig = null;
if(parallelExecution && parallelExecution.toLowerCase() === 'multimachine') {
dtaTestConfig = taskInputParser.getDistributedTestConfigurations(false);
}
else {
dtaTestConfig = taskInputParser.getDistributedTestConfigurations(true);
}

const test = new distributedTest.DistributedTest(dtaTestConfig);
test.runDistributedTest();
} else {
Expand All @@ -28,3 +36,16 @@ try {
tl._writeLine('##vso[task.logissue type=error;code=' + error + ';TaskName=VSTest]');
throw error;
}

function getDtaInstanceId(): number {
const taskInstanceIdString = tl.getVariable('DTA_INSTANCE_ID');
let taskInstanceId: number = 1;
if (taskInstanceIdString) {
const instanceId: number = Number(taskInstanceIdString);
if (!isNaN(instanceId)) {
taskInstanceId = instanceId + 1;
}
}
tl.setVariable('DTA_INSTANCE_ID', taskInstanceId.toString());
return taskInstanceId;
}
1 change: 1 addition & 0 deletions Tasks/VsTest/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@
"defaultValue": "14.0",
"required": false,
"helpMarkDown": "The version of Visual Studio test to use.",
"groupName": "executionOptions",
"options": {
"latest": "Latest",
"15.0": "Visual Studio 2017",
Expand Down
1 change: 1 addition & 0 deletions Tasks/VsTest/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@
"defaultValue": "14.0",
"required": false,
"helpMarkDown": "ms-resource:loc.input.help.vsTestVersion",
"groupName": "executionOptions",
"options": {
"latest": "Latest",
"15.0": "Visual Studio 2017",
Expand Down
28 changes: 23 additions & 5 deletions Tasks/VsTest/taskinputparser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import utils = require('./helpers');
let os = require('os');
let uuid = require('node-uuid');

export function getDistributedTestConfigurations(): models.DtaTestConfigurations {
export function getDistributedTestConfigurations(isBuild : boolean): models.DtaTestConfigurations {
tl.setResourcePath(path.join(__dirname, 'task.json'));
const dtaConfiguration = {} as models.DtaTestConfigurations;
initTestConfigurations(dtaConfiguration);
Expand All @@ -20,7 +20,7 @@ export function getDistributedTestConfigurations(): models.DtaTestConfigurations
if(dtaConfiguration.runTestsInIsolation) {
tl.warning(tl.loc('runTestInIsolationNotSupported'));
}
dtaConfiguration.dtaEnvironment = initDtaEnvironment();
dtaConfiguration.dtaEnvironment = initDtaEnvironment(isBuild);
return dtaConfiguration;
}

Expand All @@ -34,7 +34,7 @@ export function getvsTestConfigurations(): models.VsTestConfigurations {
return vsTestConfiguration;
}

function initDtaEnvironment(): models.DtaEnvironment {
function initDtaEnvironment(isBuild: boolean): models.DtaEnvironment {
const dtaEnvironment = {} as models.DtaEnvironment;
dtaEnvironment.tfsCollectionUrl = tl.getVariable('System.TeamFoundationCollectionUri');
dtaEnvironment.patToken = tl.getEndpointAuthorization('SystemVssConnection', true).parameters['AccessToken'];
Expand All @@ -44,8 +44,14 @@ function initDtaEnvironment(): models.DtaEnvironment {
const phaseId = tl.getVariable('Release.DeployPhaseId');
const projectName = tl.getVariable('System.TeamProject');
const taskInstanceId = getDtaInstanceId();

if(isBuild) {
const buildId = tl.getVariable('Build.BuildId');
dtaEnvironment.environmentUri = 'dta://env/' + projectName + '/_apis/build/' + buildId + '/' + taskInstanceId;
} else {
dtaEnvironment.environmentUri = 'dta://env/' + projectName + '/_apis/release/' + releaseId + '/' + phaseId + '/' + taskInstanceId;
}

dtaEnvironment.environmentUri = 'dta://env/' + projectName + '/_apis/release/' + releaseId + '/' + phaseId + '/' + taskInstanceId;
dtaEnvironment.dtaHostLogFilePath = path.join(tl.getVariable('System.DefaultWorkingDirectory'), 'DTAExecutionHost.exe.log');
return dtaEnvironment;
}
Expand Down Expand Up @@ -77,8 +83,20 @@ function initTestConfigurations(testConfiguration: models.TestConfigurations)
testConfiguration.runInParallel = tl.getBoolInput('runTestsInParallel');
testConfiguration.runTestsInIsolation = tl.getBoolInput('runTestsInIsolation');
testConfiguration.tiaConfig = getTiaConfiguration();
testConfiguration.vsTestVersion = tl.getInput('vsTestVersion');
testConfiguration.testSelection = tl.getInput('testSelector');

if(testConfiguration.testSelection.toLowerCase() === 'testPlan') {
testConfiguration.testplan = parseInt(tl.getInput('testPlan'));
testConfiguration.testPlanConfigId = parseInt(tl.getInput('testConfiguration'));

var testSuiteStrings = tl.getInput('testSuite').split(',');

This comment has been minimized.

Copy link
@RanjanarMS

RanjanarMS Feb 8, 2017

Member

getdelimitedinput?

testConfiguration.testSuites = new Array<number>();
testSuiteStrings.forEach(element => {
testConfiguration.testSuites.push(parseInt(element));
});
}

testConfiguration.vsTestVersion = tl.getInput('vsTestVersion');
if(utils.Helper.isNullEmptyOrUndefined(testConfiguration.vsTestVersion)) {
tl._writeLine('vsTestVersion is null or empty');
throw new Error("vsTestVersion is null or empty");
Expand Down
2 changes: 1 addition & 1 deletion Tasks/VsTest/versionFinder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ function getLatestVSTestConsolePathFromRegistry(): Q.Promise<models.ExecutabaleI

function getVSTestConsole15Path(vs15HelperPath: string): string {
let powershellTool = tl.tool('powershell');
let powershellArgs = ['-file', vs15HelperPath]
let powershellArgs = ['-NonInteractive', '-ExecutionPolicy', 'Unrestricted', '-file', vs15HelperPath]
powershellTool.arg(powershellArgs);
let xml = powershellTool.execSync().stdout;
let deferred = Q.defer<string>();
Expand Down

0 comments on commit 4fad9cb

Please sign in to comment.