Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

Commit

Permalink
Process all output at once to avoid partial data (#1108)
Browse files Browse the repository at this point in the history
* Process all output at once to avoid partial data

* Use `{env: {}}` to make the execution faster

* Add support for large test output
  • Loading branch information
uudashr authored and ramya-rao-a committed Jul 24, 2017
1 parent c876eaa commit 94dadaa
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 13 deletions.
20 changes: 12 additions & 8 deletions src/goPackages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,11 @@ export function goListAll(): Promise<Map<string, string>> {
return Promise.resolve(allPkgs);
}
return new Promise<Map<string, string>>((resolve, reject) => {
const cmd = cp.spawn(goRuntimePath, ['list', '-f', '{{.Name}};{{.ImportPath}}', 'all']);
// Use `{env: {}}` to make the execution faster
const cmd = cp.spawn(goRuntimePath, ['list', '-f', '{{.Name}};{{.ImportPath}}', 'all'], {env: {}});
const chunks = [];
cmd.stdout.on('data', (d) => {
d.toString().split('\n').forEach(pkgDetail => {
if (!pkgDetail || !pkgDetail.trim() || pkgDetail.indexOf(';') === -1) return;
let [pkgName, pkgPath] = pkgDetail.trim().split(';');
allPkgs.set(pkgPath, pkgName);
});
chunks.push(d);
});

cmd.on('close', (status) => {
Expand All @@ -40,6 +38,11 @@ export function goListAll(): Promise<Map<string, string>> {
return reject();
}

chunks.toString().split('\n').forEach(pkgDetail => {
if (!pkgDetail || !pkgDetail.trim() || pkgDetail.indexOf(';') === -1) return;
let [pkgName, pkgPath] = pkgDetail.trim().split(';');
allPkgs.set(pkgPath, pkgName);
});
goListAllCompleted = true;
return resolve(allPkgs);
});
Expand Down Expand Up @@ -118,12 +121,13 @@ export function getNonVendorPackages(folderPath: string): Promise<string[]> {
}
return new Promise<string[]>((resolve, reject) => {
const childProcess = cp.spawn(goRuntimePath, ['list', './...'], { cwd: folderPath });
let pkgs = [];
const chunks = [];
childProcess.stdout.on('data', (stdout) => {
pkgs = pkgs.concat(stdout.toString().split('\n').filter(pkgPath => pkgPath && pkgPath.indexOf('/vendor/') === -1));
chunks.push(stdout);
});

childProcess.on('close', (status) => {
const pkgs = chunks.toString().split('\n').filter(pkgPath => pkgPath && !pkgPath.includes('/vendor/'));
return resolve(pkgs);
});
});
Expand Down
23 changes: 18 additions & 5 deletions src/goTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,17 +243,30 @@ export function goTest(testconfig: TestConfig): Thenable<boolean> {

args.push(...targets);
let proc = cp.spawn(goRuntimePath, args, { env: testEnvVars, cwd: testconfig.dir });
let leftOver = '';
let errChunks = [];
proc.stdout.on('data', chunk => {
let testOutput = expandFilePathInOutput(chunk.toString(), testconfig.dir);
outputChannel.append(testOutput);
let s = chunk.toString();
let lastNewLineIndex = s.lastIndexOf('\n');
if (lastNewLineIndex > -1) {
let sub = leftOver + s.substring(0, lastNewLineIndex);
leftOver = s.substring(lastNewLineIndex + 1);

let testOutput = expandFilePathInOutput(sub, testconfig.dir);
outputChannel.appendLine(testOutput);
} else {
leftOver += s;
}
});
proc.stderr.on('data', chunk => outputChannel.append(chunk.toString()));
proc.stderr.on('data', chunk => errChunks.push(chunk));
proc.on('close', code => {
if (code) {
outputChannel.append('Error: Tests failed.');
if (errChunks.length) {
outputChannel.append(errChunks.toString());
}
outputChannel.appendLine('Error: Tests failed.');
} else {
outputChannel.append('Success: Tests passed.');
outputChannel.appendLine('Success: Tests passed.');
}
resolve(code === 0);
});
Expand Down

0 comments on commit 94dadaa

Please sign in to comment.