Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Live stream the logs #3874

Merged
merged 12 commits into from
Apr 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 40 additions & 24 deletions Tasks/VsTest/distributedtest.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as fs from 'fs';
import * as path from 'path';
import * as Q from 'q';
import * as ps from 'child_process';
import * as tl from 'vsts-task-lib/task';
import * as tr from 'vsts-task-lib/toolrunner';
Expand All @@ -20,7 +19,7 @@ export class DistributedTest {
this.registerAndConfigureAgent();
}

private async registerAndConfigureAgent() {
private async registerAndConfigureAgent() {
tl.debug('Configure the Agent with DTA... Invoking the createAgent REST API');

try {
Expand All @@ -35,7 +34,6 @@ export class DistributedTest {
} catch (error) {
tl.warning('Modules/DTAExecutionHost.exe process kill failed, pid: ' + this.dtaPid + ' , error :' + error);
}
tl.debug(fs.readFileSync(this.dtaTestConfig.dtaEnvironment.dtaHostLogFilePath, 'utf-8'));
tl.setResult(tl.TaskResult.Succeeded, 'Task succeeded');
} catch (error) {
tl.error(error);
Expand All @@ -44,12 +42,6 @@ export class DistributedTest {
}

private async startDtaExecutionHost(agentId: any) {
try {
tl.rmRF(this.dtaTestConfig.dtaEnvironment.dtaHostLogFilePath, true);
} catch (error) {
//Ignore.
}

const envVars: { [key: string]: string; } = process.env;
utils.Helper.addToProcessEnvVars(envVars, 'DTA.AccessToken', this.dtaTestConfig.dtaEnvironment.patToken);
utils.Helper.addToProcessEnvVars(envVars, 'DTA.AgentId', agentId);
Expand All @@ -58,14 +50,15 @@ export class DistributedTest {
utils.Helper.addToProcessEnvVars(envVars, 'DTA.TeamFoundationCollectionUri', this.dtaTestConfig.dtaEnvironment.tfsCollectionUrl);
utils.Helper.addToProcessEnvVars(envVars, 'DTA.MiniMatchSourceFilter', 'true');
utils.Helper.addToProcessEnvVars(envVars, 'DTA.LocalTestDropPath', this.dtaTestConfig.testDropLocation);
utils.Helper.addToProcessEnvVars(envVars, 'DTA.EnableConsoleLogs', 'true');

if (this.dtaTestConfig.vsTestLocationMethod === utils.Constants.vsTestVersionString) {
utils.Helper.addToProcessEnvVars(envVars, 'DTA.TestPlatformVersion', this.dtaTestConfig.vsTestVersion);
}

const exeInfo = await versionFinder.locateVSTestConsole(this.dtaTestConfig);
if (exeInfo) {
const exelocation = path.dirname(exeInfo)
const exelocation = path.dirname(exeInfo);
tl.debug('Adding env var DTA.TestWindow.Path = ' + exelocation);

// Split the TestWindow path out of full path - if we can't find it, will assume
Expand All @@ -87,14 +80,35 @@ export class DistributedTest {
// So we are not redirecting the IO streams from the DTAExecutionHost.exe process
// We are not using toolrunner here because it doesn't have option to ignore the IO stream, so directly using spawn

const proc = ps.spawn(path.join(__dirname, 'Modules/DTAExecutionHost.exe'), [], { env: envVars, stdio: 'ignore' });
const proc = ps.spawn(path.join(__dirname, 'Modules/DTAExecutionHost.exe'), [], { env: envVars });
this.dtaPid = proc.pid;
tl.debug('Modules/DTAExecutionHost.exe is executing with the process id : ' + this.dtaPid);

proc.on('error', (err) => {
this.dtaPid = -1;
throw new Error('Failed to start Modules/DTAExecutionHost.exe.');
proc.stdout.setEncoding('utf8');
proc.stderr.setEncoding('utf8');
proc.stdout.on('data', (c) => {
// this is bit hacky way to fix the web method logging as it's not configurable currently
// and writes info to stdout directly
const lines = c.toString().split('\n');
lines.forEach(function (line: string) {
if (line.startsWith('Web method')) {
tl.debug(line);
} else {
tl._writeLine(line.toString());
}
});
});
proc.stderr.on('data', (c) => {
const lines = c.toString().split('\n');
lines.forEach(function (line: string) {
tl._writeError(line.toString());
});
});

proc.on('error', (err) => {
this.dtaPid = -1;
throw new Error('Failed to start Modules/DTAExecutionHost.exe.');
});

proc.on('close', (code) => {
if (code !== 0) {
Expand Down Expand Up @@ -122,7 +136,9 @@ export class DistributedTest {
//Modify settings file to enable configurations and data collectors.
let settingsFile = this.dtaTestConfig.settingsFile;
try {
settingsFile = await settingsHelper.updateSettingsFileAsRequired(this.dtaTestConfig.settingsFile, this.dtaTestConfig.runInParallel, this.dtaTestConfig.tiaConfig, null, false, this.dtaTestConfig.overrideTestrunParameters);
settingsFile = await settingsHelper.updateSettingsFileAsRequired
(this.dtaTestConfig.settingsFile, this.dtaTestConfig.runInParallel, this.dtaTestConfig.tiaConfig,
null, false, this.dtaTestConfig.overrideTestrunParameters);
//Reset override option so that it becomes a no-op in TaskExecutionHost
this.dtaTestConfig.overrideTestrunParameters = null;
} catch (error) {
Expand All @@ -134,17 +150,17 @@ export class DistributedTest {
utils.Helper.addToProcessEnvVars(envVars, 'runsettings', settingsFile);
utils.Helper.addToProcessEnvVars(envVars, 'testdroplocation', this.dtaTestConfig.testDropLocation);
utils.Helper.addToProcessEnvVars(envVars, 'testrunparams', this.dtaTestConfig.overrideTestrunParameters);
utils.Helper.setEnvironmentVariableToString(envVars, 'codecoverageenabled', this.dtaTestConfig.codeCoverageEnabled);
utils.Helper.addToProcessEnvVars(envVars, 'buildconfig', this.dtaTestConfig.buildConfig);
utils.Helper.addToProcessEnvVars(envVars, 'buildplatform', this.dtaTestConfig.buildPlatform);
utils.Helper.addToProcessEnvVars(envVars, 'testconfigurationmapping', this.dtaTestConfig.testConfigurationMapping);
utils.Helper.addToProcessEnvVars(envVars, 'testruntitle', this.dtaTestConfig.testRunTitle);
utils.Helper.addToProcessEnvVars(envVars, 'testselection', this.dtaTestConfig.testSelection);
utils.Helper.addToProcessEnvVars(envVars, 'tcmtestrun', this.dtaTestConfig.onDemandTestRunId);
utils.Helper.setEnvironmentVariableToString(envVars, 'testplan', this.dtaTestConfig.testplan);
if (!utils.Helper.isNullOrUndefined(this.dtaTestConfig.testSuites)) {
utils.Helper.addToProcessEnvVars(envVars, 'testsuites', this.dtaTestConfig.testSuites.join(','));
}
utils.Helper.setEnvironmentVariableToString(envVars, 'codecoverageenabled', this.dtaTestConfig.codeCoverageEnabled);
utils.Helper.setEnvironmentVariableToString(envVars, 'testplan', this.dtaTestConfig.testplan);
utils.Helper.setEnvironmentVariableToString(envVars, 'testplanconfigid', this.dtaTestConfig.testPlanConfigId);
// In the phases world we will distribute based on number of agents
utils.Helper.setEnvironmentVariableToString(envVars, 'customslicingenabled', 'true');
Expand All @@ -156,15 +172,15 @@ export class DistributedTest {
}

private async cleanUp(temporarySettingsFile: string) {
//cleanup the runsettings file
if (temporarySettingsFile && this.dtaTestConfig.settingsFile !== temporarySettingsFile) {
try {
tl.rmRF(temporarySettingsFile, true);
} catch (error) {
//Ignore.
//cleanup the runsettings file
if (temporarySettingsFile && this.dtaTestConfig.settingsFile !== temporarySettingsFile) {
try {
tl.rmRF(temporarySettingsFile, true);
} catch (error) {
//Ignore.
}
}
}
}
private dtaTestConfig: models.DtaTestConfigurations;
private dtaPid: number;
}
2 changes: 1 addition & 1 deletion Tasks/VsTest/make.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"dest": "./"
},
{
"url": "https://testexecution.blob.core.windows.net/testexecution/3766237/TestExecution.zip",
"url": "https://testexecution.blob.core.windows.net/testexecution/3812251/TestExecution.zip",
"dest": "./Modules"
}
]
Expand Down
2 changes: 1 addition & 1 deletion 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": 32
"Patch": 33
},
"demands": [
"vstest"
Expand Down
2 changes: 1 addition & 1 deletion 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": 32
"Patch": 33
},
"demands": [
"vstest"
Expand Down