Test improvements (#17428)

Retry adding package and print reason for failure
This commit is contained in:
Ryan Brandenburg 2019-11-27 13:49:43 -08:00 committed by GitHub
parent b24b92494a
commit 32a2cc5943
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 41 additions and 33 deletions

View File

@ -200,12 +200,18 @@ namespace Microsoft.DotNet.OpenApi.Commands
var packageId = kvp.Key;
var version = urlPackages != null && urlPackages.ContainsKey(packageId) ? urlPackages[packageId] : kvp.Value;
await TryAddPackage(packageId, version, projectFile);
}
}
private async Task TryAddPackage(string packageId, string packageVersion, FileInfo projectFile)
{
var args = new[] {
"add",
"package",
packageId,
"--version",
version,
packageVersion,
"--no-restore"
};
@ -224,7 +230,7 @@ namespace Microsoft.DotNet.OpenApi.Commands
RedirectStandardOutput = true,
};
var process = Process.Start(startInfo);
using var process = Process.Start(startInfo);
var timeout = 20;
if (!process.WaitForExit(timeout * 1000))
@ -234,10 +240,12 @@ namespace Microsoft.DotNet.OpenApi.Commands
if (process.ExitCode != 0)
{
Out.Write(process.StandardOutput.ReadToEnd());
Error.Write(process.StandardError.ReadToEnd());
throw new ArgumentException($"Could not add package `{packageId}` to `{projectFile.Directory}`");
}
var output = await process.StandardOutput.ReadToEndAsync();
var error = await process.StandardError.ReadToEndAsync();
await Out.WriteAsync(output);
await Error.WriteAsync(error);
throw new ArgumentException($"Could not add package `{packageId}` to `{projectFile.Directory}` due to: `{error}`");
}
}