From 35f9fced3e73269cb9c8fe9a67d78168b8224e3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=F0=9F=98=8ANitin=20Gurram=F0=9F=98=8A?= Date: Fri, 24 Mar 2017 15:03:49 +0530 Subject: [PATCH 1/8] Live stream the logs --- Tasks/VsTest/distributedtest.ts | 64 +++++++++++++++++---------------- 1 file changed, 34 insertions(+), 30 deletions(-) diff --git a/Tasks/VsTest/distributedtest.ts b/Tasks/VsTest/distributedtest.ts index 59344d419954..d919724829ef 100644 --- a/Tasks/VsTest/distributedtest.ts +++ b/Tasks/VsTest/distributedtest.ts @@ -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'; @@ -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 { @@ -28,14 +27,13 @@ export class DistributedTest { await this.startDtaExecutionHost(agentId); await this.startDtaTestRun(); try { - if(this.dtaPid !== -1) { + if (this.dtaPid !== -1) { tl.debug('Trying to kill the Modules/DTAExecutionHost.exe process with pid :' + this.dtaPid); process.kill(this.dtaPid); } } 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); @@ -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); @@ -58,31 +50,41 @@ 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) { + if (this.dtaTestConfig.vsTestLocationMethod === utils.Constants.vsTestVersionString) { utils.Helper.addToProcessEnvVars(envVars, 'DTA.TestPlatformVersion', this.dtaTestConfig.vsTestVersion); } - var exeInfo = await versionFinder.locateTestWindow(this.dtaTestConfig); - if(exeInfo) { - tl.debug("Adding env var DTA.TestWindow.Path = " + exeInfo.location); + const 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', utils.Helper.getVSVersion( parseFloat(this.dtaTestConfig.vsTestVersion)))); + tl.error(tl.loc('VstestNotFound', utils.Helper.getVSVersion(parseFloat(this.dtaTestConfig.vsTestVersion)))); } // 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 // 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.stdout.setEncoding('utf8'); + proc.stderr.setEncoding('utf8'); + proc.stdout.on('data', (c) => { + tl._writeLine(c.toString()); + }); + proc.stderr.on('data', (c) => { + tl._writeError(c.toString()); + }); + proc.on('error', (err) => { - this.dtaPid = -1; - throw new Error('Failed to start Modules/DTAExecutionHost.exe.'); - }); + this.dtaPid = -1; + throw new Error('Failed to start Modules/DTAExecutionHost.exe.'); + }); proc.on('close', (code) => { if (code !== 0) { @@ -108,9 +110,11 @@ export class DistributedTest { } //Modify settings file to enable configurations and data collectors. - var settingsFile = this.dtaTestConfig.settingsFile; + 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) { @@ -122,17 +126,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'); @@ -144,15 +148,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; } \ No newline at end of file From eb7f5cae54bf53393f5271d389518c391e4db7d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=F0=9F=98=8ANitin=20Gurram=F0=9F=98=8A?= Date: Mon, 27 Mar 2017 09:50:53 +0530 Subject: [PATCH 2/8] Version bumpup --- Tasks/VsTest/task.json | 2 +- Tasks/VsTest/task.loc.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Tasks/VsTest/task.json b/Tasks/VsTest/task.json index 4ab603df77f2..2b2788f0be49 100644 --- a/Tasks/VsTest/task.json +++ b/Tasks/VsTest/task.json @@ -17,7 +17,7 @@ "version": { "Major": 2, "Minor": 0, - "Patch": 22 + "Patch": 23 }, "demands": [ "vstest" diff --git a/Tasks/VsTest/task.loc.json b/Tasks/VsTest/task.loc.json index 9e91883de139..85654d90fb46 100644 --- a/Tasks/VsTest/task.loc.json +++ b/Tasks/VsTest/task.loc.json @@ -17,7 +17,7 @@ "version": { "Major": 2, "Minor": 0, - "Patch": 22 + "Patch": 23 }, "demands": [ "vstest" From d16b14473c66fff64397fc8e09ab714c369e541d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=F0=9F=98=8ANitin=20Gurram=F0=9F=98=8A?= Date: Mon, 27 Mar 2017 11:28:45 +0530 Subject: [PATCH 3/8] Fix web request logging --- Tasks/VsTest/distributedtest.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Tasks/VsTest/distributedtest.ts b/Tasks/VsTest/distributedtest.ts index d919724829ef..fd73312337b0 100644 --- a/Tasks/VsTest/distributedtest.ts +++ b/Tasks/VsTest/distributedtest.ts @@ -75,7 +75,14 @@ export class DistributedTest { proc.stdout.setEncoding('utf8'); proc.stderr.setEncoding('utf8'); proc.stdout.on('data', (c) => { - tl._writeLine(c.toString()); + // this is bit hacky way to fix the web method logging as it's not configurable currently + // and writes info to stdout directly + const data = c.toString(); + if (data.startsWith('Web method')) { + tl.debug(data); + } else { + tl._writeLine(c.toString()); + } }); proc.stderr.on('data', (c) => { tl._writeError(c.toString()); From 96973b3d15a0e53d3472cd85cfb29833dbf0f26b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=F0=9F=98=8ANitin=20Gurram=F0=9F=98=8A?= Date: Tue, 11 Apr 2017 09:20:56 +0530 Subject: [PATCH 4/8] Downmerge from master --- Tasks/VsTest/task.loc.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tasks/VsTest/task.loc.json b/Tasks/VsTest/task.loc.json index 6a8bba8cd250..8e580a58ba63 100644 --- a/Tasks/VsTest/task.loc.json +++ b/Tasks/VsTest/task.loc.json @@ -17,7 +17,7 @@ "version": { "Major": 2, "Minor": 0, - "Patch": 23 + "Patch": 26 }, "demands": [ "vstest" From 0fcf9571180c9ebef490ec91703c4327c1e99642 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=F0=9F=98=8ANitin=20Gurram=F0=9F=98=8A?= Date: Tue, 11 Apr 2017 13:06:37 +0530 Subject: [PATCH 5/8] Identify line splits properly --- Tasks/VsTest/distributedtest.ts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/Tasks/VsTest/distributedtest.ts b/Tasks/VsTest/distributedtest.ts index ee6e072588f5..5d17975a0892 100644 --- a/Tasks/VsTest/distributedtest.ts +++ b/Tasks/VsTest/distributedtest.ts @@ -89,12 +89,14 @@ export class DistributedTest { 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 data = c.toString(); - if (data.startsWith('Web method')) { - tl.debug(data); - } else { - tl._writeLine(c.toString()); - } + const lines = c.toString().split('\n'); + lines.forEach(function (line: string) { + if (line.startsWith('Web method')) { + tl.debug(line); + } else { + tl._writeLine(c.toString()); + } + }); }); proc.stderr.on('data', (c) => { tl._writeError(c.toString()); From 213ac5be3d575cdbddbb5a60d538d623e25e2c09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=F0=9F=98=8ANitin=20Gurram=F0=9F=98=8A?= Date: Tue, 11 Apr 2017 13:09:56 +0530 Subject: [PATCH 6/8] Bump up task version --- Tasks/VsTest/task.json | 2 +- Tasks/VsTest/task.loc.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Tasks/VsTest/task.json b/Tasks/VsTest/task.json index aa599a9b92fd..712cbb3216f1 100644 --- a/Tasks/VsTest/task.json +++ b/Tasks/VsTest/task.json @@ -17,7 +17,7 @@ "version": { "Major": 2, "Minor": 0, - "Patch": 26 + "Patch": 27 }, "demands": [ "vstest" diff --git a/Tasks/VsTest/task.loc.json b/Tasks/VsTest/task.loc.json index 8e580a58ba63..b56c4101c021 100644 --- a/Tasks/VsTest/task.loc.json +++ b/Tasks/VsTest/task.loc.json @@ -17,7 +17,7 @@ "version": { "Major": 2, "Minor": 0, - "Patch": 26 + "Patch": 27 }, "demands": [ "vstest" From e1db0fcdfd74bc23145ff0f30ba1568fbf4d63d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=F0=9F=98=8ANitin=20Gurram=F0=9F=98=8A?= Date: Thu, 20 Apr 2017 18:08:22 +0530 Subject: [PATCH 7/8] Updated task.json --- Tasks/VsTest/distributedtest.ts | 4 ++-- Tasks/VsTest/task.json | 2 +- Tasks/VsTest/task.loc.json | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Tasks/VsTest/distributedtest.ts b/Tasks/VsTest/distributedtest.ts index bbb3684a2c8a..17b7b07ed955 100644 --- a/Tasks/VsTest/distributedtest.ts +++ b/Tasks/VsTest/distributedtest.ts @@ -94,14 +94,14 @@ export class DistributedTest { if (line.startsWith('Web method')) { tl.debug(line); } else { - tl._writeLine(c.toString()); + tl._writeLine(line.toString()); } }); }); proc.stderr.on('data', (c) => { const lines = c.toString().split('\n'); lines.forEach(function (line: string) { - tl._writeError(c.toString()); + tl._writeError(line.toString()); }); }); diff --git a/Tasks/VsTest/task.json b/Tasks/VsTest/task.json index a777c11844af..9b9b1dbca2a8 100644 --- a/Tasks/VsTest/task.json +++ b/Tasks/VsTest/task.json @@ -17,7 +17,7 @@ "version": { "Major": 2, "Minor": 0, - "Patch": 28 + "Patch": 29 }, "demands": [ "vstest" diff --git a/Tasks/VsTest/task.loc.json b/Tasks/VsTest/task.loc.json index 581361186c42..9e86e88aaacc 100644 --- a/Tasks/VsTest/task.loc.json +++ b/Tasks/VsTest/task.loc.json @@ -17,7 +17,7 @@ "version": { "Major": 2, "Minor": 0, - "Patch": 28 + "Patch": 29 }, "demands": [ "vstest" From 0080f1a523b0a240c19e589ba014ca86f1e87414 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=F0=9F=98=8ANitin=20Gurram=F0=9F=98=8A?= Date: Mon, 24 Apr 2017 10:54:16 +0530 Subject: [PATCH 8/8] Updated test execution engine --- Tasks/VsTest/make.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tasks/VsTest/make.json b/Tasks/VsTest/make.json index e1334ce4e374..8bc5a8098880 100644 --- a/Tasks/VsTest/make.json +++ b/Tasks/VsTest/make.json @@ -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" } ]