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,44 +200,52 @@ namespace Microsoft.DotNet.OpenApi.Commands
var packageId = kvp.Key;
var version = urlPackages != null && urlPackages.ContainsKey(packageId) ? urlPackages[packageId] : kvp.Value;
var args = new[] {
"add",
"package",
packageId,
"--version",
version,
"--no-restore"
};
await TryAddPackage(packageId, version, projectFile);
}
}
var muxer = DotNetMuxer.MuxerPathOrDefault();
if (string.IsNullOrEmpty(muxer))
{
throw new ArgumentException($"dotnet was not found on the path.");
}
private async Task TryAddPackage(string packageId, string packageVersion, FileInfo projectFile)
{
var args = new[] {
"add",
"package",
packageId,
"--version",
packageVersion,
"--no-restore"
};
var startInfo = new ProcessStartInfo
{
FileName = muxer,
Arguments = string.Join(" ", args),
WorkingDirectory = projectFile.Directory.FullName,
RedirectStandardError = true,
RedirectStandardOutput = true,
};
var muxer = DotNetMuxer.MuxerPathOrDefault();
if (string.IsNullOrEmpty(muxer))
{
throw new ArgumentException($"dotnet was not found on the path.");
}
var process = Process.Start(startInfo);
var startInfo = new ProcessStartInfo
{
FileName = muxer,
Arguments = string.Join(" ", args),
WorkingDirectory = projectFile.Directory.FullName,
RedirectStandardError = true,
RedirectStandardOutput = true,
};
var timeout = 20;
if (!process.WaitForExit(timeout * 1000))
{
throw new ArgumentException($"Adding package `{packageId}` to `{projectFile.Directory}` took longer than {timeout} seconds.");
}
using var process = Process.Start(startInfo);
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 timeout = 20;
if (!process.WaitForExit(timeout * 1000))
{
throw new ArgumentException($"Adding package `{packageId}` to `{projectFile.Directory}` took longer than {timeout} seconds.");
}
if (process.ExitCode != 0)
{
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}`");
}
}